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!