Graphics Reference
In-Depth Information
Below are some examples.
Represent the base 2 number 100101 in base 10.
>> base2dec('100101',2)
Ans =
37.00
Represent the hexadecimal number FFFFAA00 in base 10.
>> base2dec ('FFFFAA0', 16)
Ans =
268434080.00
Calculate the result in base 10 of the operation FFFAA2 + FF − 1
>> base2dec('FFFAA2',16) + base2dec('FF',16)-1
years =
16776096.00
A.6 Real Numbers
A rational number is of the form p/q , where p is an integer and q another integer. The way in which the rational
is different in MATLAB from that of the majority of calculators is that the integer forms are retained through
calculations. If we ask a calculator to calculate the sum 1/2 + 1/3 + 1/4 , most will return something like 1.0833 , which
is no more than an approximation to the result.
MATLAB can work with rational numbers in exact mode, so the result of expressions involving rational numbers
is always another rational or whole number. If so, it is necessary to activate this format with the command format
rat . But MATLAB also returns approaches using decimals in the results if the user so wishes, by activating any other
type of format (e.g. format short or format long ). MATLAB solves the calculator operation above in exact mode in the
following way:
>> format rat
>> 1/2 + 1/3 + 1/4
Ans =
13/12
Unlike calculators, to make operations with rational numbers the result always can be accurate. Therefore, while
MATLAB is dealing with rationals as ratios of integers, it keeps them in this way. In this way, rounding errors are not
dragged in calculations with fractions, which can become very serious, as evidenced by the theory of errors. Note
that, once enabled in rational format, when calling MATLAB that you add two rationals, it returns a rational as a ratio
of integers and thus represent it symbolically. Once enabled in the rational format, operations with rationals will be
exact until changed to a different format.
 
Search WWH ::




Custom Search