# Revision history [back]

You can use scipy.optimize.fsolve to find a solution, but you'll need to set up things slightly differently. You'll want to consider your function as a map from RR^2 -> RR^2 as opposed to CC -> CC.

sage: x, y = var('x,y')
sage: g = cos(cos(cos(cos(x+i*y)))) - sin(sin(sin(sin(x+i*y))))
sage: f(x,y) = (real(g), imag(g))
sage: from scipy.optimize import fsolve
sage: fsolve(lambda v: f(*v), (1.0,1.0))
array([ 0.75688714,  0.610155  ])
sage: f(*_)
(1.87627691162e-13, -4.80504525058e-13)


You'll have to be careful with your initial guess as the procedure may not converge.

sage: fsolve(lambda v: f(*v), (0.0,0.0))
array([  1.01756188e+00,   1.17664027e-08])
sage: f(*_)
(0.165849713543, -9.91343156065e-13)


SciPy should give a warning the first time this happens, but it's best to use the full_output option to be sure:

sage: fsolve(lambda v: f(*v), (0.0,0.0), full_output=1)
(array([  1.01756188e+00,   1.17664027e-08]), {'qtf': array([ -1.65849759e-01,  -2.24024475e-06]), 'nfev': 26, 'fjac': array([[ -1.00000000e+00,   1.35076898e-05],
[ -1.35076898e-05,  -1.00000000e+00]]), 'r': array([  3.14707173e-04,   3.50982324e-09,  -2.59845204e-04]), 'fvec': array([  1.65849714e-01,  -9.91343156e-13])}, 5, 'The iteration is not making good progress, as measured by the \n  improvement from the last ten iterations.')


(Note the "The iteration is not making good progress" comment. See the SciPy documentation for the specifics on the output given by full_output.)

Looking at question 500 will also be useful. It probably wouldn't be too difficult to make a something that does this behind the scenes.