Some MATLAB hints
- To start matlab, you type
- module load math/matlab (should do this only once)
- matlab &
If you want to run matlab without all the fancy windows, use one of the
follwing instead
- matlab -nodesktop
- matlab -nojvm
- Start matlab and type help intro.
-
When you say x*y, this is defined as matrix-matrix multiplication:
the number of columns of x must match the number of rows of
y (unless one of them is a scalar). If
x
and
y
have the same shape, you can multiply each element of
x by the corresponding element of y by using
x.*y .
-
If
x
is a vector, you can get its length with length(x).
If
x is a matrix, you can get its dimensions with
size(x) . This means, for example, that you don't have to pass the
dimensions of the your arrays to your functions; this information can be
retrieved within the function automatically.
-
If you run into any matlab error, you can type dbstop if error
to enter the debugger the next time you run into the error.
You will get a different prompt, where you can type out the values of all
the variables involved in the line where the error occured.
Be sure to exit the debugger with dbquit before continuing.
-
When writing the MATLAB code for the bisection problem, there are three ways
to enter the expression needed for the function f:
- repeat the entire expression everytime you need it (for readability,
assign the expression to a new temporary variable and use the temporary);
- write the expression in a file called f.m using the function syntax
listed by the help function command;
- use the "inline function" syntax explained by the help inline command.
-
To print out a row of numbers, you can use something like
disp([1,3.14159,x]). Vary the number of digits displayed with the
format command (see help format for options).
Alternatively, you can use fprintf (type help fprintf).