specifying constraints on a spline function
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I am trying contrain a spline function to attain its maximum at a specic point, I have used the following to acheive that https://www.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
however, I am stuck at some point.
so this is what I have tried to contrain the spline function, the data used is attached
% force fit pass through (xp,yp) with horizontal ta,gential (peak)
pntcon = struct('p',{0 1},'x',{xp xp},'v',{yp 0});
options = struct('pntcon', pntcon);
% https://www.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
pp = BSFK(xb,yb,4,15,[],options);
xi = linspace(min(xb),max(xb),600);
yi = ppval(pp,yi);
This does work in some cases but, in other case I will get something like the attached plot. So my question is, would there be another way to force some conditions on the spline function such that it will attain its global maximum at that point and whatever comes after that point should always be smaller than it?
댓글 수: 2
Bruno Luong
2023년 9월 20일
You might try to enforce the second derivative at xp smaller than some negative curvature.
답변 (1개)
Bruno Luong
2023년 9월 21일
편집: Bruno Luong
2023년 9월 21일
I enforce the curvature to be negative in the x-interval (350,450)
load('data.mat')
nknots = 20;
knots = linspace(min(xb),max(xb),nknots+1);
negcurv_int = [350 450];
locnc = discretize(negcurv_int,knots);
pntcon = struct('p',{0 1},'x',{xp xp},'v',{yp 0});
lo = -Inf(1,nknots);
up = +Inf(1,nknots);
up(locnc(1):locnc(2)) = 0; % curvature is negative
shape = struct('p',2,'lo',lo,'up',up);
options = struct('pntcon', pntcon,'shape',shape);
% https://www.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
pp = BSFK(xb,yb,4,nknots,[],options);
xi = linspace(min(xb),max(xb));
yi = ppval(pp,xi);
figure
plot(xb,yb,'r.');
hold on
plot(xi,yi,'b')
plot(xp,yp,'or');
xline(xp)
with option 'knotremoval' set to 'none'
options = struct('pntcon', pntcon,'shape',shape,'knotremoval','none')
Clearly the data cannot be well fitted with those constraints
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Splines에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!