On Tuesday, June 4, 2013 4:56:43 PM UTC-4, Alastair Irving wrote:
>
> On 04/06/2013 21:11, Mike wrote: 
> > 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)) 
> > 
>
> 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 
>

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)
   c=x-a
   return a-2, b-3
print findroot(f, (5, 6))

Mike

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to