next up previous
Next: MATLAB Functions Up: Guide Contents Previous: Matrices and MATLAB

Numbers and Arithmetic Expressions

  MATLAB uses conventional decimal notation to enter numbers. The leading minus sign and decimal point are optional, and numbers may be specified using scientific notation. The following examples are valid numbers in MATLAB.

tabular82

WARNING: If you try to import data produced by a FORTRAN routine that prints the values of double precision variables, MATLAB will not understand the use of ``D'' in place of ``E'' in scientific notation. (You can use the Unix command tr to replace all ``D''s with ``E''s.)

To build expressions, MATLAB provides the usual arithmetic operators.

tabular88

(MATLAB's use of two division operators will be explained in Section 7.) To change the normal precedence of these operators enclose portions of an expression in parentheses in the usual manner.

On the Rick Lab's HP servers MATLAB uses IEEE double precision floating point arithmetic to perform its computations. Although MATLAB stores the full precision of all computations, by default it displays results in a 5 digit fixed point format. The output format can be changed using the format command. The following example prints the result of entering the vector [5/7.3 7.7432e-7] under different format settings.
format short
0.6849 0.0000
format short e
6.8493e-01 7.7432e-07
format long
0.68493150684932 0.00000077432000
format long e
6.849315068493150e-01 7.743200000000001e-07
You can learn more about the format command by entering help format. The remainder of the examples in this guide assume that the ``short e'' format has been chosen.



Ian Cavers
Fri Dec 4 15:01:52 PST 1998