Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Perhaps you should try fsolve:

import numpy
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]
s=opt.fsolve(f,[1,1])
print s
print f([20,20])
#[ 20.  20.]
#[0.0, 0.0]

Perhaps you should try fsolve:

import numpy
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]
s=opt.fsolve(f,[1,1])
print s
print f([20,20])
#[ 20.  20.]
#[0.0, 0.0]

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]