필터 지우기
필터 지우기

How to evaluate a first/second derivative for 5th order spline?

조회 수: 5 (최근 30일)
Abdul Mannan
Abdul Mannan 2015년 9월 8일
편집: Abdul Mannan 2015년 9월 8일
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
Abdul Mannan
Abdul Mannan 2015년 9월 8일
편집: Abdul Mannan 2015년 9월 8일
OK. I got the answer but I am not erasing the question for the future use.
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);
dsp = fnder(sp);
dyy = fnval(xx,dsp);
ddsp = fnder(sp,2);
ddyy = fnval(xx,ddsp);
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(xx,dyy), title('first derivative'); hold off
hold on; figure, plot(xx,a_o);
plot(xx,ddyy); title('second derivative'); hold off
end
Use it and please wish me peace and blessings.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by