Lab Activity 5 - Answer Sheet



Name: ____________________________ NetID: _________________ Section#: ______


Part 1: Prelab

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

y=x7- ln4(x)
with an initial guess of x= 5. (Don't write the root 0.6359 approx.)

_____________________________________________________________

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

y=x4 - ln4(x) on the interval [1,2].


____________________________________________________________

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




on the interval [1,5]. (Don't write the answer 15.3662. Just the Matlab code that gives the answer.)

____________________________________________________________

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



the interval [1,5] using 100 points. (Don't write the answer
15.3660. Just the Matlab code that gives the answer.) You may use multiple lines.

x = __________________________________________________________


y = __________________________________________________________


trapz( ____________________________ , ________________________________)




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

z = cos( sqrt(x2 + y2)) / sqrt(x2 + y2)

over the interval [-10,10] x [-10,10] in the x-y plane.

>> x = linspace(-10,10,400);

>> y = x;

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

>> ZMAT = _________________________________________________________________________

>> surf( XMAT , YMAT , ZMAT )

6. We want to model the motion of a free falling object using the first order ordinary differential equation: http://en.wikipedia.org/wiki/Free_fall



(see also Classical Mechanics: A Modern Perspective 2nd ed. Barger and Olsson p. 8) where the mass of the object m = 75 Kg ,the acceleration due to gravity g = 9.8 m/s2 and


and

drag coefficient CD = 0.51, http://en.wikipedia.org/wiki/Drag_coefficient

cross-sectional area of the object, perpendicular to air flow A = 1.1 m2 ,

air density ρ = 1 Kg/ m3 ,

We want to solve for the vertical velocity v (which is a function of t written v = v(t) ) using the Matlab ODE solver ode45. Assume that at time t = 0, v = 0

( v(0) = 0).

To solve this equation we would type,

>> [ t,v] = ode45(@vprime, [0,100] , 0);

But we first need to complete the function named vprime.

a) Complete the function vprime by filling in the blank below.

function dv = vprime(t,v)

m = 75;

CD = 0.51;

A = 1.1;

rho = 1;

g = 9.8;

dv = ____________________________________________________________________________

b) Using this model what is the terminal velocity ? _____________________

(Hint: try plot(t,v) or v(end) )





Part 2: Global variables in Matlab

  1. Write the value that Matlab returns when you type the following at the command prompt:

>> x
x =
_____________________________
>> y
y =
_____________________________
>> result
result =
___________________________

  1. Write the value that Matlab returns when you type the following at the command prompt:

>> result = dummy(-4)
result =
_____________________________
>> y = dummy(0)
y =
_____________________________
>> result
result =
___________________________


  1. In the editor modify the code for the dummy function by adding the global command as shown below,

function result = dummy(parameter)
global x
x = 4;
result = x + parameter;


Write the value that Matlab returns when you type the following at the command prompt:
>> global x
>> x
x =
_____________________________
>> y = dummy(-4)
y =
_____________________________
>> x
x =
___________________________

  1. In the editor modify the code for the dummy function by removing the statement x =4; so that your function should now look like the following:


function result = dummy(parameter)
global x
result = x + parameter;


Write the value that Matlab returns when you type the following at the command prompt:
>> x = 10;
>> y = dummy(-4)
y =
_____________________________



Part 3: Discretization of sound

  1. If the sound has been recorded backwards then let's solve the problem of understanding the mystery message. Specifically, the problem is that if
    volts = [v1 v2 v3 ... vn] then we actually want [ vn ... v3 v2 v1]. Fill in the blanks and then type in this command to listen to the message.

    >> flipvolts = volts( _________ : _________ : __________);
    >> message = audioplayer(flipvolts,frequency);

    >> play(message)

  2. What is the mystery message that with enlighten mankind?

    _____________________________________________________________________________________________

  3. Write the command to display the number of values the vector flipvolts contains, (don't use size, that's for matrices)

    >> __________________________________

  4. Fill in the blank below with the new vector which is the old sound + new sound. You should hear the echo effect.

    >> player = audioplayer( (_______________________________)/peak , frequency);
    >> play(player)




Part 4: Dynamics

  1. Fill in the blank to complete the code for the function named Derivatives_resistance .


    dydv = _________________________________________________________

  2. What is the time (in seconds approximately) when the object hits the ground (y = 0) ? Hint: plot t versus y. Use grid on command too.

    t = _________________________________________________ (approx.)


  3. What is the velocity ( meters/second approximately) when the object hits the ground (y = 0)?

    v = _________________________________________________(approx.)
    (Of course this is the same answer as in prelab 5 question 6b)

  4. Increase A (area) in the function named Derivatives_resistance so that the terminal velocity is about -10 meters/second. Round answer to nearest integer value.

    A = ______________________________________________________

  1. Complete the function named xyzprime that will compute the derivatives of the three dependent variables x, y and z , by filling in the blanks.


function dxdydz = Derivatives_xyz(t , xyz)
x = xyz(1);
y = xyz(2);
z = xyz(3);
dxdydz = [ ______________________________; _________________________________ ; ___________________________________];


  1. The actual data points (x,y,z) are plotted using A) squares
    B) stars
    C) circles
    D) diamonds