Ask Your Question
2

Can Sagemath expand integrals on Taylor series?

asked 2021-12-20 03:37:09 +0100

cdelv gravatar image

Hi, many times an integral is too difficult to be solved. Then we can expand it in a Taylor series and take a few terms of the series to approximate it. Can Sagemath do this? If yes, how?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-12-20 06:35:43 +0100

Emmanuel Charpentier gravatar image

updated 2021-12-20 06:37:06 +0100

The PowerSeries offers an implementation usable for this usage :

sage: R1.<t>=PowerSeriesRing(QQ)
sage: cos(t).integral(t)
t - 1/6*t^3 + 1/120*t^5 - 1/5040*t^7 + 1/362880*t^9 - 1/39916800*t^11 + 1/6227020800*t^13 - 1/1307674368000*t^15 + 1/355687428096000*t^17 - 1/121645100408832000*t^19 + O(t^21)

But note that:

sage: sin(t)
t - 1/6*t^3 + 1/120*t^5 - 1/5040*t^7 + 1/362880*t^9 - 1/39916800*t^11 + 1/6227020800*t^13 - 1/1307674368000*t^15 + 1/355687428096000*t^17 - 1/121645100408832000*t^19 + O(t^20)

The discussion of :

sage: cos(t).integral(t)-sin(t)
O(t^20)

Is left to the reader as an exercise... ;-)

An alternative avoiding this subtle point is the use of the taylor method/function :

sage: cos(x).taylor(x,0,20).integral(x)
1/51090942171709440000*x^21 - 1/121645100408832000*x^19 + 1/355687428096000*x^17 - 1/1307674368000*x^15 + 1/6227020800*x^13 - 1/39916800*x^11 + 1/362880*x^9 - 1/5040*x^7 + 1/120*x^5 - 1/6*x^3 + x
sage: sin(x).taylor(x,0,21)
1/51090942171709440000*x^21 - 1/121645100408832000*x^19 + 1/355687428096000*x^17 - 1/1307674368000*x^15 + 1/6227020800*x^13 - 1/39916800*x^11 + 1/362880*x^9 - 1/5040*x^7 + 1/120*x^5 - 1/6*x^3 + x

And :

sage: cos(x).taylor(x,0,20).integral(x)-sin(x).taylor(x,0,21)
0

HTH,

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-12-20 03:37:09 +0100

Seen: 267 times

Last updated: Dec 20 '21