Cubic Spline and its gradient

7 visualizzazioni (ultimi 30 giorni)
Taylor
Taylor il 15 Set 2013
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 Commento
dpb
dpb il 15 Set 2013
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.

Accedi per commentare.

Risposte (1)

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

Categorie

Scopri di più su Spline Construction in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by