Nonlinear system of equations Julia

I am trying to solve a large number (50) of nonlinear equations in Julia. At the moment, I'm just trying to do this work with two equations to get the syntax on the right, etc. However, I tried various packages / tools - NLsolve, nsolve in SymPy and NLOpt in JuMP (where I ignore the purpose of the function and just introduce equality constraints) - without much luck. I think I should focus on having it work in one. I would appreciate any advice on choosing packages and, if possible, code.

This is how I tried to do it in NLsolve (using it in mcpsolve mode so that I can impose restrictions on the variables that I solve for - x [1] and x [2]), which are unemployment rates and therefore are limited between zero and 1 ):

using Distributions using Devectorize using Distances using StatsBase using NumericExtensions using NLsolve beta = 0.95 xmin= 0.73 xmax = xmin+1 sigma = 0.023 eta = 0.3 delta = 0.01 gamma=0.5 kappa = 1 psi=0.5 ns=50 prod=linspace(xmin,xmax,ns) l1=0.7 l2=0.3 wbar=1 r=((1/beta)-1-1e-6 +delta) ## Test code function f!(x, fvec) ps1= wbar + (kappa*(1-beta*(1-sigma*((1-x[1])/x[1])))) ps2= wbar + (kappa*(1-beta*(1-sigma*((1-x[2])/x[2])))) prod1=prod[1] prod2=prod[50] y1=(1-x[1])*l1 y2=(1-x[2])*l2 M=(((prod1*y1)^((psi-1)/psi))+((prod2*y2)^((psi-1)/psi))) K=((r/eta)^(1/(eta-1)))*M pd1=(1-eta)*(K^eta)*(M^(-eta))*prod1 pd2=(1-eta)*(K^eta)*(M^(-eta))*prod2 fvec[1]=pd1-ps1 fvec[2]=pd2-ps2 end mcpsolve(f!,[0.0,0.0],[1.0,1.0], [ 0.3, 0.3]) 

I get this error message:

error message

Any suggestions are welcome! I understand that the formulas are pretty ugly, so let me know if any additional simplifications help (I tried!).

+5
source share
1 answer

I thought you set the initial conditions outside the range because I tried mcpsolve(f!,[0.0,0.0],[0.0,0.0],[0.3, 0.3]) and it worked.

However, I also tried other combinations:

mcpsolve(f!,[0.4,0.4], [0.0,0.0], [0.3, 0.3]) worked

mcpsolve(f!,[0.4,0.4], [0.3,0.3], [1.0,1.0]) not

mcpsolve(f!,[0.6,0.6], [1.0,1.0], [0.3,0.3]) not

Have you checked these values ​​in your test?

+1
source

All Articles