Abs function error on python jupyter

37 views
Skip to first unread message

fenixjose

unread,
Jun 19, 2017, 5:10:34 PM6/19/17
to Project Jupyter
From this program.............

num = 4
x, u = symbols('x u')
Irr = Function('Irr')(u)
Irr = 4*pi**2*u**2*Abs(integrate(0.25*(1-cos(2*pi*x*num))*exp(-I*2*pi*u*x), (x, 0, 1)))**2 # Notice the use of Abs function.
print(N(Irr.subs(u,1.1)))

The result is ..................
0.0279388389446924 + 1.23479674389006e-24*I
But it is supposed to be a real number, not a complex, even with an imaginary part close to zero !!!

On the other hand, the same program on PyCharm - Python 3.5 is 0.0279388389446924 (just real number)

Am I doing something wrong?

My system is.............
The version of the notebook server is 4.2.3 and is running on:
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

Paul Hobson

unread,
Jun 19, 2017, 5:15:08 PM6/19/17
to jup...@googlegroups.com
Where did you define the 

"symbols", "Function", "Abs" and "I" objects?
-p

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/0e640955-2525-466e-9437-3dc14b05ee8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Kluyver

unread,
Jun 20, 2017, 9:01:53 AM6/20/17
to Project Jupyter
I guess you're using sympy? You may need to ask a sympy mailing list. Jupyter shouldn't be affecting what your code actually does, but it may be that your code finds a different version of sympy.

--
Reply all
Reply to author
Forward
0 new messages