0% found this document useful (0 votes)
91 views6 pages

Part 1: Programming The Find - H Function: Lab Activity 4 - Answers

This document contains the steps to solve a system of equations modeling heat transfer using matrices in MATLAB. It involves writing the equations, rearranging them, converting to a matrix equation of the form Ax=b, defining the matrices using diag(), and solving the system using backslash. It also covers using global variables in MATLAB functions and defining functions to model dynamics problems involving derivatives.

Uploaded by

Michael Yoo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views6 pages

Part 1: Programming The Find - H Function: Lab Activity 4 - Answers

This document contains the steps to solve a system of equations modeling heat transfer using matrices in MATLAB. It involves writing the equations, rearranging them, converting to a matrix equation of the form Ax=b, defining the matrices using diag(), and solving the system using backslash. It also covers using global variables in MATLAB functions and defining functions to model dynamics problems involving derivatives.

Uploaded by

Michael Yoo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab Activity 4 - Answers

Name: __________________________ NetID: _______________ Section#:


______

Part 1: Programming the find_h function


1. 1. Write down the five equations (by plugging in i from 1 to 5):
For example your first equation (for i = 1) should look like this:
____________________K2(h1-h2) + K1(h1-HL) =B1___________________

Remember: h0 is given as HL, while h6 is HR for this case. They are given
constants and NOT part of the final h that we're trying to solve.
______ K3(h2-h3) + K2(h2-H1) =B2_____________________
K4(h3-h4) + K3(h3-H2) =B3_______________________________

_________ K5(h4-h5) + K4(h4-H3) =B4______________________________

_________ K6(h5-h6) + K5(h5-HR) =B5_____________________________

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 + K1HL________________

_________(K2+K3)h2 + (-K3)h3 = B2 + K2H1


_______________________________________________________

______(K3+K4)h3 + (-K4)h4 = B3 + K3H2


_______________________________________________________________

_______(K4+K5)h4 + (-K5)h5 = B4 + K4H3


___________________________________________________________________

____(K5+K6)h5 + (-K6)hR = B5 + K5H4


_____________________________________________________________________

3. #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):

Make sure HL and HR are moved to the right hand side since they are part of
the constant terms.
Write down the equation that you are going to solve, in the matrix
form [matrix]*[column vector] = [column vector]. (Hint: see the matrix
equation in the MP 1 write-up above equation_4 in the 3. Math section.)
*

4. Fill in the blanks to create the matrix main:


main = diag( _____________________________ , ________ );

5. Fill in the blanks to create the matrix upper:


upper = diag( _____________________________ , ________ );

6. Fill in the blanks to create the matrix lower:


lower = diag( _____________________________ , ________ );

7. Fill in the blanks to create the matrix rhs in 3 steps:


8. rhs = _______________ ;
9. rhs(1) = ____________________________________ ;

rhs(N) = ____________________________________ ;

10. Fill in the blank to solve the system of equations using the backslash (\)
operator, and store the result in a vector h:
h = __________________________________ ;

11. Fill in the blank to transpose the column vector h into a row vector.
12.

h = ________________; % hint: use the transpose operator ' and the


vector h

Part 2: Global variables in Matlab

13. Write the value that Matlab returns when you type the following at the
command prompt:
>> x
x=
_____________________________
>> y
y=
_____________________________
>> result
result =
___________________________
14. 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 =
___________________________
15. 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=
___________________________
16. 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: Dynamics
17. Fill in the blank to complete the code for the function
named Derivatives_resistance .

dydv = _________________________________________________________
18. 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.)
19. 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)
20. 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 = ______________________________________________________
21. 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 = [ ______________________________;
_________________________________ ;
___________________________________];

You might also like