upiterbarg / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

findroot problem #246

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I coded p1 , p2 script in c:\Python33\ : 

p1:
def f2():
        exec(open('c:\Python33\p2.py').read())
        return;
def f1():
    f2()
    return;

p2:
from mpmath import *
print(findroot(lambda x: sin(x)-0.5, x0=0.2)) 

What is the expected output? What do you see instead?
when i run idle then:

first time;
from mpmath import *
print(findroot(lambda x: sin(x)-0.5, x0=0.2)) 
0.523598775598299  expected output no problem

but if enter this form:
from p1 import *
f1()

result:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    f1()
  File ".\p1.py", line 7, in f1
    f2()
  File ".\p1.py", line 3, in f2
    exec(open('c:\Python33\p2.py').read())
  File "<string>", line 5, in <module>
  File "C:\Python33\lib\site-packages\mpmath\calculus\optimization.py", line 925, in findroot
    fx = f(*x0)
  File "<string>", line 5, in <lambda>
NameError: global name 'sin' is not defined

What version of the product are you using? On what operating system?
Python 3.3.2 ,   Windows 7

Please provide any additional information below.

in p2: 
when i replace 
"print(findroot(lambda x: sin(x)-0.5, x0=0.2))" 
to "print(sin(2))" 
no problem occured

or if i added "from mpmath import *"  to p1' as first line
no problem occured
print(findroot(lambda x: sin(x)-0.5, x0=0.2))  Works

So:
in my development excpectations needs to this 
way of p1 and p2 works

What is the problem i can't understand
Thanks for any help 

Original issue reported on code.google.com by kadirdo...@gmail.com on 10 Nov 2013 at 10:37