The following works:
using ModelingToolkit, NonlinearSolve
# Define a nonlinear system
@variables x y z
@parameters σ ρ β
eqs = [0 ~ σ * (y - x)
0 ~ x * (ρ - z) - y
0 ~ x * y - β * z]
@mtkbuild ns = NonlinearSystem(eqs)
guesses = [x => y, y => 1.0, z => 0.0]
ps = [σ => 10.0, ρ => 26.0, β => 8 / 3]
prob = NonlinearProblem(ns, guesses, ps)
sol = solve(prob, NewtonRaphson())
output:
retcode: Success
u: 2-element Vector{Float64}:
-2.129924444096732e-29
-2.398137151871876e-28
While this doesn’t work:
using ModelingToolkit, NonlinearSolve
# Define a nonlinear system
@variables x y z
@parameters σ ρ β
eqs = [0 ~ σ * (y - x)
0 ~ x * (ρ - z) - y
0 ~ x * y - β * z]
@mtkbuild ns = NonlinearSystem(eqs)
guesses = [y => 1.0, z => 0.0]
ps = [σ => 10.0, ρ => 26.0, β => 8 / 3]
prob = NonlinearProblem(ns, guesses, ps)
sol = solve(prob, NewtonRaphson())
output:
ERROR: Initial condition underdefined. Some are missing from the variable map.
Please provide a default (`u0`), initialization equation, or guess
for the following variables:
Set(Any[x])
Is there a good reason for this? I would think that if the initial guess for σ
and y
are known, the program should be able to automatically calculate the initial guess for x
using the equation 0 ~ σ * (y - x)