[R] calculating arc length using R?
Ravi Varadhan
rvaradha at jhsph.edu
Fri Nov 14 18:42:50 CET 2003
Hi:
If your curve is in a 2-dim plane, then you can use the following
formula (in Tex notation):
\int_a^b \sqrt{1 + (\frac{df}{dx})^2} dx
So you need to take the derivative of your function first, and then
compute the integral of (1 + deriv^2) from a to b.
Here is a simple code to find the arclength of the curve: sin(x),
between -pi and pi.
##########################
arclen <- function(gexp, a, b) {
g <- function(x) { }
body(g) <- D(gexp, "x")
farc <- function(x) sqrt(1 + g(x)^2)
integrate(farc,low=a,upp=b)$val
}
gexp <- expression(sin(x))
arclen(gexp,-pi,pi)
###########################
Best,
Ravi.
----- Original Message -----
From: Greg Trafton <trafton at itd.nrl.navy.mil>
Date: Thursday, November 13, 2003 9:37 pm
Subject: [R] calculating arc length using R?
> Hi, All. I have a function I want to know the plotted length of.
> is it
> possible to calculate the length of the function (e.g., arc length)?
>
> for example, if I want to know the length of the line of
> sin(x) from -pi to pi, how can I do that in R?
>
> thanks!
> greg
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
More information about the R-help
mailing list