CS101 Prelab 5

Name: _________________________

 

Netid: ___________________     Section: ___________

 

 

Print out this page and fill in the blanks to answer the following questions. Hand in this assignment at the beginning of Lab activity #5. You should use the material found in Lecture 5,6 and 7 of the course notes and/or Matlab by Pratap Chapters 4.3.3, 5.6, 6.1,6.3, 4.1, 5.4 and 4.3.6 .  As with all prelabs/labs, if you are not sure of the answer you may go to any EWS lab on campus and check your results by using Matlab, or you can ask anyone of the CS101 staff for help.

 

1. Using the built-in function fzero write the Matlab command(s) to find a root of the function



with an initial guess of
x = 1. (Don't write the root)

 

      fzero('x.^2 - sin(cos(10*x))',1)    ( * or .*)

      or

 

     fzero(@(x) x.^2 - sin(cos(10*x)),1) ( * or .*)

                 ___________________________________________________

 2. Using the built-in function fplot write the Matlab command to plot the function



on the interval .

 

      fplot('x.^2 - sin(cos(10*x))',[-2*pi 2*pi])  ( * or .*)

      or

 

      fplot(@(x)x.^2 - sin(cos(10*x)),[-2*pi 2*pi])  ( * or .*)

                ___________________________________________________

3. Using the built-in function quadl write the Matlab command to compute the definite integral of the function

on the interval . (Don't write the answer just the Matlab code that gives the answer.)

quadl('2 .* exp(-x .^ 2)- log(x)',1,2)

                                __________________________________________________

4. Using the built-in function trapz write the Matlab command to compute the definite integral of the function

on the interval  using 100 points. (Don't write the answer just the Matlab code that gives the answer.)

You may use multiple lines.

 

                                x = linspace(1,2,100)

 

      y = 2 .* exp(- x .^ 2)- log(x)

 

      trapz(x,y)

 

                                __________________________________________________

5. Complete the following Matlab code, by filling in the blanks, to plot the surface described by the equation,

            over the interval  in the x-y plane.

 

                  x = linspace(-3,3,50);

      y = x;

      [XMAT, YMAT ] = meshgrid(x,y);

      ZMAT = __ XMAT .* YMAT.*(XMAT.^2 - YMAT.^2) ./ (XMAT.^2 + YMAT.^2);____(must use .* and .^_

          surf( XMAT , YMAT , ZMAT )

 

6. Given x = [ 1    2   3    4    5] and y = [ 1   4    9    16    25]  ,  circle the choice(s) that give(s) an identical plot to plot(x,y). There may be more than one correct answer.

 

      a)plot( x, x.*x)

 

 

      b) plot( x, x*x)

 

 

      c) plot( y , x)

 

 

      d) plot(y)