splines, polyfit and polyval, wrong coefficients?!?

8 views (last 30 days)
David
David on 9 Jul 2014
Edited: David on 9 Jul 2014
Good morning all together,
I have a question concerning the spline function and it´s coefficients (MATLAB R2012b). I have created a function out of two clothoids which looks like this.
Now I want to evaluate this function piecewise by fitting a cubic spline. Afterwards I took a look at the coefficients and tried to find the piecewise polynomial function:
y = spline(xges,yges);
xev = linspace (0,1,10);
hold on
for i =1:length(y.coefs)
br = y.breaks(i:i+1);
xxp(i,:) = linspace(br(1),br(2),10);
cf = y.coefs(i,:);
yp(i,:) = polyval(cf,xev);
% ypp (i,:) = ppval(y,xxp(i,:));
plot(xxp(i,:),yp(i,:),'.g') ;
end
But it doesn´t fit the function. The piecewise polynomial functions are wrong. So are also the coefficients of the cubic spline wrong? Or am I doing some mistake by evaluating the piecewise polynomial functions? It´s also a little bit weird that the spline looks perfect, when I´m not using the polyval, but the ppval function. (Blue line is with ppval, green lines with polyval)
I hope you can help me
Thank you in advance,
David

Answers (0)

Community Treasure Hunt

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

Start Hunting!