STEER Program – Notes

STEER Program Notes


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));