Geoscience Reference
In-Depth Information
For real numbers there is, by dei nition, no such gap between consecutive
numbers. h e use of a i nite number of l oating-point numbers is limited
by the number of available bits due to the i nite precision arithmetic of a
computer. h ere are countless examples available with which to demonstrate
this, but we will restrict ourselves to the simple example of the sine of ˀ.
Typing
sin(pi)
yields
ans =
1.2246e-16
and not, as would be expected, zero. Since pi is only the nearest l oating-
point value to ˀ, the sine of pi is not exactly zero but a value very close to
zero.
Let us now look at some examples of arrays in order to familiarize
ourselves with the dif erent data types in MATLAB. For the i rst example we
create a 3-by-4 array of random numbers with double precision by typing
clear
rng(0)
A = rand(3,4)
We use the function rand that generates uniformly distributed pseudorandom
numbers within the open interval [0,1]. To obtain identical data values, we
use rng(0) to reset the random number generator by using the integer 0 as
seed (see Chapter 3 for more details on random number generators and types
of distributions). Since we did not use a semicolon here we get the output
A =
0.8147 0.9134 0.2785 0.9649
0.9058 0.6324 0.5469 0.1576
0.1270 0.0975 0.9575 0.9706
By default, the output is in a scaled i xed point format with 5 digits, e.g.,
0.8147 for the (1,1) element of A . Typing
format long
switches to a i xed point format with 16 digits for double precision. Recalling
A by typing
A
Search WWH ::




Custom Search