# Method error using NLsolve

Hi, I am stuck with a code and would need some help. I am sorry if the mistake is obvious, but I am new to this and would really need some help there. I have the following code:

``````function bk_opti_decent(grid::Any,
β::AbstractFloat,
Re::AbstractFloat,
Rl::AbstractFloat,
u::Function,
u_prime::Function,
E::AbstractFloat)

function foc1(Sb::Number,
c_bar::Number,
Lb::Number,
K::Number,
Lf::Number,
Sf::Number,
θhigh::Number,
P_star::Number,
θlow::Number,
D::Number)

c1_ND = D * c_bar
c1_D = Lb + Lf
c21(θ) = (Lb - θ* c_bar * D) * Rl + Sb * Re + Lf * Rl + Sf * Re
c22(θ) = (Lb - θ* c_bar * D) * Re + Sb * Re + Lf * Rl + Sf * Re
c2_D(θ) = c13 + (Sb + Sf) * Re / (1 - θ)
E_UD = θhigh * u(Lb + Lf) + (1-θhigh) * u(Lb + Lf + Re*(Sb + Sf)/ (1-θhigh))
E_UND = θhigh * u(c1_ND) + (1-θhigh) * u( Re*(Sb + Sf)/ (1-θhigh))
Diff = E_UND - E_UD

val1(θ) = (Re - 1) * u_prime(c21)
val2(θ) = (Re - Rl) * u_prime(c22)
val3(θ) = (P_star-1) * θ * u_prime(c1_D) + ((P_star - 1)*(1- θ) + Re ) * u_prime(c2_D)
val4 = Diff * (P_star - 1) * (Re / ( c_bar * D * (Re - P_star)))

end

Bk_policyfunc = Array{Real}(0,2) #solution matrix

for (i,D) in enumerate(grid)

function f!(F::Any ,x::Any)

F[1]= foc1(x[1], x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9], D)
F[2]= x[3] - D - x[1]
F[3]= x[4] - E - D
F[4]= x[5] - x[2] * (Rl/(Re-Rl))
F[5]= x[6] - x[4] + x[5]
F[6]= x[7] -  x[5] / x[1]
F[7]= x[9] - x[3]/ (D * x[2])
F[8]= x[8] - (Re * x[3] - Re * x[1] * x[7] + x[2] * x[7] * D) / ( x[2] * D * (Re - x[7]))

end

initial_x = [0.5 0.5 0.5 0.5 0.5 0.5 0.8 0.3 0.3 ]
results1_bk = nlsolve(f!, initial_x)

Bk_policyfunc[1, i] = results.zero[1]
Bk_policyfunc[2, i] = results.zero[2]
Bk_policyfunc[3, i] = results.zero[3]
Bk_policyfunc[4, i] = results.zero[4]
Bk_policyfunc[5, i] = results.zero[5]
Bk_policyfunc[6, i] = results.zero[6]
Bk_policyfunc[7, i] = results.zero[7]
Bk_policyfunc[8, i] = results.zero[8]

return Bk_policyfunc

end

end
``````

Then I create a structure for a model (m) with specific parameters and when i tried solving part of it with

``````bank = bk_opti_decent(m.grid,
m.β,
m.Re,
m.Rl,
m.u,
m.u_prime,
m.E)
``````

I get the following error that I am not able to solve. I changed the types of my unknow to “Number”, but it did not solve the problem. Here is the error:

``````MethodError: no method matching //(::#c21#289{Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64}, ::Int32)
Closest candidates are:
//(::Integer, ::Integer) at rational.jl:40
//(::Rational, ::Integer) at rational.jl:43
//(::Complex, ::Real) at rational.jl:56
...

Stacktrace: