Ask Your Question
1

scipy.optimize.root

asked 2012-09-21 06:26:30 +0100

mattias gravatar image

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 flag offensive close merge delete

Comments

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.

DSM gravatar imageDSM ( 2012-09-21 10:47:21 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-09-21 08:12:33 +0100

achrzesz gravatar image

updated 2012-09-21 15:01:50 +0100

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]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-09-21 06:26:30 +0100

Seen: 1,286 times

Last updated: Sep 21 '12