How to evaluate integrals numerically: convert expression to float

50 views
Skip to first unread message

Carlos Bouthelier Madre

unread,
May 16, 2017, 2:17:38 PM5/16/17
to sympy
Hi, I am trying to compute an integral of a function f that has no primitive, I have used Integral(f,(Tita1, 0, pi/2).(Tita2,0,pi/2)), because I wanted to be able to define it and operate with it before evaluating it. The problem is that when I try to use .evalf(), it won't give me a float number, just an expression of the integral divided in several sums of the same integral within different intervals. 

The expression of the integral is 
ZE=16.0*Integral(4*Integral(8.0*(194.818182068005*(-sqrt(0.25*cos(Tita1)**2 + 1) + sqrt(0.25*cos(Tita2)**2 + 1))*(sqrt(0.25*cos(Tita1)**2 + 1) + sqrt(0.25*cos(Tita2)**2 + 1))*exp(1.5*sqrt(0.25*cos(Tita1)**2 + 1) - 0.5*sqrt(0.25*cos(Tita2)**2 + 1)) - 194.818182068005*(sqrt(0.25*cos(Tita1)**2 + 1) - sqrt(0.25*cos(Tita2)**2 + 1))**2*exp(0.5*sqrt(0.25*cos(Tita1)**2 + 1) - 0.5*sqrt(0.25*cos(Tita2)**2 + 1)) + 194.818182068005*(sqrt(0.25*cos(Tita1)**2 + 1) - sqrt(0.25*cos(Tita2)**2 + 1))**2*exp(1.5*sqrt(0.25*cos(Tita1)**2 + 1) + 0.5*sqrt(0.25*cos(Tita2)**2 + 1)) + 194.818182068005*(sqrt(0.25*cos(Tita1)**2 + 1) - sqrt(0.25*cos(Tita2)**2 + 1))*(sqrt(0.25*cos(Tita1)**2 + 1) + sqrt(0.25*cos(Tita2)**2 + 1))*exp(0.5*sqrt(0.25*cos(Tita1)**2 + 1) + 0.5*sqrt(0.25*cos(Tita2)**2 + 1)))*exp(-1.0*sqrt(0.25*cos(Tita1)**2 + 1))/((sqrt(0.25*cos(Tita1)**2 + 1) - sqrt(0.25*cos(Tita2)**2 + 1))**2*(sqrt(0.25*cos(Tita1)**2 + 1) + sqrt(0.25*cos(Tita2)**2 + 1))*sqrt(0.25*cos(Tita1)**2 + 1)*sqrt(0.25*cos(Tita2)**2 + 1)), (Tita1, 0, 1.5707963267949)), (Tita2, 0, 1.5707963267949))

What could I use to evaluate it ? How could I define it to make it work? 

In fact, I have substituted some other variables in the expression of ZE, so it can compute the Integral. It would also be useful to know how to plot ZE(x), if x was the unsubstitude variable inside the previous integral.


Thanks in advance

Aaron Meurer

unread,
May 16, 2017, 2:58:53 PM5/16/17
to sy...@googlegroups.com
Looks like a bug. evalf() should work. Can you open an issue for it in
the SymPy issue tracker?

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/6d80f23d-4e40-4e97-beb4-607e1a72ee43%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Carlos Bouthelier Madre

unread,
May 17, 2017, 4:36:53 AM5/17/17
to sympy
Done, if you meant here: https://github.com/sympy/sympy/issues/12646
How could I fix this bug? Shall I update my sympy version or recover a previous one?
Message has been deleted

Carlos Bouthelier Madre

unread,
May 17, 2017, 6:46:52 AM5/17/17
to sympy
Hi Aaron,

May the issue be due to the fact that the integral that I am trying to perform is 2 dimensional? Perhaps Integral() doesn't work for more than one variable, and therefore evalf() can't evaluate it and leaves it as an expression. Any ideas for solving it? Shall I use another integration function from another library (scipy or numpy)?

El martes, 16 de mayo de 2017, 20:58:53 (UTC+2), Aaron Meurer escribió:
Reply all
Reply to author
Forward
0 new messages