Created
August 29, 2015 10:09
-
-
Save mick001/b6aa8a0b225fa43c6315 to your computer and use it in GitHub Desktop.
How to calculate the length of an arbitrary arc. Full article at http://www.firsttimeprogrammer.blogspot.com/2015/03/how-to-calculate-length-of-arbitrary-arc.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Line integral calculation % | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Variable definition for symbolic calculations | |
syms t; | |
% Parametric curve | |
x = @(t) t; | |
y = @(t) sqrt(t); | |
% Integration limits | |
a=0; | |
b=10; | |
% Let's define ds | |
ds = sqrt(diff(x,t)^2+diff(y,t)^2); | |
% Indefinite integral | |
S = int(ds,t); | |
% Definite integral | |
line = int(ds,t,a,b) | |
% Plot of the data | |
points = 200; | |
xtra = 5; | |
x1 = linspace(0,b+xtra,points); | |
plot(x1,y(x1),'b.'); | |
grid on; | |
x2 = linspace(a,b,(b+xtra)/b*points); | |
hold on | |
plot(x2,y(x2),'r.'); | |
hold off | |
title('Line integral') | |
xlabel('x') | |
ylabel('y') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment