Cubic Spline and its gradient
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
dpb
le 15 Sep 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.
Réponses (1)
Walter Roberson
le 15 Sep 2013
Perhaps you should be using fndir() to generate the gradient; you could then evaluate the gradient at particular locations if you want to.
0 commentaires
Voir également
Catégories
En savoir plus sur Spline Construction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!