Applying boundary conditions on a cubic spline interpolation
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Marc Abdel Nour
am 4 Nov. 2022
Kommentiert: Marc Abdel Nour
am 10 Nov. 2022
Hello,
I'm trying to implement the function interp1 in my code, as follows:
S=interp1(x,y,xq,'spline')
As output, I'm getting the interpolated value at position xq, using cubic spline interpolation. But interp1 uses not-a-knot as boundary condition, is there any way i can get S using different boundary conditions?like clamped or periodic or ....?
I tried using csape, but the thing is that i couldn't get the interpolated value at the specific location xq.
Thank you in advance for your help
0 Kommentare
Akzeptierte Antwort
Santosh Fatale
am 10 Nov. 2022
Hi Marc,
As you mentioned, you can use “csape” function for different end conditions. Note that “csape” returns interpolants in ppform. You can use “fnval” function to calculate value of interpolant in ppform at the specific location xq.
For more information about “csape” and “fnval” functions and ppform follow these links:
Weitere Antworten (1)
Bruno Luong
am 10 Nov. 2022
You can use my function spline1d available here https://fr.mathworks.com/matlabcentral/fileexchange/24996-spline-derivative?s_tid=srchtitle
You can select periodic bc, natural bc [default]; not-a-knot, or clamping first or second derivative on boundary.
This FEX is written long ago and a little bit out-date, but it still working =.
x=cumsum(rand(1,6));
y=rand(size(x));
xi=linspace(min(x),max(x));
yi_notaknot=interp1(x,y,xi,'spline');
yi_natural=spline1d(x,y,xi,[]);
figure
plot(x,y,'or');
hold on
h1=plot(xi,yi_notaknot,'b');
h2=plot(xi,yi_natural,'r');
legend([h1 h2],'not-a-knot','natural')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1187633/image.png)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!