# STEER Program Â– Notes

STEER Program Notes

MATLAB

MATLAB allows for easy manipulation of matrices.Â  The following is an interesting take on inverses of matrices that I found in the MATLAB demo programs.

(In MATLAB programs, a Â“%Â” symbol indicates a comment.)

n = 100;Â Â Â  Â Â Â Â Â Â Â

a = rand(n);Â Â  Â Â Â Â %Creates nxn matrix "a" containing random values from 0 to 1.

imagesc(a);Â Â Â Â Â Â Â  %Scales the data in "a" and displays it as an image.

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  %Each element in "a" corresponds to a rectangular

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Â %area in the image.Â  The values of the elements of

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Â %"a" are indices into the current colormap that

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Â %determine the color of each patch.

colormap(hot);Â  Â Â Â %A colormap is an m x 3 matrix of real numbers

Â %between 0.0 and 1.0.Â  Each row is an RGB vector

Â %that defines one color.Â  "hot" is a colormap that

Â %varies smoothly from black, through shades of red,

Â %orange, and yellow, to white.

axis square;Â Â Â Â Â Â  %Makes the current axis square. The x and y axis are

Â %equal lengths and the increments are equal. b = inv(a);Â Â  Â Â Â Â Â %Creates the inverse matrix of "a".

imagesc(b);Â Â  Â Â Â Â Â %See above.

axis square;Â Â Â Â Â  Â %See above. imagesc(a * b);Â Â  Â %Creates the image of the matrix of a * b.

axis square;Â Â Â Â Â  Â %Creates a square plot.Â  Since this should be the

Â Â Â Â Â  Â Â Â Â Â Â Â Â Â Â Â Â Â %identity matrix, one should expect the graph to be

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  %a white line down the diagonal of the matrix,

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  %representing the ones down the diagonal.Â

Â %All else should be black (zeroes). Plotting Graphs in MATLAB - One can also easily plot graphs and sets of graphs in MATLAB.Â  This allows for simultaneous comparisons of functions. %Create a vector of values from 0 to 5, in steps of .5

t = 0:.5:5;

%Create a 2x1 set of graphs.Â  This is the first of two graphs.

%Plot t vs. sin(t).

subplot (2,1,1); plot(t,sin(t));Â

%Repeat for cos(t).Â  This is the second of 2 graphs.

subplot (2,1,2); plot(t,cos(t));