Lab Activity 4 - Answer Sheet

Name: ___________________________________    NetID: _____________________ Section#: ______

This lab is worth 12 points.  Each problem is worth 2/3point.

Part 1: Programming the find_h function

  1. Write down the five equations (by plugging in i from 1 to 5):

    K2*(h1-h2)+K1*(h1-HL)=B1
    K3*(h2-h3)+K2*(h2-h1)=B2
    K4*(h3-h4)+K3*(h3-h2)=B3
    K5*(h4-h5)+K4*(h4-h3)=B4
    K6*(h5-HR)+K5*(h5-h4)=B5
        

    Note: accept either h0 or HL and likewise with h6 or  HR.

  2. Rewrite the five equations in question 1 such that the coefficients for each unknown are grouped properly and all the constants are moved to the right hand side. The first equation has been done for you:

    (K1+K2)*h1 + (-K2)*h2 = B1 + K1*HL
    
    (-K2)*h1 + (K2+K3)*h2 + (-K3)*h3 = B2
    (-K3)*h2 + (K3+K4)*h3 + (-K4)*h4 = B3
    (-K4)*h3 + (K4+K5)*h4 + (-K5)*h5 = B4
    (-K5)*h4 + (K5+K6)*h5 = B5 + K6*HR

  3. Convert these equations into an equivalent matrix equation in this form (look up MP1 Math section for the general form, but we will use N=5 for our case):  Convert the above system of equations into the matrix form lhs * y = rhs.

    | K1+K2 -K2   0     0     0     |   | h1 | = | B1+K1*HL  |
    | -K2   K2+K3 -K3   0     0     |   | h2 | = | B2       |
    | 0     -K3   K3+K4 -K4   0     | * | h3 | = | B3       |
    | 0     0     -K4   K4+K5 -K5   |   | h4 | = | B4       |
    | 0     0     0     -K5   K5+K6 |   | h5 | = | B5+K6*HR |
  4. Fill in the blanks to create the matrix main:

    main = diag( K(1:N) + K(2:N+1), 0 );
  5. Fill in the blanks to create the matrix upper:

    upper = diag( -K(2:N), 1 );
  6. Fill in the blanks to create the matrix lower:

    lower = diag( -K(2:N) , -1 );
  7. Fill in the blanks to create the matrix rhs in 3 steps:

    rhs = B ; 
    rhs(1) = B(1)+K(1)*HL ;
    rhs(N) = B(N)+K(N+1)*HR ;
  8. Fill in the blank to solve the system of equations using the backslash (\) operator, and store the result in a vector h:

    h = lhs \ rhs ;
  9. Fill in the blank to transpose the column vector h into a row vector.
       h = _______ h' _________; % hint: use the transpose operator ' and the vector h  

Part 2: Global variables in Matlab

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

  2. >> x
    x =
    __________5___________________
    >> y
    y =
    ___________1__________________
    >> result
    result =
    _________Undefined function or variable 'result'. (or something equivalent to this)______________________

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

  4. >> result = dummy(-4)
    result =
    _____________0________________
    >> y = dummy(0)
    y =
    _____________4________________
    >> result
    result =
    ____________0_______________


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

  6. 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 =
    __________5___________________
    >> y = dummy(-4)
    y =
    __________0___________________
    >> x
    x =
    ___________4________________

  7. 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:


  8. 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 =
    ___ 6 _____




    Part 3: Dynamics

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


    dydv = _______[v ; (c./m) .* v.^2 - g ];_____(may use dot form of the operators and some versions of Matlab may require the parenthesis)

  10. 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 = ______99.15 or something around 100 sec_____ (approx.)


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

    v = __________-52.38_______or something close to -50_______________________________________(approx.)
    (Of course this is the same answer as in prelab 5 question 6b)

  12. 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 = _____________27 meters2_____or any integer from 23 thru 31. The actual answer is 27.436______

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


  14. function dxdydz = Derivatives_xyz(t , xyz)
    x = xyz(1);
    y = xyz(2);
    z = xyz(3);
    dxdydz = [ ___________10*(y-x)______; _____-y + 28*x - x*z_______ ; _______(-8/3)*z + x*y__________