

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Name:
EXAM II - BME 201 - SPRING 2011
Instructions: You will have 55 minutes to complete the 3 questions below and the Bonus. There are a total of 120 points available. Partial credit will be awarded if your scratch work is organized neatly. Commenting your code is not required, but will help us to award points when possible. You may use a calculator when needed. Scratch paper is available at the front of class. Good luck!
Question 1 (30 pts):
t = [ 0 0.1 0.2 0.3 0.4 0.5]; % time in seconds P = [ -10 -8 -2 0 2 8]; % position in mm
In the laboratory you perform an experiment tracking the position of a mass through time using a data acquisition card with a sampling rate of F samples/s. The two arrays above contain the first six samples of data that were recorded during the collection.
a. (5) What was the value of F for this data set?
b. (5) Write code to compute the velocity, V=dP/dt of the mass. What is length(V)?
c. (10) Write code to compute the acceleration A = dV/dt of the mass. What is length(A)?
d. (10) Write code to create a figure with 3 subplots arranged in a column:
-Top subplot should be P vs. t. -Middle subplot should be V vs. t. -Bottom subplot should be A vs. t.
*Be sure the arrays you plot are all the same length! Do not include grids, labels etc.
Question 2 (30 pts): Water volume in a reservoir as a function of time can be expressed using the following function: V(t) = 10^9 + 10 8 (1 – e -t/100) - r t
Where V is the water volume, t is the time in days, and r is the town’s consumption rate in liters/day.
(a) (10) Write an anonymous function called resVol that returns the current water volume, V, at a given time, t for r = 10^7 liters/day.
(b) (20) Write code using an anonymous function called critVol and the built-in MATLAB function fzero to find the time, tdrain when the reservoir is half-full (i.e. when V(t) = 0.5*V(0)). Assume a good initial guess for tdrain is 50 days and fzero is used as specified below.
X = FZERO(FUN,X0) tries to find a zero of the function FUN near X0, If X0 is a scalar.
Question 3 (40 pts):
a. (30) Create a user-defined function called WackSum.m that takes an input array (with length>=2), called input and outputs a scalar called wackysum that is the solution to the following simple rule:
*If the n+1 th^ element of the input array is greater than or equal to the n th^ element of the input array, add the value of the n+1 th^ element to the n th^ element. Else subtract the value of the n+1 th^ element from the n th^ element. Do this stepping through each element of the input array in order to create a cumulative scalar value called wackysum.
For example, for the array below called testinput1 your function should return the value 9 for wackysum (i.e. 3 + 4 - 1 + 1 + 2 = 9)
testinput1 =
NOTE: Be sure your code will work for input arrays of any length >=2.
b. (10) Show how you would call your function from the command line or a script file for input testinput2. Then trace step-by-step through each iteration of the code inside your function to determine the wackysum for:
testinput2 =
*BONUS (20 pts):
updown = [2, 4, 6, 5, 8, 7 ]; time = [1, 2, 3, 4, 5, 6 ];
(10) Write a Matlab function called locatetime.m that takes two input arrays (time and updown) and returns an array called endtime that contains the time values when the value of the array updown is both greater than 4 and also decreasing. Your code should work for input arrays of any length. Feel free to use either a for or while loop in your function.
(5) Demonstrate how you would call the function from the command line or a script file for the two arrays given above.
(5) What is the final value of the endtime array?