Finding length of curve created using 'fit' function
조회 수: 5 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
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.
댓글 수: 0
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!