Lab Report #1, Ma402,   2001

Name:                                                                     Student ID.

The Lab report #1 is due 5:00pm, Friday, Aug. 31st.  You can  slide it to the door of Dr. Li's office, HA316. The lab work should be done individually or two persons jointly.


It is  recommended that you work under your sub-directory MA402. See Computer Survival Guide.

1.  Use Netscape ( http://courses.ncsu.edu/classes-a/math/ma402_info/ML5_codes/ML5index.htm) or anonymous ftp:

          ftp ftp.ncsu.edu            or           ftp ftp.eos.ncsu.edu
          login ID: anonymous
          Password: your email address
          cd /pub/math/zhilin/TEACHING/MA402
          cd MATLAB
          get fofdh.m                              to get a single file
          prompt off
          mget *                                      to get all the files in the directory

2.  Practice Matlab

      add Matlab
      matlab

      >> intro                                                                        % Go through  several slides!
      >> help ops
      >> helpwin                                                                  % double click on elfun
      >>  demo
      >> diary lab1.text                                                       % Start recording everything to lab1.text
      >>  a= 3.8;
      >> sqrt(2+a^3.5) + sin(a)*cos(2*a)+tan(a)*log(a) + log10(a) + ...
            abs(a) - atan(a) + 1/exp(a)
      >> a = [ 1 2 3 4 -1]
      >> b = a'
      >>  length(a)
      >>  a = magic(5)
      >> a(4,3)
      >> a(:,1)
      >> a(3,:)
      >> a .* a                                                % What does this do?
      >> who
      >> diary off
      >> ! more  lab1.text                           % Execute a Unix command to print out the lab1.text.

       Questions: What difference do you see when we use colon : or  semi-colon?

 3.  Run the test problem directly

>> t(1)=0; y(1)=200; h = 5; n=60; a=60/65; b=350/65;
>> for k=1:n,
     y(k+1) = a*y(k)+b; t(k+1) = t(k) + h;
   end
>> plot(t,y)
      Questions: What do you do if we want the result for a=1.2; h=4: What happens if we quit Matlab and then want ot redo the computation?

4.  Run the rest problem from the file fofdh.m

     >> fofdh

     Questions: What is a script file of Matlab?  What should we do if we want to change the parameters?

5.  Add labels, titles to the graph. Save the data, save the plot, and get hard a hard copy of the plot.

     Add the following in the fofdh.m file
     grid on
     xlabel('Time in seconds')
     ylabel('Temperature')
     title('Example of Newton's law of cooling')

     print -deps plot1.eps                        % Save the plot as a .eps file
     print -deps plot1.ps                          %  Save the plot as a .ps file
     % ! lpr   plot1.ps                                  %  get a hard copy of the plot without quitting  Matlab
      ! ls                                                          % Excute a Unix command
     save my_matlab_082401                 %  Save my data  if I do not have time to finish. Use
                                                                   % load my_matlab_082401 in Matlab next time to get it back.

      After quitting Matlab, get a hard copy of the plot by typing
           lpr plot.ps

     Questions: What is the function of the symbol % in Matlab?
                            How to you get a hard copy of a plot?
                            How do you save your work if necessary?

6. Run fofdh.m again with

  • tfinal = 3,000; h=150;
  • tfinal = 3,000; h= 100;
  • tfinal = 3,000; h= 50;
  • tfinal = 30,0000; h=200;
  •     Questions: Which results can we trust? Why there is no picture for the last case? Can this happen in terms of mathematical theory? Now try:   tfinal = 30,000, h=1e-5;  what happened?  What is the best choice of h?