How to evaluate a first/second derivative for 5th order spline?
Show older comments
I am using 5th order spline for my function. I want to evaluate its first and second derivative. For example, I am using the code as follows
if true
x = [0,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1];
y = [0,0.7071,1,0.7071,0,-0.7071,-1,-0.7071,0];
k = 5;
sp = spapi( optknt(x,k), x, y );
xx = 0:.005:1;
yy = fnval(xx,sp);
v_o = 2*pi*cos(2*pi*xx); % First Derivative
a_o = -(2*pi)^2*sin(2*pi*xx); % Second Derivative
plot(xx,yy);
hold on; figure, plot(xx,v_o);
plot(diff(yy,1)); hold off % inaccurate first difference
hold on; figure, plot(xx,a_o);
plot(diff(yy,2)); hold off % inaccurate second difference
end
Please, tell me how can I find first and second derivative for 5th order spline. Thanks
1 Comment
Abdul Mannan
on 8 Sep 2015
Edited: Abdul Mannan
on 8 Sep 2015
Answers (0)
Categories
Find more on Spline Construction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!