The height and upward-going velocity of a rocket (in meters and m/sec) can be re
ID: 3690256 • Letter: T
Question
The height and upward-going velocity of a rocket (in meters and m/sec) can be represented by the following equations:
f(t) = 2.13 t 2 0.0013 t 4 + 0.000034 t 4.751
u(t) = 4.26 t 0.0052 t 3 + 0.000161534 t 3.751
a. Write two MATLAB functions (as two M-files) that compute the height and velocity of the rocket by the above equations, but they also give zero height and zero velocity for all t’s for which f(t) < 0, that is, after the rocket hits ground. Mathematically,
h(t) = f(t), if f(t) 0
0 , if f(t) < 0 ,
v(t) = u(t), if f(t) 0
0 , if f(t) < 0
The MATLAB functions must accept any vector of times t, and return the output vectors h(t), v(t), e.g., with usage: h = hfun(t) v = vfun(t)
b. Generate a vector of equally-spaced time instants t over the interval 0 t 70 sec with step-increment of 0.01 sec. Use the find function to determine the time when the rocket hits the ground to within 0.01 sec.
c. Use the max function to determine the maximum height of the rocket and the corresponding time with an accuracy of 0.01 sec.
d. Repeat part (c) using the function fminbnd and compare the accuracy of the result with that part (c).
e. Repeat part (d) using the function fzero applied to the velocity v(t), noting that the velocity is zero when the maximum height is reached.
f. Using fminbnd determine the maximum positive velocity and the corresponding time. Note that the maximum negative velocity is when the rocket hits the ground.
g. Make a plot of h(t) versus t and add the maximum and ground points, as well as the maximum-velocity points, on the graph. Also, plot the velocity v(t) vs. t and add on the graph the maximum (positive) velocity, also add the velocity at which ground is reached, as well as the zero-velocity or maximum-height point.
Explanation / Answer
function result = hfun(t)
%calculate f(t) = 2.13t^2-0.0013t^4+0.000034t^4.751
for i = 1: length(t)
hft = 2.13 * power(t(i),2) - 0.0013 * power(t(i),4) + 0.000034 * power(t(i),4.751)
if(hft < 0)
result(i) = 0;
else
result(i) = hft
end
end
end
function result = vfun(t)
%calculate u(t) = 4.26t-0.0052t^3+0.000161534t^3.751
for i = 1: length(t)
uft = 4.26 * t - 0.0052 * power(t(i),3) + 0.000161534 * power(t(i),3.751)
hft = hfun(t)
if(hft < 0)
result(i) = 0;
else
result(i) = uft
end
end
end
disp(hfun([1 2 4 8 16 32 64 128]))
disp(vfun([1 2 4 8 16 32 64 128]))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.