findroot error

22 views
Skip to first unread message

Mike

unread,
Jun 4, 2013, 4:11:19 PM6/4/13
to sage-s...@googlegroups.com
The following code snippet works, until you uncomment the "c=x-a" line, at which point you get the error 
"TypeError: f() takes exactly 2 arguments (1 given)".  The line "c=x" causes no problems.  What's going on?

(Note: I know you don't need that line; this replicates the TypeError  in a more complicated problem.)

from mpmath import *
def f(a,b):
#   c=x-a
   return a-2, b-3
print findroot(f, (5, 6))

Alastair Irving

unread,
Jun 4, 2013, 4:56:43 PM6/4/13
to sage-s...@googlegroups.com
Hi

The problem is that the findroot function calls your function f with
parameters of a multiprecision type which is not compatible with
symbolic expressions. Although you can evaluate f(5,6) you cannot do
f(mp.convert(5),mp.convert(6))
as Sage cannot do
x-mp.convert(5)

HTH

Alastair Irving
Message has been deleted

Mike

unread,
Jun 4, 2013, 8:34:03 PM6/4/13
to sage-s...@googlegroups.com

Thank you! - that does explain the error.

If I convert back within the function (as below) , it eliminates the error message, and also seems to work in my "real" problem.  Are there better ways to do this "conversion back" (to something compatible with symbolic expressions) than using RealField?


from mpmath import *
def f(a,b):
   a=RealField(100)(a)
Reply all
Reply to author
Forward
0 new messages