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!