## Math101,  Matlab Help

### Starting Matlab:

Matlab is one of the most commonly used scientific computational programs. To start it, click (or double click) the Matlab icon.

### Ending Matlab:

To finish a Matlab session, type "quit" at the prompt in the Matlab window.

### Simple arithmetic:

Matlab interprets expressions you type in. For example

A=5+3

B=3*4+2

A/B

B^2 (this is squaring)

A/C would produce an error: C has not been defined. If you don't assign the result of an expression to some variable name (like A or B above), then it is assigned to the variable ans. If you don't want to see the result of a command on the screen, end the line with a semicolon (;) For example,

C=sqrt(A+B);

assigns the result to a variable C, but doesn't tell you what it is. You can see it with the command

C

Other functions available include exp, log, sin, cos, tan, atan, acos, the last two being inverse functions (inverse tangent, inverse cosine).

### Graphing functions:

The basic variable in Matlab is the array, meaning a list of numbers, not a single number. You can create an array with a single command, for example

x=1:10

makes the variable x the array [1 2 3 4 5 6 7 8 9 10]. The command

y=x.^2

makes the variable y the array [1 4 9 16 25 36 49 64 81 100]. This is just each one of the x's squared. (Note the '.' before the '^' in the command to square each element of the x array.) Now

plot(x,y)

plots the squaring function. You need not take x to be just integers. The command

x=linspace(0,10,101)

takes values from 0 to 10 equally spaced (linearly spaced), and 101 of them in all. This means x is the array [0 0.1 0.2 0.3 ... 9.8 9.9 10.0]. (This might have been a good time to end the line with a semicolon -- no need to see all those x's.) Now

y=x.^2;

plot(x,y,'g')

plots the squaring function, but with more values. The graph will be in green because of the 'g'. Try also things like

y=2*x+3

plot(x,y)

plot(x,sin(x))

plot(x,exp(x))