# How to increase precision of numeric integraion?

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 close merge delete

Sort by » oldest newest most voted

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..

more