Below is my fast and dirty  approach for making an mpmath friendly
nonlinear system from one configured for scipy.optimize.fsolve.

Thanks for the tips.

import sympy as sy
import numpy

sy.var('x1,x2,a,b')
global a,b
# assume f_list is a "long" list of "functions" generated by another
sympy script
# f_list may contain more than 100 terms
f_list=list([a*x1**2 + x2, b*5*x1**2 - 3*x1 + 2*x2 - 3])
x=list([x1,x2])#degrees of freedom or unknowns
parameters=list([a,b])#knowns
x0=numpy.array([1,1])#
args=x+parameters
b=1
a=2
# make the symbolic functions more 'numerical'
F1=sy.lambdify(args,f_list)
#reshuffle F1 as an fsolve freindly function with global parameters
def F2(x):
        global a,b
        parameters=list([a,b])
        args=tuple(x)+tuple(parameters)
        return F1(*args)

#F2(x)-> F3(x1,x2) for mpmath.findroot
f3='def F3(%s):\n\treturn F2(tuple(%s))'%(str(x)[1:-1],str(x))
exec f3

print(sy.mpmath.findroot(F3,list(x0)))

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to