Cubic Spline and its gradient

3 次查看(过去 30 天)
Taylor
Taylor 2013-9-15
Hello knowers of things,
I have a set of x and y data points and I'm am trying to get a fit. so far I have followed this process.
x = [...]; %too much data to type here
y = [...];
cs = spline(x,y);
plot(x,y,'o',x,ppval(cs,x),'-'); %this showed an excellent fit
I am using these data points to machine a part but I need the numerical gradient of that spline so can find the magnitude of the normal vector and multiply that by the radius of the machine part and get a new set of x and y coordinates t plug into the mill. When I try the gradient command I get he following output
gradient(cs)
'Error using zeros'
'Trailing string input must be valid numeric class name'
Error in gradient (line 64)
g = zeros(size(f),class(f)); %case of singleton dimension
If anyone could help me out or point me in the right direction I would really appreciate it. I'm still new at this.
  1 个评论
dpb
dpb 2013-9-15
Depends on what you need, specifically...
Look at
doc ppval % and friends
to evaluate the spline at a set of points from which one can then do numeric gradient if numeric is sufficient.
Alternatively,
doc unmkpp
will break out the details of the fitted spline from which you can obtain explicit coeffiecients and breakpoints of the piecewise polynomial and do the direct computation of the derivative from the polynomial rule for derivatives.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2013-9-15
Perhaps you should be using fndir() to generate the gradient; you could then evaluate the gradient at particular locations if you want to.

类别

Help CenterFile Exchange 中查找有关 Spline Construction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by