使用NLsolve时,边界检查错误

时间:2017-08-16 15:12:47

标签: optimization julia equation-solving

我想用NLSolve解决下面的NL方程组。

using NLsolve
function f!(x, fvec; α=0.21,γ=0.4,β=0.99,μ=0.20,δ=0.14,θ=0.25)
i=α-1
b=α-2
c=1/γ
fvec[1]=x[3]-x[3]*β*(1-δ+(α/μ)*x[1]^i*float(x[2])^-i)
fvec[2]=θ*x[3]*x[2]^c-(1-α)*x[1]^α*float(x[2])^-α*(1/μ)
fvec[3]=x[3]+δ*x[1]-x[1]^α*float(x[2])^-i
fvec[4]=x[2]-0.33
fvec[5]=-1.05^(1/4)+1-δ+(α/μ)*x[1]^i*float(x[2])^-i
end
function g!(x, fjac;α=0.21,γ=0.4,β=0.99,μ=0.2,δ=0.14,θ=0.25)
a=-α-1
i=α-1
b=α-2
fjac[1,1]=-x[3]β*(α/μ)*(α-1)*(x[1]^b)*float(x[2])^-i
fjac[1,2]=-x[3]β*(α/μ)*(1-α)*(x[1]^i)*float(x[2])^-α
fjac[1,3]=1-β*(1-δ+(α/μ)*x[1]^i*float(x[2])^-i)
fjac[2,1]=-(α/μ)*(1-α)*x[1]^i*float(x[2])^-α
d=(1/γ)-1
fjac[2,2]=(θ/γ)*x[3]*x[2]^d+(1-α)*(α/μ)*x[2]^a*x[1]^α
fjac[2,3]=θ*x[2]^(1/γ)
fjac[3,1]=δ-α*x[1]^i*float(x[2])^-i
fjac[3,2]=-(1-α)*x[1]^α*float(x[2])^-α
fjac[3,3]=1
fjac[4,1]=0
fjac[4,2]=1
fjac[4,3]=0
fjac[5,1]=(α/μ)*i*x[1]^b*float(x[2])^-i
fjac[5,2]=(α/μ)*(1-α)*x[1]^i*float(x[2])^-α
fjac[5,3]=0
end

nlsolve(f!,g!,[0.1,0.33,1.2])

实现上述代码时,将返回以下错误:

BoundsError: attempt to access 3-element Array{Float64,1} at index [4].

请问我该如何解决?

0 个答案:

没有答案