Reputation: 81
I am very new to Julia. I am trying to solve a system of nonlinear equations to find a vector (p_new
). Below a simplified version of my problem. The issue is that I get this message: "ERROR: MethodError: no method matching zero(::, Type{Any})"
. I am not sure whether it is because the initial conditions are not well defined. Thanks in advance!
p_1 = [ 1, 2, 2.3]
p_1b = [ 1, 2.2, 2.5]
mgc = [1, 1, 0.5]
theta = 0.8
OW1 = [0 1 0; 1 1 1; 0 0 1]
g = ones(3,1)
function pupdate!(p_1,mgc,theta,OW1)
delt = p_1.*theta
delt = 2.718281828459.^delt
Sp1 = sum(delt)
sp1 = delt./Sp1
markup = p_1 .- mgc
sp1 .= markup
end
g0 = [p_1b, mgc, theta, OW1]
p_new = nlsolve(pupdate!, g0)
Upvotes: 5
Views: 3281
Reputation: 1345
I ran into the same error, and the problem was that my vector representation of the state was incorrect. In your case I encounter a similar situation.
julia> g0 = [p_1b, mgc, theta, OW1]
4-element Vector{Any}:
[1.0, 2.2, 2.5]
[1.0, 1.0, 0.5]
0.8
[0 1 0; 1 1 1; 0 0 1]
The fix is quite easy:
julia > g0 = p_1b; mgc; theta; OW1[:]]
which return a vector.
It also took me some time to get used to Julia's use of ,
, ;
and
, but once you do, it's quite good.
FWIW: I would suggest embracing Julia's multiple dispatch and not creating functions pupdate!
and gupdate!
but just one function update!
with two methods.
Upvotes: 0