Ask Your Question
1

How to increase precision of numeric integraion?

asked 2017-06-03 11:46:54 +0100

ablmf gravatar image

I am trying to evaluate an integral numeraically like this

sage: s = integrate(t*sin(t)/(1+cos(t)^2), t, 0, pi)
sage: s.n(prec=100)
2.4674011002723395
sage: s.n(prec=1000)
2.4674011002723395

As you can see, increasing prec does not give me more precise result. Is there any way to get more digits ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-06-03 14:16:12 +0100

mforets gravatar image

updated 2017-06-03 22:24:04 +0100

the interfaces maxima, sympy, giac, fricas, are not able to symbolically evaluate the integral (*), whose exact value is $\pi^2/4$. however, it is possible that you use algorithm='mathematica_free', which gives the good indefinite integral, and then use subs to get the definite integral (although notice that in v.7.6. this option is broken as you can see in the sagecell, but it has been fixed in the latest development version!).

to compute the integral numerically and with arbitrary precision (**), let's try mpmath:

sage: from mpmath import mp
sage: mp.dps = 200
sage: print(mp.quad(lambda t: t*mp.sin(t)/(1+mp.cos(t)^2), [0, mp.pi]))

2.4674011002723396547086227499690377838284248518101976566033373440550112056048013107504433509296380579560064784435057860194430870305075116819026544194962994152475999640516439076428765103082100821952173

compare to:

sage: N(pi^2/4, digits=200)

2.4674011002723396547086227499690377838284248518101976566033373440550112056048013107504433509296380579560064784435057860194430870305075116819026544194962994152475999640516439076428765103082100821952173

(*) in Sage v.8.0.beta8

(**) for arbitrary precision numerical integration using "Sage functions", i've found this hint: #8321 which leads me to thinking that it is a feature which has not been implemented, although i'm not 100% sure..

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: 2017-06-03 11:46:54 +0100

Seen: 805 times

Last updated: Jun 03 '17