# Basic use

First let's use Matlab just like a calculator. Type

1.2 * sin(3.4^2 + log10(5))

to see the value of *12 x sin(3.4 ^{2} + log_{10}5)*. To keep this value for later use, calling it by the name `result' (for
example) type

result = 1.2 * sin(3.4^2 + log10(5))

Now you can use this value in a new calculation:

new = 3+result/2

(Note that this gives *3 + (result/2)*
not *(3 + (result)/2*;
you
can always use round brackets to specify exactly what you mean:

newnew = (3+result)/2

Matlab knows about complex numbers. You get
by typing
`sqrt(-1)`, but since most people use *i* to represent
you can get it more easily by typing `i`. (To allow for the
peccadilloes of electrical engineers you can also get it by typing
`j`.) Try typing

exp(i*pi)

to check that Matlab also knows about the exponential function and π.
(You have just evaluated *e ^{iπ}*.) You can enter complex numbers
either in terms of real and imaginary parts (

*z*=

*x*+

*iy*), or in terms of modulus and argument (

*z=re*). Try typing

^{iθ}z = 3 + 4*i

and

z = 5 * exp(i*0.9273)

Note that in both cases Matlab's response is in *x*+*iy* form, and that
the argument (θ)
must be specified in radians, not in degrees.
You can recover the real part, imaginary part, modulus (absolute value),
and argument by typing `real(z) imag(z) abs(z)` and `angle(z)`
respectively. To find |*z*^{2}|, for example, type `abs(z^ 2)`.

*Warning*: If you should type something like `i = 10` then the value
of `i` will be redefined and will no longer be .

One of the most useful features of Matlab is that functions like
`sin`, `log`, `abs` and many others will work on whole
lists of numbers simultaneously. Suppose, for example, that we wanted
to evaluate the list

for some reason. We could do this by typing

sin([-pi/2, 0, pi/2, pi])

Notice that we used `(` and `)` to enclose the argument to
the function `sin`, but `[` and `]` to enclose the list
of numbers. If you make your list of numbers vertical instead of
horizontal, then the answer comes out vertical too. Try:

vlist = [-pi/2; 0; pi/2; pi] sin(vlist)

So, between `[` and `]` commas are used to put things beside each
other, while semicolons
put things on top of each other. (You can also use a space instead of
a comma, and a line-break (`Return' key) instead of a semicolon --
try it.)

In fact functions like `sin` will work on two-dimensional arrays
of numbers, and the result will have the same shape as the original
array. To find

type:

try1 = [1, 2, 3 ; -1, -2, -3] log(try1)