Each of the problems below is intended to be solved by generating a script or m-file. Be sure to have a very clearly written header for each M-file so that anyone reading your work can decipher the sort of problems you are solving in each M-file. Also, be sure to label all axes and assign each plot a title.

A complete set of m-file solutions can be found here. Of course, your work does not have to look exactly like these scripts but the results (e.g. plots) should look much the same. Donít be lazy and start by looking at these answers Ö only refer to these solutions if you get stuck or want to check your finished work.

Click here to see what your resulting plots should look like.

  1. Read the HELP pages on the following functions (either by typing "help" and then the function name at the MATLAB command prompt, or by clicking these links): plot (concentrate on how to plot using different symbols and colors), subplot, zoom, figure, close, text, loglog, semilogx, semilogy, prod, load, save, length.
  2. Start by using the same M-file you generated for problems #8-14 on PS#1. The objective here will be to modify this M-file using the SUBPLOT command so that now you will make 4 separate plots on a single page. You only have to worry about accomplishing problem #13 from PS#1. Make each of your four plots have a different line style along with separate titles and axis labels. Print the resulting plot figure.
  3. Repeat Problem #2 but now use 4 different data symbols of your choice for each one of the 4 subplots. Be sure that only the data points are plotted and are not connected by lines. You should notice that if you plot ALL of the data points using symbols that graph gets a bit messy. One way to get around this is to use less points between the minimum (W = neg_pi.jpg (893 bytes)) and maximum (W = pos_pi.jpg (951 bytes)). Print the resulting plot figure.


    For problems #4 and 5 be sure to use the title, label and text commands to clearly identify what it is you are plotting in each graph. Submit one plot and one M-file. Click here to see what your resulting plot should look like.
  4. Generate an array X that starts at 0.0 and goes to 10.0 in steps of 0.001.
  5. Use the subplot command to generate 4 plots on a single page which are
    (1) X vs eX, (2) X vs e-X, (3) X vs semilogy(eX) and (4) X vs semilogy(e-X).


    For problems #6-9 we are going to write and test an M-file that generates a series expansion of "e" which is:

                            
    e_expand.gif (451 bytes)

    Submit a single M-file and two plots. As always, be sure to clearly label each data line in your graph so that I know what you are plotting. Click here to see what your resulting plots should look like.
  6. Generate an array X that starts at 0.0 and goes to 1.0 in steps of 0.0001.
  7. Plot X vs eX using the built-in Matlab function for "e" (i.e., EXP(X)).
  8. Use the series equivalent for e to calculate 10 new values for e and call them EXP1, EXP2, EXP3, EXP4 ... EXP10. Here EXP1 calculates e only using the first factorial term (i.e. e_first_term.gif (112 bytes)), EXP2 calculates e using both the first and second factorial terms (i.e., e_second_term.gif (164 bytes)), EXP3 calculates e using the first, second and third factorial terms (i.e., e_third_term.gif (214 bytes)) and so on up to EXP10 which calculates e using the first ten factorial terms.
  9. Now, on the same plot generated in problem #7 plot X vs EXP1X, X vs EXP2X,
    X vs EXP3Xand so on up to and including X vs EXP10X. Use different line styles for each trace and use the TEXT command to tell me what lines correspond to what series expansion (i.e., EXP1, EXP2, ... EXP10).
  10. Now, repeat #8 exactly except instead of using the plot command use the semilogy command to plot your data.

    For problems #11-13 we are going to examine sinusoidal functions as they grow and decay in an exponential fashion. Submit a single M-file and a single plot. Click here to see what your resulting plot should look like.

  11. Generate an array X that starts at 0 and goes to 50pi.gif (52 bytes) in steps of 0.01.
  12. Generate another array Y that starts at 0 goes to 6.0 where the increments between 0 and 6.0 are such that the length of vector Y is the same as vector X.
  13. Use the subplot command to generate 4 plots on a single page evaluating the following functions: (1) Y vs eYsin(X), (2) Y vs e-Ysin(X),
    (3) Y vs semilogy(eYsin(X)) and (4) Y vs semilogy(e-Ysin(X)). N.B. remember that you cannot take the logarithm of a negative number ... So you're going to have to do "something'" to your sin function or at least the data it generates to get this problem to come out correctly.


    For problems #14-17 we are going to learn how to both save and load ASCII data files. Submit a single M-file and a single plot. Click here to see what your resulting plot should look like.

  14. Write a matlab M-file to evaluate the following expression: siny_over_siny2.gif (258 bytes), where Y is an array that goes from 0 to 5pi.gif (52 bytes) in steps of pi_over_100.gif (119 bytes).
  15. Plot Y vs. X in one panel of a 4 panel subplot with axis limits as follows : abscissa 0 to 16 and ordinate -30 to +30. N.B. For this problem Y is the abscissa and X is the ordinate.
  16. Now, save X into a data file named PS2.dat using 16-digit ASCII form. Then load this file back into Matlab and plot the data in PS2.dat against the data you generated in problem #14. That is plot X vs. PS2.dat in one of the panels of a 4 panel subplot.
  17. Multiply the two data vectors together (X∑PS2) and plot X vs. X∑PS2 in one of the panels of a 4 panel subplot. For this plot set the axis limits as follows: abscissa -30 to +30 and ordinate 0 to 750.
  18. Subtract the two data sets (X - PS2) and plot X vs. (X - PS2) in the last remaining panel of the 4 panel subplot.

To continue on to the next core lesson, click here.