필터 지우기
필터 지우기

How to make a spline with end point limits?

조회 수: 4 (최근 30일)
Abdul Mannan
Abdul Mannan 2015년 9월 15일
댓글: Abdul Mannan 2015년 9월 15일
I want to make a spline of some data x (input) and y (output), with constrained slope (first derivative) and zero initial and final 2nd derivative. For example
if true
x = [ 0, 0.125, 2*0.125, 3*0.125, 4*0.125, 5*0.125, 6*0.125, 7*0.125, 8*0.125 ];
y = [0, sin(2*pi*f/8), 1, sin(2*pi*3*f/8), 0, sin(2*pi*5*f/8),-1,sin(2*pi*7*f/8), 0];
end
I know that I can find fifth order spline with this like
if true
k = 8;
sp = spapi( optknt(x,k), x, y );
xx = 0:0.0001:1;
yy = fnval(xx,sp); % Evaluating data for xx using given spline
dsp = fnder(sp);
dyy = fnval(xx,dsp); % First Derivative
ddsp = fnder(sp,2); % Second Derivative
ddyy = fnval(xx,ddsp);
plot(xx, yy, xx, dyy, xx, ddyy), shg % Plotting all data.
end
Although, it is good, but I want to put constrained on second derivative at end points. How can I do that?
  댓글 수: 1
Abdul Mannan
Abdul Mannan 2015년 9월 15일
OK. This is explained in help in "spapi" MATLAB Command. You can do it as follows.
if true
x = [ 0, 0.125, 2*0.125, 3*0.125, 4*0.125, 5*0.125, 6*0.125, 7*0.125, 8*0.125 ];
y = [0, sin(2*pi*f/8), 1, sin(2*pi*3*f/8), 0, sin(2*pi*5*f/8),-1,sin(2*pi*7*f/8), 0];
k = 6;
sp = spapi(augknt(x,6,2),[x,x,min(x),max(x)],[y,[0 2*pi*cos(2*pi*f/8), 2*pi*cos(2*pi*f/4),2*pi*cos(2*pi*3*f/8),2*pi*cos(2*pi*4*f/8),2*pi*cos(2*pi*5*f/8),2*pi*cos(2*pi*6*f/8),2*pi*cos(2*pi*7*f/8),0],0,0]);
xx = 0:0.001:1;
yy = fnval(xx,sp);
dsp = fnder(sp);
dyy = fnval(xx,dsp);
ddsp = fnder(sp,2);
ddyy = fnval(xx,ddsp);
plot(xx, yy, xx, dyy, xx, ddyy), shg
end

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

답변 (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