![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179394/image.jpeg)
How to construct cubic splines?
3 views (last 30 days)
Show older comments
Hello, I am trying to implement the following code in Matlab but it dose not work.
x = 2*pi*[0 1 .1:.2:.9];
y = cos(x);
csp = csape( x, y, 'periodic' );
hold on
fnplt(csp,'g')
hold off
0 Comments
Accepted Answer
John D'Errico
on 24 Feb 2018
Edited: John D'Errico
on 24 Feb 2018
Do you have the curve fitting toolbox? CSAPE is part of that TB. (It used to be in the splines TB but that got merged into the curve fitting TB some years ago.)
x = 2*pi*[0:.1:1];
y = cos(x);
SLM = slmengine(x,y,'knots',x,'endcond','periodic','regul',0,'result','pp','plot','on');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179394/image.jpeg)
So a purely interpolating cubic spline, with periodic boundary conditions.
2 Comments
John D'Errico
on 24 Feb 2018
Edited: John D'Errico
on 24 Feb 2018
At the command line, use the ver command. If you have that TB, you will see it listed. So, for me, I see this:
ver
...
Curve Fitting Toolbox Version 3.5.6 (R2017b)
John D'Errico
on 25 Feb 2018
Works fine for me. Don't you hate that? ;-)
x = 2*pi*[0 1 .1:.2:.9];
y = cos(x);
csp = csape( x, y, 'periodic' );
fnplt(csp,'g')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/187993/image.jpeg)
Your release is only slightly older than mine, which should not be a problem.
Perhaps you have hurt the feelings of your computer recently? Try giving it flowers? My computer can hold a grudge. Ok. Only kidding.
Seriously, can you use the other tools from the curve fitting toolbox? If not, then you might have an installation problem with that toolbox. I'd check to see if there were corruption problems on your disk. Maybe try re-installing MATLAB from online - that is pretty quick with a fast connection.
I just looked at the release notes, but do not see any recent changes to csape.
Is the CFT in your search path? So while you have a license, perhaps your search path got screwed up?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!