Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indefinite Integral in R

Tags:

r

I am looking to calculate the indefinite integral of an equation.

I have data from an accelerometer feed into R through a visual C program, and from there it was simple enough to come up with an equation to represent the acceleration curve. That is all well in good, however i need to calculate the impact velocity as well. From my understanding from the good ol' highschool days, the indefinite integral of my acceleration curve will yield the the equation for the velocity.

I know it is easy enough to perform numerical integration with the integrate() function, is there anything which is comparable for an indefinite integral?

like image 843
user1003131 Avatar asked Nov 08 '11 12:11

user1003131


2 Answers

library(Ryacas)
x <- Sym("x")
Integrate(sin(x), x)

gives

expression(-cos(x))

An alternative way:

yacas("Integrate(x)Sin(x)")

You can find the function reference here

like image 75
George Dontas Avatar answered Oct 19 '22 09:10

George Dontas


If the NA's you mention are informative in the sense of indicating no acceleration input then they should be replace by zeros. Let's assume you have the data in acc.vec and the device recorded at a rate of rec_per_sec:

acc.vec[is.na(ac.vec)] <- 0
vel.vec <- cumsum(acc.vec)/recs_per_sec

I do not think constructing a best fit curve is going to improve your accuracy in this instance. To plot velocity versus time:

plot(1:length(acc.vec)/recs_per_sec, vel.vec, 
       xlab="Seconds", ylab="Integrated Acceleration = Velocity")
like image 24
IRTFM Avatar answered Oct 19 '22 09:10

IRTFM