PDA

View Full Version : arclength of array



hcrisp
11-13-2009, 03:06 PM
Is there a function for computing the arclength of a f(x) array? I couldn't find any. The formula is: s = integrate_a_to_b( SQRT(1 + (derivative(f(x)))^2) * dx).

Assuming there isn't, how can I do it programmatically? Something like this?



n = 200
dt = 1/100.
x = FINDGEN(n)*dt
y = SIN(2. * !PI * x) + RANDOMU(s, n)/2.

y_ = DERIV(x, y)
y_2 = (y_)^2.
quo = SQRT(1 + y_2)

s_ = DBLARR(n)
s_(1:n-1) = (quo(1:n-1) + quo(0:n-2)) / 2.0 ; trapezoidal method
s_ = s_ * dt
s = DBLARR(n)
FOR i=1L, n-1 DO s(i) = s(i-1) + s_(i)
PRINT, s(n-1)
; 18.084868
; ???

hcrisp
11-16-2009, 10:44 AM
I suppose you could do it the piecewise Pythagorean way (no calculus needed):



n = 200
dt = 1/100.
x = FINDGEN(n)*dt
y = SIN(2. * !PI * x) + RANDOMU(ss, n)/2.

dx = [0., x(1:*) - x(0:n-2)]
dy = [0., y(1:*) - y(0:n-2)]
s_ = SQRT(dx^2 + dy^2)
s = DBLARR(n)
FOR i=1L, n-1 DO s(i) = s(i-1) + s_(i)
PRINT, s(n-1)
; 33.062168