Getting started on Matlab

First things first: RPI has site license for matlab, so matlab is free for RPI students. It may very well be already installed on your laptop, of not, contact vcc help desk at 7777, ro go online to

$\displaystyle http://dotcio.rpi.edu/services/software-labs$

The most helpful command is help command. Type help help in matlab command prompt window to see general help.

Type

a=1

to assign the value of “1” to variable a.

Type

x=linspace(0,2*pi,100);

to generate a vector of 100 values equally spaced between zero and $2\pi$. Type

$y=x.^2$

to generate a vector of squares of $x$. Note a dot after $x$.

Type

z=cos(x);

to generate a vector of cosine of x.

Type

plot(x,y)

to see a plot of x versus y.

Type

hold on; plot(x,z,'r')

to generate the second plot in red color on top of preveous plot.

To get help in general it is enough to type “help” and the name of the command, for example

help plot

will give you a lot of help for use on plot command.

Usefull commands for matrix operations are

eye(5,5)

zero(2,5)

rand(4,1)

Type help eye or help rand or help zero to get all the details.

Some people find notebook command to be usefull. Type help notebook to read about it.

Other usefull commands for matrices are max, norm, abs. Type help and the name of the command for full details.

Input and output commands are disp, fprintf and input. Type help and the name of the command for full details.

We will discuss more matrix operations in class, in particular,

A=rand(4,4); A(3,3)

will output the 3-3 element of random matrix A,

A(:,3)

will output third column, and

A(3,:)

will output third row of the random matrix A.

Furthermore

A(3,1:2)

will output first two elements of third row of matrix A.

Pay especial attention to the function command, which allows you to define your own matlab function.

Other commands which will be useful as semester progresses are Matlab “backslash” which will be discussed in lectures extensively, polyfit for polynomials fits, polyval for evaluation of polynomials, fzero for finding roots of the equations, spline for splines, ode45 for ode's.

Finally type

help for

help while

and

help if

for detailed help and examples of loops and if-statements.

This list is necessarily short, but it covers at least 75% of necessary matlab commands that will be usefull.

Use course online examples, and please pay attention with inclass matlab demonstrations.

Please be patient, and do not afraid to experiment. Also use matlab build in “help” buttom, and “demo” buttom.