splines, polyfit and polyval, wrong coefficients?!?
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (0)
See Also
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!