For this project you may work individually or in pairs (no groups larger than two). Two students working together need only turn in one printout with both names on it. You should not share answers with anybody other than your "teammate". Make sure you are familiar with the student honor code.
Important reminder! As soon as you enter MATLAB, remember to start saving your session, either by using the diary command as in Project 1, or by whatever other means you found works for you.
Write a MATLAB program to produce the matrix of the linear transformation from R2 to R2 that rotates vectors counterclockwise through a given angle. (The formula for the matrix is given in Example 3 on pp. 77-78.) This matrix is a function of the angle (measured in radians), so your program will compute a function of one variable that outputs a 2 x 2 matrix. MATLAB knows the functions "sin" and "cos", and the number "pi" (lower-case).
Once you've stored your program in a .m-file, you can test it by seeing if it gives the correct matrices for some angles whose sine and cosine you know. For example, if your .m-file is "rotate.m", typing "rotate(pi/3)" should give you a 2x2 matrix whose rows are [0.5000, -0.8660] and [.8660, 0.5000]. You will also be able to test it graphically in problems below.
When you are satisfied that your program is correct, again use the "type" command to include the file contents in your output, but first make sure you begin and end the file with good visual separators.
regular_N=[ ... ]where "..." stands for the entries of your 2x9 matrix. Then, once you start up MATLAB, any time you type "regular_N" MATLAB will interpret that to be the matrix stored in your .m-file. Make sure you don't name this file with a common variable name like "A.m", because as long as this file exists, MATLAB will think that the variable A stands for the matrix stored in A.m.
Now start up MATLAB. At the prompt, type "regular_N" (or whatever you named your matrix). You will be using this matrix a lot below, so during this MATLAB session give it a second name, B, by next typing "B=regular_N".
MATLAB can plot a set of points in the xy plane using the "plot" command. To learn how this works, type "help plot" and read what MATLAB says. Then to plot the N in figure 1, you can do the following:
plot(x,y,'.-')(make sure you use the correctly slanted apostrophes). As you can see from reading the output of "help plot", the period after the first apostrophe tells MATLAB to put dots at each point whose x-coordinate is given by an entry in your vector x and whose y-coordinate is given by the corresponding entry in your vector y; thus the points whose columns were given by the matrix B will be plotted. The hyphen after the period tells MATLAB to draw a solid line between consecutive points. If you're working on Unix, a window should pop up with the plot.
axis([-10 10 -10 10])This will re-fit your plot into a box that runs from -10 to 10 along each axis. Otherwise MATLAB's default is to scale the picture vertically and horizontally so that it just fits into a box of predetermined physical size, which would defeat the purpose of this project: to see how your picture changes under vairous linear transformations, with the location and scale of the coordinate axes held fixed. (Note: typing "grid" toggles between superimposing a rectangular grid on your plot and removing the grid. You may be able to re-size the plot window so that this grid appears square.)
Input the two-by-two matrices A and S defined on p. 156. To see the effect of multiplication by A, plot the second row of A*B against the first row, just as you plotted the second row of B against the first row to view the "regular N". After you enter the plot command, again type
axis([-10 10 -10 10])to rescale your axes so that you can meaningfully compare this plot to the previous one. Below, enter this "axis" command every time you plot something new. (It's your option whether also to use the "grid" command to superimpose the coordinate grid on your plot as well.) Print your plot.
Next see the effect that multiplying by S has on your slanted N by bringing up a new plot window and plotting the rows of S*A*B against each other. Print your plot. How does this plot differ from the previous plot?
rotB=rotate(pi/6)*Band then plot the second row of rotB against the first row.) Print your plot.
reflx=[1 0; 0 -1]and
refly=[-1 0; 0 1]Appropriately multiplying matrices, plot the effect of the linear transformations corresponding to reflx and refly on your slanted N (the result of S*A*B). Print your plots. Describe in words what these linear transformations did.
reflxy=[0 1; 1 0]Let rotB be the matrix you constructed in problem 4. Bring up a new plot window and re-plot the corresponding rotated N (using the same "axis" command as before), but don't print the plot yet. Type
holdTo see the effect that the linear transformation has on the rotated N, multiply reflxy*rotB. This time do not bring up a new plot window. Enter the commands to plot the second row of reflxy*rotB against the first. The "hold" command that you entered will cause the plot to be superimposed on the previous plot. Print out the double-plot, and describe in words the effect that multiplying by reflxy had on your rotated N.
Another way to do such a double-plot without using the "hold" command is to enter
plot(x1,y1,'.-',x2,y2,'.-')where x1,y1 are the first pair of x and y vectors you want to plot against each other and x2,y2 are the second pair. However, the two plots then come up simultaneously, so it's harder to tell which plot is which.