peri | R Documentation |
1. This function returns the length of an arc which is defined by the function whose data points are present in the df dataframe.
2. The dataframe should be a 2 column dataframe with column names should be defined as 'X' and 'Y', where 'X' denotes the x-axis of the function.
3. The function also allows to calculate segments of the function by placing it within the xmin and xmax boundaries.
peri(df, xmin, xmax)
df |
Two column dataframe with columns defined a 'X' and 'Y' defining the arc whose length needs to be calculated |
xmin |
A single element numeric vector which defines the starting point of the section of the arc |
xmax |
A single element numeric vector which defines the ending point of the section of the arc |
The returned value is a single element numeric vector
Chitran Ghosal
#define a semi-circle in the range (-1, 1) centered at the origin with a radius of 1
X <- seq(-2, 2, by = 0.01)
Y <- rep(NA, times = length(X))
for(i in 1:length(X)){
if( (X[i] < -1) | (X[i] > 1)){
Y[i] <- 0
}else{
Y[i] <- sqrt(1 - X[i]^2)
}
}
dat <- data.frame(X, Y)
names(dat) <- c('X', 'Y')
plot(dat$X, dat$Y, type = 'l', col = 'red', asp = 1)
peri(df = dat, xmin = 0, xmax = 1)
peri(df = dat, xmin = -1, xmax = 1 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.