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