19-01-2013, 12:34 PM
MATLAB numbers and numeric formats
MATLAB numbers.pdf (Size: 196.49 KB / Downloads: 216)
INTRODUCTION
All numerical variables are stored in MATLAB in double precision floating-point form.
(In fact it is possible to force some variables to be of other types but not easily and this ability
is not needed here.) Floating-point representation of numbers is essentially equivalent to the
“scientific notation” of your calculator. Specifically a (real) number x is stored in binary
floating point form as
where f is called the mantissa and E the exponent. The exponent is an integer (positive or
negative) and the mantissa lies in the range 1 f 2. This representation is entirely internal
to the machine and its details are not important here. (They are important when analyzing
carefully the performance of numerical algorithms.)
Similar formats using the conventional decimal system are available for MATLAB input
and output. These formats can be set in the File – Preferences menu in the MATLAB
command window. They can also be changed using MATLAB commands.
Strings and printing
In more advanced applications such as symbolic computation, string manipulation is a very
important topic. For our purposes, however, we shall only need very limited skills in handling
strings initially. One most important use might be to include Your Name and the Course as part
of your MATLAB workspace in a simple, and automatic, way.
This is easily achieved by using strings and the MATLAB print function fprintf in a special
file called startup.m which will be executed automatically when you start MATLAB.
Strings can be defined in MATLAB by simply enclosing the appropriate string of
characters in single quotes.
MATLAB’s mathematical functions
All of the standard mathematical functions—often called the elementary functions—that
you will meet in your Calculus courses are available in MATLAB using their usual
mathematical names. Many other functions—the special functions—are also included; you
will most likely come across some of these in later mathematics and, more especially,
engineering courses.
The elementary functions are listed in your User’s Guide. This listing includes several
functions which will not be familiar to you yet, and several that we shall not deal with in this
book.
Array arithmetic
Array arithmetic allows us to perform the equivalent arithmetic operations on all the
components of a vector. In most circumstances the standard arithmetic symbols achieve what is
wanted and expected. However, especially for multiplication, division and powers involving
MATLAB vectors (or matrices) a dot . is needed in conjunction with the usual operation sign.
These various operations are best illustrated with some simple MATLAB examples. For
these examples we shall use the following data vectors a and b, and scalar (number) c.
Since the vectors a and b have the same size, they can be added or subtracted from one
another. They can be multiplied, or divided, by a scalar, or a scalar can be added to each of
their components.