specifying constraints on a spline function
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Bruno Luong
le 20 Sep 2023
You might try to enforce the second derivative at xp smaller than some negative curvature.
Réponses (1)
Bruno Luong
le 21 Sep 2023
Modifié(e) : Bruno Luong
le 21 Sep 2023
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 commentaires
Voir également
Catégories
En savoir plus sur Splines dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!