In: Computer Science
Write a MATLAB function named myaccel that accepts three inputs and has a single output.
Inputs:
Output:
Example:
time=0:10; position=time.^3; myaccel(time,position,2.8) % should return 22.8
Fucntion Code
function y = myaccel(time,pos,tq)
pval = pos(time);
h = time(2)-time(1);
y2 = zeros(1,length(time));
for i=1:length(time)-2
y2(1,i) = (pval(i+2)-2*pval(i+1) + pval(i))/h^2; %Formula for
forward difference second order
end
y = interp1(time,y2,tq); %interpolation function
end
=============================
Script code to call above function
syms time
position = matlabFunction(time.^3); %Position function
defined
time = 0:10;
y = myaccel(time,position,2.8)
=================================
Results
========================================