Ole G S
Ole G S

Reputation: 1

Find Anti-derivative in R

I want to be able to find the anti-derivative of an arbitrary function in R.

Suppose I´ve got f = 1/(2*x^2) and want to find F, which by the way is easy to calculate by hand.

I´ve tried the following:

f<- function (x) {1/(sqrt(x))}

F = antiD(f)

This gives me:

Error: no applicable method for 'rhs' applied to an object of class "function"

Can someone give me a push in the right direction here?

Upvotes: 0

Views: 2689

Answers (2)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84529

With Ryacas:

library(Ryacas)
yac_str("Integrate(x) 1/Sqrt(x)")
# [1] "2*Sqrt(x)"

Upvotes: 0

user2474226
user2474226

Reputation: 1502

Are you using the mosaicCalc package?

I don't think you can use a function as argument to the antiD(). It expects a formula:

F <- antiD( 1/sqrt(x) ~ x)

This will give you a function F that takes two parameters x and C (constant). In this instance, it can't do a symbolic integration as it doesn't know what to do with the sqrt() function. If you alternatively did:

F <- antiD(x^-0.5 ~ x) 

Then you'll see that symbolic integration has been done:

F
function (x, C = 0) {2 * x^(1/2) + C}

Upvotes: 5

Related Questions