# scipy.optimize.root

Hello,

I'm trying to use scipy.optimize.root without any luck (http://docs.scipy.org/doc/scipy/refer...). An import attempt returns: "'module' object has no attribute 'root'"

Any suggestions on how I can get this module?

Thanks, jv

Methods tried:

"import scipy from scipy import optimize from scipy.optimize import root"

"import scipy from scipy import optimize sol = optimize.root(q, [0., 0.])"

edit retag close merge delete

3

root was only introduced in 0.11.0; import scipy; print scipy.__version__ gives 0.9.0 in Sage 5.3. I don't think you're doing anything wrong, it's just that Sage's scipy is out of date with respect to that doc.

( 2012-09-21 10:47:21 +0200 )edit

Sort by ยป oldest newest most voted

Perhaps you should try fsolve:

import numpy as np
import scipy
from scipy import optimize as opt
y_a =50.;y_b =50.; x0 = 40.
v=lambda n:np.sqrt(n)
v1=lambda n:1/(2*np.sqrt(n))
u=lambda n:np.sqrt(n)
u1=lambda n:1/(2*np.sqrt(n))
alpha_a = .2 ;alpha_b = .2
def f(x):
g_a=x[0];x_a=x[1]
f1 =((1-alpha_b)*v1(g_a+alpha_b*(x0 - g_a)))/((1-alpha_a)*v1(x0-g_a+alpha_a*(g_a)))-((v(g_a+alpha_b*(x0-g_a))-u(y_a)+u(y_a-x_a))/(v(x0-g_a+alpha_a*(g_a))-u(y_b)+u(y_b-(x0-x_a))))
f2 =(u1(x_a)/u1(x0-x_a))-((v(g_a+alpha_b*(x0-g_a))-u(y_a)+u(y_a-x_a))/(v(x0-g_a+alpha_a*(g_a))-u(y_b)+u(y_b-(x0-x_a))))
return [f1,f2]
# if you copy to the console then first copy and evaluate the above
# and next copy and evaluate the remaining part (problems with edit?)
s=opt.fsolve(f,[1,1])
print s
print f([20,20])
#[ 20.  20.]
#[0.0, 0.0]

more

## Stats

Seen: 725 times

Last updated: Sep 21 '12