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!