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 Center および File ExchangeSpline Construction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by