Spline with clamped end conditions using griddedInterpolant

5 Ansichten (letzte 30 Tage)
John Billingham
John Billingham am 22 Dez. 2022
Kommentiert: John Billingham am 22 Dez. 2022
I can create a piecewise polynomial spline with clamped end conditions from vectors x and y using
pp = spline(x,[dy1 y dy2])
where dy1 and dy2 are the required slopes. How can I do this using griddedInterpolant?
fy = griddedInterpolant(x,y,'spline')
is the knot-a-knot spline. Can I not clamp the end points?

Antworten (1)

John D'Errico
John D'Errico am 22 Dez. 2022
Bearbeitet: John D'Errico am 22 Dez. 2022
You cannot do so. There is no capability for that in griddedInterpolant. But I fail to see the problem. Just use spline, which DOES allow that option. Then you can interpolate the spline you have created as you wish. WTP?
  2 Kommentare
John Billingham
John Billingham am 22 Dez. 2022
Sorry, I should have added that griddedinterpolant seems to be much faster than ppval, and it's this speed that I'm after for a clamped spline.
John Billingham
John Billingham am 22 Dez. 2022
x = linspace(0,1,100); y = rand(1,100);
x1 = rand(1,100);
ppx = spline(x,y);
fx = griddedInterpolant(x,y,'spline');
tic
for k = 1:100000
y1 = ppval(ppx,x1);
end
toc
Elapsed time is 1.429425 seconds.
tic
for k = 1:100000
y1 = fx(x1);
end
toc
Elapsed time is 0.300864 seconds.
This makes a considerable difference for what I'm trying to do.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Splines finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by