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

; ???

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

; ???