## Introduction

Matlab® is a product of the Mathworks.

This page contains some miscellaneous commands which will help you learn Matlab, but don't deal with numeric code. The topics are laid out in the left hand frame in approximate order of importance. You do not have to learn the full contents of one topic before you procede to the next.

#### Getting and Starting Matlab

If you want a free version of Octave, you can follow the instructions here. Please note, there are minor differences between Octave and Matlab, but most of the syntax is the same, at least fro what you will be learning. You can also visit www.octave.org or go directly to the download site for Windows. For other platforms, see Octave's main page.

If you are using a Unix account, it is likely that Matlab is already installed. To run Matlab from home, you can go to the C.H.I.P. in MC 1052, pay \$20.00 for a copy of X-Win 32 from which you will be able to connect to your Unix host from home. You also have the option of paying \$180.00 for your own copy of Matlab.

N.B., while engulf used to have Matlab running, at the current time, no unix machines have Matlab installed.

To start matlab, just type matlab at a Unix prompt or double click on the Matlab icon under either Mac or Windows.

If you already know C, a lot of Matlab code will be familiar to you. The main advantage of Matlab over C when doing numerical calculations is that Matlab is interpreted. That is, you can see the result of one command before you continue on to the next one, unlike C where you must compile the source each time you make a change.

#### Getting Help

The most useful command in Matlab is help. This brings up a description of the command you are asking help for. An example of this is:

```>> help det

DET    Determinant.
DET(X) is the determinant of the square matrix X.

Use COND instead of DET to test for matrix singularity.

help sym/det.m

```

All examples in these tutorials will have two greater than symbols followed by a command which can be cut and paste into your version of Matlab. Any output is displayed in red.

Note in the above example, I asked for help on det and instead, the help page indicates that you should use DET(X). This is explained by the following line from help help:

```
out.  Always type commands in lowercase since all command and
function names are actually in lowercase.

```

When asking for help for operators, for example, +, .*, or ', Matlab will bring up a help page which looks like:

```
>> help +

Operators and special characters.

Arithmetic operators.
plus       - Plus                               +
uplus      - Unary plus                         +
minus      - Minus                              -
uminus     - Unary minus                        -
mtimes     - Matrix multiply                    *
.
.
.

```

In order to find help for the specific operator in question, you must enter the word in the first column. For example, you would use help plus, help times, and help transpose when looking for help on .*, and ', respectively.

Another useful function is lookfor which will search through all the help pages looking for that particular word. This is useful if you know a concept but do not know the name of the function which implements it.

```>> lookfor determinant

>> lookfor determinant
DET    Determinant.
DET    Symbolic matrix determinant.
DRAMADAH Matrix of zeros and ones with large determinant or inverse.

```

The function which tells you where to find the source code for the particular function. Some functions in Matlab are built in, so their source code is not viewable, but most functions are written using Matlab code which you can inspect, copy from, and modify:

```>> which det

det is a built-in function.

>> which sortrows

/.software/arch/matlab-6.1/distribution/toolbox/matlab/datafun/sortrows.m

```

To view the source, you can edit the above file.

The comment character in Matlab is the percent symbol % and comments out everything up to the next new-line character.

```>> A = [ 1  2  3  4  5     % this is the first row of the matrix
6  7  8  9 10
11 12 13 14 15 ]   % this is the last row, along with a closing bracket

A =

1     2     3     4     5
6     7     8     9    10
11    12    13    14    15

```

Like in C and Java, you can assign to variables using =. If you do not assign output to a variable, Matlab automatically assigns it to the variable ans.

```>> det( A*A' )   % find the determinant of A multiplied by the transpose of A

ans =

0

```

The command who gives you a list of all variables to which you've assigned to.

```>> who