MATLAB PLEASE HELP The height and upwardgoing velocity of a
MATLAB. PLEASE HELP!!!!!
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
Part 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,
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)
Part 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.
Part C
Use the max function to determine the maximum height of the rocket and the corresponding time with an accuracy of 0.01 sec.
Part D
Repeat part (c) using the function fminbnd and compare the accuracy of the result with that part (c).
Part 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.
Part 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
Part 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.
Solution
function h =height(t)
h=zeros(size(t));
for k=1:length(t)
h(k)=2.13.*(t(k).^2)-0.0013.*(t(k).^4)+0.000034.*(t(k).^4.751);
if h(k)<0
h(k)=0;
end
end
end
function v =velocity(t)
v=zeros(size(t));
h=v;
for k=1:length(t)
h(k)=2.13.*(t(k).^2)-0.0013.*(t(k).^4)+0.000034.*(t(k).^4.751);
if h(k)<0
v(k)=0;
else
v(k)=4.26.*t(k)-0.0052.*(t(k).^3)+0.000161534.*(t(k).^3.751);
end
end
end
B)
t=0:0.01:70;
h=height(t);
x=find(h==0);
t1=t(x(2));
disp([\'time when rocket hits the ground = \' num2str(t1) \' seconds\']);
>> m12
time when rocket hits the ground = 63.02 seconds
>>
C)
t=0:0.01:70;
h=height(t);
[x,t1]=max(h);
disp([\'maximum height that the rocket reach = \' num2str(x) \' metres\']);
disp([\'time when rocket reaches maximum height = \' num2str(t(t1)) \' metres\']);
>> m13
maximum height that the rocket reach = 1470.1873 metres
time when rocket reaches maximum height = 40.5 metres
>>

