Krylov-Newton algorithm
BifurcationKit
is built upon the newton algorithm for solving (large-dimensional) nonlinear equations
\[F(x)=0\in\mathbb R^n,\quad x\in\mathbb R^n.\]
Writing $J(x)\in\mathcal L(\mathbb R^n)$ the jacobian, the algorithm reads
\[x_{n+1} = x_n - J(x_n)^{-1}F(x_n)\]
with initial guess $x_0$.
The crux of the algorithm is to solve the linear system in $y$:
\[J(x_n)\cdot y = F(x_n).\]
To this end, we never form $J^{-1}$ like with pinv(J)
but solve the linear system directly.
Space of solutions
For the algorithm to be defined, a certain number of operations on x
need to be available. If you pass x::AbstractArray
, you should not have any problem. Otherwise, your x
must comply with the requirements listed in Requested methods for Custom State.
Different Jacobians
There are basically two ways to specify the jacobian:
- Matrix based
- Matrix-free.
In case you pass a matrix (in effect an AbstractMatrix
like a sparse one,...), you can use the default linear solver from LinearAlgebra
termed the backslash operator \
. This is a direct method. This is the case 1 above.
Another possibility is to pass a function J(dx)
and to use iterative linear solvers. In this case, this is termed a Krylov-Newton method. This is the case 2 above. In comparison to the Matrix-based case, there is no restriction to the number of unknowns $n$.
The available linear solvers are explained in the section Linear solvers (LS).
One can find a full description of the Krylov-Newton method in the solve
.
Simple example
Here is a quick example to show how the basics work. In particular, the problem generates a matrix based jacobian using automatic differentiation.
using BifurcationKit
F(x, p) = x.^3 .- 1
x0 = rand(10)
prob = BifurcationProblem(F, x0, nothing)
sol = BifurcationKit.solve(prob, Newton(), NewtonPar(verbose = true))
NonLinearSolution{Vector{Float64}, BifurcationProblem{BifFunction{typeof(Main.F), BifurcationKit.var"#104#122"{typeof(Main.F)}, BifurcationKit.var"#108#126"{typeof(Main.F)}, Nothing, BifurcationKit.var"#105#123"{typeof(Main.F)}, Nothing, BifurcationKit.var"#107#125"{BifurcationKit.var"#105#123"{typeof(Main.F)}}, BifurcationKit.var"#111#130"{BifurcationKit.var"#d1Fad#128"{typeof(Main.F)}}, BifurcationKit.var"#113#132", BifurcationKit.var"#115#134", BifurcationKit.var"#117#136", Bool, Float64, BifurcationKit.Jet{Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}}, Vector{Float64}, Nothing, typeof(identity), typeof(BifurcationKit.plot_default), typeof(BifurcationKit.record_sol_default), typeof(BifurcationKit.save_solution_default)}, Vector{Float64}, Int64}([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], ┌─ Bifurcation Problem with uType Vector{Float64}
├─ Inplace: false
├─ Dimension: 10
├─ Symmetric: false
└─ Parameter: p, [2.4728822341225603, 5.2332696305527294e8, 1.5505984064591005e8, 4.594365622832112e7, 1.361293491940589e7, 4.0334619389866167e6, 1.1950995744180924e6, 354103.31825005275, 104919.24234970615, 31086.923568712544 … 239.23239955475745, 70.62534035044257, 20.66987729494697, 5.875482590876786, 1.5147289184366093, 0.2837742826969303, 0.02039559427807558, 0.00013558676838454353, 6.127000906630542e-9, 0.0], true, 22, 22)
Example
The (basic) tutorial Temperature model presents all cases (direct and iterative ones).