- Starting and stopping

- Windows and such
- Command window
- Figure window(s)
- Editor window(s)

- Using MATLAB as a calculator

- Using MATLAB's built-in functions

- On-line Help(!)

- Suppressing output with the semicolon

To stop MATLAB type ``quit'' at the MATLAB prompt, i.e.

>> quit

>> pi

MATLAB responds with

ans = 3.1416

Try the following examples

>> sin(pi/4) >> 2^(log2(4)) >> sqrt(9)

>> x = 5 x = 5 >> y = pi/4 y = 0.7854 >> z = y + x^0.25 z = 2.2807

Note that z exists only as a numerical value, not as the formula with which it was created.

Use the `who` command to list the currently active
variables. For the preceding session this results in

>> who Your variables are: ans x y z leaving 7433616 bytes of memory free.

To print the value of a variable that is already defined just type its name at the prompt.

>> z z = 2.2807

The
variables
section describes how to work with MATLAB variables

You can also create your own functions. To do this you type MATLAB commands into a plain text file. The file must have the extension ".m", and because of this MATLAB functions are often referred to as "m-files". Creating and using functions is described in the Programming Matlab section.

MATLAB also has some special variables and functions. You have
already encountered the `ans` variable which is
automatically created whenever a mathematical expression is not
assigned to another variable.

The built-in `eps` variable is used as a tolerance for
internal calculations. Initially `eps` is equal to
machine epsilon. You can reset the value of `eps`, but
this is not recommended unless you are very sure you know what
you are doing.

The `realmax`, `realmin`, `Inf` and
`NaN` built-in variables are used to handle floating
point exceptions. All numerical variables in MATLAB are
stored as 32 bit floating point numbers. This corresponds
to ``double precision'' on most computers (supercomputers
and some high-end workstations being the exception).
The `Inf` and `NaN` values appear if a
floating point exception occurred during the calculations.

In general you should not try to (re)assign the values of any built-in variables listed in the table below.

>> help

To get help on a specific topic, for example the cosine function, type

>> help cos

Using

To see how the semicolon works enter the following statements
exactly as shown, ending each line with a carriage return. Do
not enter the prompt character, `>>`.

>> x = pi/3; >> y = sin(x)/cos(x); >> z = y - tan(x); >> z >> yThe last two lines do not end in semicolons so MATLAB prints the results of evaluating

[Preceding Section] [Master Outline] [Section Outline] [Next Section]