필터 지우기
필터 지우기

Finding length of curve created using 'fit' function

조회 수: 5 (최근 30일)
Prabs
Prabs 2014년 5월 23일
편집: Star Strider 2014년 5월 24일
So I've created a polynomial curve using the 'fit' function based on a range of coordinates. Is there any way of finding the length of the curve that has been created?
line1 = fit(middle_points(:,1),middle_points(:,2),'poly3');
plot(line1);
Thanks for the help in advance.

답변 (2개)

Star Strider
Star Strider 2014년 5월 23일
편집: Star Strider 2014년 5월 24일
Using the techniques in Arc Length (and every calculus book I’ve seen), I would use the x and y line coordinates from the line you have already calculated, create in integrand using hypot and then trapz to do the integration:
p = [3 -5 -7 -11]; % Polynomial
x = linspace(0,5); % Independent variable
y = polyval(p,x); % Calculate y-values
CLF = hypot(diff(x), diff(y)); % Calculate integrand from x,y derivatives
CL = trapz(CLF) % Integrate to calculate arc length
Using cumtrapz is also a possibility if you are interested in the intermediate values of the arc length.

John D'Errico
John D'Errico 2014년 5월 23일
I'll make some fake data.
x = linspace(-pi/2,pi/2,20);
y = sin(x);
% fit a quintic (degree 5) polynomial
P5 = polyfit(x,y,3);
% differentiate the polynomial
P5der = polyder(P5);
fun = @(x) sqrt(1 + polyval(P5der,x).^2);
integral(fun,-pi/2,pi/2)
ans =
3.8224
Note that I've also got a function called arclength on the file exchange that will return the arc length, WITHOUT needing to go through the intermediate of a polynomial fit. That polynomial fit may introduce errors that are unacceptable.
  댓글 수: 1
Prabs
Prabs 2014년 5월 24일
Hey John, I tried the arclength function that you've created. Doesnt seem to be working correctly for me. I've got x coordinates and y coordinates of the points that I've plotted, and I used 'fit' to plot the curve of best fit. Now in your arclength function, I'm using the x coordinates as px and the y coordinates as py. Are those the correct inputs I should be using? Correct me if I'm wrong please. Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by