In: Advanced Math
%%Matlab code for time velocity polynomial
clear all
close all
%all height and time data
t=[0 1 2 3 4 5 6 7 8 9 10];
h=[0.1 1.3 4.2 9.9 16.1 25.2 36.9 50.1 65 80.1 98.1];
%2nd order polynomial fit
pp=polyfit(t,h,2);
%smooth t data
tt=linspace(0,10,101);
%polynomial values
hh=polyval(pp,tt);
figure(1)
%plotting of actual and fitted data
plot(t,h,'r*')
hold on
plot(tt,hh)
xlabel('time')
ylabel('height')
title('time vs. height plot')
legend('Actual data','2nd order polynomial')
%function for height n 2nd order polynomial
syms x
h1(x)=pp(1)*x^2+pp(2)*x+pp(3);
fprintf('\t2nd order polynomial fit for height = ')
disp(vpa(h1,4))
%derivative of the function
v(x)=diff(h1,x);
fprintf('\t2nd order polynomial fit for velocity = ')
disp(vpa(v,4))
%all velocity values
for i=1:length(tt)
vv(i)=double(v(tt(i)));
end
figure(2)
plot(tt,vv)
xlabel('time')
ylabel('velocity')
title('time vs. velocity plot')
%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%
Please enter your own data and rerun the code.