There seems to be no explicit Taylor series, but the series function is available. The following code works:
library(rSymPy)
sympy("var('p')")
sympy("var('x')") # or sympy("x = Symbol('x', real=True)")
#
xt <- sympy("p=series(exp(x), x, 0, 10)") # expand about 0 to 10th order
which gives the answer:
[1] "1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + x**6/720 + x**7/5040 + x**8/40320 + x**9/362880 + O(x**10)"
We can verify this answer by changing the code to:
library(rSymPy)
sympy("var('p')")
sympy("var('x')")
xt <- sympy("p=series(exp(x), x, 0, 10)")
xt0 <- sympy("p.removeO()")
x <- 1/3
T1 <- eval(parse(text=xt0))
T2 <- exp(x)
print(T1-T2)
Finally, the error from the series extension:
[1] -4.811929e-12
I hope this is useful for anyone who wants to use the rSymPy R package
source
share