Ask Your Question
0

Finding numerical solution to a nonlinear equation

asked 2014-08-03 06:39:57 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I'm trying to find a solution for a nonlinear equation using cloud.sagemath but I have been unsuccessful. The command "solve" could not find a result, and I haven't been able to input the range over which the solution should be looked. Here is my code:

phi = var('phi')
a = .25
beta = 1
g = .2
ce = .5
alpha = .1
gamma = 2
V = .5
rho = .8
sigma = 4
sigmaeps = 1
K = 2 
R = 2 
K2 = 2 
avginv = K+R+K2
Sinv = phi*avginv
Swinv = K2+R-Sinv
psinv = (-1+(1+4*rho^(-2)*sigma^(-2)*K)^(1/2))/(2*rho^(-2)*sigma^(-2))
phipriv = K/avginv
phipub = Swinv/avginv
prob = a-a*e^(-Swinv)
kappa = gamma*prob*(1-prob)*g^2
N = beta^(-1)*(1+alpha)*phi - beta^(-1)*alpha
L = beta^(-2)*(V+(1-phipriv)*avginv^(-1)+sigmaeps - 2*sigmaeps*phi + rho^2*sigma^2*psinv^(-2)*phipriv^2)
q = (beta*ce^(-1)-alpha*kappa^(-1)*N)*(gamma*L + ce^(-1)+kappa^(-1)*N^2)
y = q*N
phi1 = alpha/(1-alpha)
eq = beta*ce^(-1)-alpha*kappa^(-1)*N == 0
phi2 = solve(eq,phi)
print phi2

I get

[
phi == -1/11*e^(12*phi - 8) - 2/11*e^(6*phi - 4) + 4/11
]

Can someone help? And how can I ask for a solution on $[0,1]$?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2014-08-03 18:52:46 +0100

FrédéricC gravatar image

updated 2014-08-03 18:55:51 +0100

Hello,

Something like that ?

sage: eq.find_root(0,1)
0.6666666666676859

or rather

sage: eq.find_root(0,1/2)
0.3367803592444174
edit flag offensive delete link more

Comments

By plotting the function, I noticed that there would be 2 roots. Unfortunately, find_root cannot obtain them at once. But following your suggestion did the trick.

Jorge gravatar imageJorge ( 2014-08-04 06:31:14 +0100 )edit

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: 2014-08-03 06:39:57 +0100

Seen: 1,462 times

Last updated: Aug 03 '14