How to construct cubic splines?

1 次查看(过去 30 天)
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

采纳的回答

John D'Errico
John D'Errico 2018-2-24
编辑:John D'Errico 2018-2-24
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.)
My SLM toolbox (found on the file exchange) does allow periodic boundary conditions.
x = 2*pi*[0:.1:1];
y = cos(x);
SLM = slmengine(x,y,'knots',x,'endcond','periodic','regul',0,'result','pp','plot','on');
So a purely interpolating cubic spline, with periodic boundary conditions.
  2 个评论
John D'Errico
John D'Errico 2018-2-24
编辑:John D'Errico 2018-2-24
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
John D'Errico 2018-2-25
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')
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?

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by