specifying constraints on a spline function

2 visualizaciones (últimos 30 días)
Malak
Malak el 20 de Sept. de 2023
Editada: Bruno Luong el 21 de Sept. de 2023
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 comentarios
Bruno Luong
Bruno Luong el 20 de Sept. de 2023
You might try to enforce the second derivative at xp smaller than some negative curvature.
Malak
Malak el 20 de Sept. de 2023
would you please guide me how to do that?

Iniciar sesión para comentar.

Respuestas (1)

Bruno Luong
Bruno Luong el 21 de Sept. de 2023
Editada: Bruno Luong el 21 de Sept. de 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

Categorías

Más información sobre Splines en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by