Nonlinear systems: numerical continuation and boundary value problems
Follow nonlinear equilibrium branches with pseudo-arclength continuation, detect bifurcations, and solve boundary-value and periodic-orbit problems.
After this lesson you can
- Implement natural and pseudo-arclength continuation with tangent prediction and Newton correction.
- Detect folds and branch bifurcations with determinant and eigenvalue test functions.
- Solve boundary-value problems by single and multiple shooting and explain when single shooting fails.
- Use solve_bvp collocation for boundary-value problems and periodic orbits.
Before you start
Following solutions
A reactor can have several steady states under the same cooling setting. As that setting changes, a stable branch can end at a fold and the state jump to another: a form of hysteresis. A buckling bridge and a biochemical oscillator also exhibit branches, although their equations and stability criteria differ. Integrating one initial condition can hide unstable equilibria and coexisting solutions.
Write the equilibrium condition as , with and scalar parameter . If is invertible, the implicit function theorem allows a local description and yields . Natural continuation increments and corrects using Newton’s method. At a fold, becomes singular and that parameterization fails, even though the full curve may remain smooth.
Pseudo-arclength
Pseudo-arclength continuation treats as unknown. Given a point and a unit tangent in the null space of , predict and correct with
The second equation fixes a hyperplane perpendicular to the previous tangent. Newton solves the augmented system; orient the new tangent so its inner product with the previous one is positive. A small step reduces the risk of jumping branches, but costs more corrections. If Newton fails, a practical implementation reduces the step and retries; the lab reports failure so it is visible.
In one iteration, if , the correction satisfies
The predictor need not satisfy ; the corrector must reduce both residual components. Pseudo-arclength is a local approximation to arc length, not the exact distance along an arbitrary curve. Scales of and matter: if one variable is millions of times larger than another, it can dominate the Euclidean norm and hyperplane. Nondimensionalize or choose explicit weights and keep them fixed when comparing steps.
The model is a reduced thermal balance , , with relative temperature . It can be obtained by eliminating steady-state concentration from a well-mixed reactor with one reaction and positive rate . Parameters are a dimensionless example, not plant measurements. The scalar equation describes reduced thermal equilibrium; stability of the full reactor requires analyzing all its dynamic variables.
To see the elimination, let be normalized concentration and suppose . At equilibrium and the reaction rate is . A simplified thermal balance leads to the displayed expression after substituting that equilibrium. This reduction helps find steady points, but replacing a dynamic variable with its equilibrium value does not alone prove stability of the two-equation system.
If has rank , its null space is one-dimensional and generated by tangent . At a regular fold is singular, but the augmented matrix with final row is invertible: a vector in its null space must be a multiple of by the first rows and orthogonal to by the last, hence zero.
Numerical bifurcation detection uses indicators and then locates and verifies the event. A sign change of a real eigenvalue, or a determinant passing through zero, can signal a fold or branch bifurcation; alone it does not distinguish them. In two dimensions, Hopf requires zero trace, positive determinant and transverse crossing of the complex pair. In higher dimensions follow the real part of an eigenvalue pair. A coarse grid can miss events: reduce the step and inspect eigenvectors.
For example, has branch for every and two branches when . At the origin, and also : matrix loses rank. This is not the regular fold from the previous proof. To switch branches construct a new seed in the critical direction and correct it; an isolated sign change does not automatically select that branch. As an alternative to recomputing the Jacobian each iteration, Broyden’s method updates an approximation, which must be monitored near singularities.
Shooting and collocation
In a boundary-value problem, conditions are known at different endpoints. Single shooting proposes unknown initial values, integrates an ODE and adjusts those values to meet final conditions. For , , , a variation in initial slope changes by . The factor is approximately 1101.3: a small error is amplified because a growing mode exists.
Multiple shooting introduces an unknown state at each node and requires each local integration to end at the next state. Shorter segments reduce growth within each integration, but the full continuity system may still be ill-conditioned. In the linear example that system is solved directly, equivalent to one exact Newton step; a nonlinear problem requires iteration and residual checks. Collocation approximates the whole solution with piecewise polynomials and fits the ODE residual and boundary conditions jointly. The solve_bvp documentation describes its adaptive mesh and conditions.
If is flow through segment , continuity equations are , together with endpoint conditions. Their Jacobian has sparse blocks: each equation involves only two consecutive nodes. The periodic cell uses exactly this structure, with the last node connected to the first. The local benefit appears when comparing for each segment with for the whole interval; that figure should not be multiplied or interpreted as the condition of the entire coupled matrix.
In collocation, a solution reported as converged still requires checking: inspect boundary residual, tolerance, node count and change under mesh refinement. Different seeds can converge to different solutions. This matters especially when an equilibrium and a cycle coexist, as in the next example.
Hopf and periodic orbits
The Brusselator is a two-variable reaction model:
For , equilibrium is and its Jacobian has trace and determinant . With , the imaginary pair crosses at . The figure calculates a cycle branch through numerical closure and phase, starting at and using each solution as the next seed. Amplitude is maximum minus minimum of ; discrete points do not prove cycle stability.
The periodic orbit of unknown period satisfies . Shifting the time origin produces the same orbit and leaves a neutral direction. A phase condition removes that ambiguity; here we use and choose the nonconstant solution using a seed near the cycle. The condition does not eliminate constant equilibrium as an algebraic solution, so amplitude and period are also checked.
Floquet multipliers are eigenvalues of the fundamental matrix after one period. One is 1 due to the time direction of an autonomous cycle; transverse stability is decided by the others, not the neutral multiplier. Calculating them requires integrating the variational equation along the orbit and checking closure accuracy.
Closure has two components for the Brusselator and three unknowns: two initial coordinates and . Phase provides the third equation. Conversely, fixing an arbitrary period and adding a phase can overdetermine the problem. In the lab, the seed selects intersection corresponding to the desired branch; a section that is not transverse at the chosen point can make this phase condition unsuitable.
Lab: continuation and orbit
The first block implements prediction and correction for a square system with one parameter. The tangent comes from the null space by SVD. It returns accepted points and raises an error if Newton does not converge.
import numpy as np
def pseudo_arclength(F,J,x0,lam0,ds,n,tol=1e-10,max_iter=12):
x=np.atleast_1d(np.asarray(x0,dtype=float));z=np.r_[x,float(lam0)]
if ds<=0 or n<0 or np.linalg.norm(F(x,lam0))>tol: raise ValueError('punto inicial o paso inválido')
def tangent(point,previous=None):
A,b=J(point[:-1],point[-1])
_,_,V=np.linalg.svd(np.column_stack((A,np.asarray(b).reshape(-1))))
t=V[-1]
if previous is None and t[0]<0: t=-t
if previous is not None and np.dot(t,previous)<0: t=-t
return t
t=tangent(z);branch=[z.copy()]
for _ in range(n):
pred=z+ds*t;q=pred.copy()
for iteration in range(max_iter):
f=np.asarray(F(q[:-1],q[-1]),dtype=float).reshape(-1)
residual=np.r_[f,np.dot(t,q-pred)]
if np.linalg.norm(residual,np.inf)<tol: break
A,b=J(q[:-1],q[-1])
aug=np.vstack((np.column_stack((A,np.asarray(b).reshape(-1))),t))
q-=np.linalg.solve(aug,residual)
else: raise RuntimeError('Newton no convergió; reduce el paso')
t=tangent(q,t);z=q;branch.append(z.copy())
return np.asarray(branch)
def cstr(x,lam):
theta=x[0];q=.1*np.exp(12*theta/(12+theta))
return np.array([lam-theta+10*q/(1+q)])
def cstr_jac(x,lam):
theta=x[0];q=.1*np.exp(12*theta/(12+theta))
return np.array([[-1+10*q/(1+q)**2*144/(12+theta)**2]]),np.array([1.])branch=pseudo_arclength(cstr,cstr_jac,[0.],-1/1.1,.05,160)
folds=np.flatnonzero(np.diff(np.sign(np.diff(branch[:,1]))))+1
print('retornos aproximados (θ, λ):',branch[folds])
print('residuo máximo:',max(abs(cstr([x],lam)[0]) for x,lam in branch))Detection by sign changes in differences of locates only the step containing each fold; it is not a refined root. For Hopf, evaluate the trace and determinant of the analytical Brusselator Jacobian:
def bruss_jac(x,B):
u,v=x
return np.array([[-(B+1)+2*u*v,u*u],[B-2*u*v,-u*u]])
for B in (1.8,2.,2.2):
J=bruss_jac([1.,B],B)
print('B, traza, determinante:',B,np.trace(J),np.linalg.det(J))Construct three shooting segments with phase . Seed and period 6.4 are approximations for ; they are integrated to generate initial nodes. The corrector requires closure between segments and returns its residual.
import numpy as np
from scipy.integrate import solve_ivp
from scipy.optimize import root
A=1.; B=2.3; K=3
def bruss(y):
u,v=y
return np.array([A-(B+1)*u+u*u*v,B*u-u*u*v])
def flow(y,t):
sol=solve_ivp(lambda t,y:bruss(y),(0,t),y,rtol=1e-8,atol=1e-10)
if not sol.success: raise RuntimeError(sol.message)
return sol.y[:,-1]
nodes=[np.array([1.,3.])]
for i in range(1,K): nodes.append(flow(nodes[-1],6.4/K))
def orbit_residual(z):
T=z[-1]; pts=z[:-1].reshape(K,2)
if T<=0: return np.full(2*K+1,1e6+abs(T))
return np.r_[*[flow(pts[i],T/K)-pts[(i+1)%K] for i in range(K)],pts[0,0]-A]
fit=root(orbit_residual,np.r_[np.array(nodes).ravel(),6.4],tol=1e-9)
if not fit.success or np.linalg.norm(orbit_residual(fit.x),np.inf)>1e-7: raise RuntimeError('disparo no convergió')
orbit_fit=fit.x
print('periodo:',orbit_fit[-1],'estado inicial:',orbit_fit[:2])
print('residuo de cierre y fase:',np.linalg.norm(orbit_residual(orbit_fit),np.inf))Collocation uses that orbit as seed, with rescaled time . It imposes two periodic conditions and one phase condition for two components and unknown parameter .
from scipy.integrate import solve_ivp,solve_bvp
T=orbit_fit[-1];initial=orbit_fit[:2];mesh=np.linspace(0,1,81)
def bruss_bvp(y):
u,v=y
return np.array([1.-3.3*u+u*u*v,2.3*u-u*u*v])
sample=solve_ivp(lambda t,y:bruss_bvp(y),(0,T),initial,t_eval=mesh*T,rtol=1e-8,atol=1e-10)
def ode(s,y,p): return p[0]*bruss_bvp(y)
def bc(ya,yb,p): return np.r_[ya-yb,ya[0]-1.]
coll=solve_bvp(ode,bc,mesh,sample.y,p=[T],tol=1e-6)
if not coll.success: raise RuntimeError(coll.message)
print('periodos disparo y colocación:',T,coll.p[0])
print('diferencia de periodo:',abs(T-coll.p[0]),'amplitud x:',np.ptp(coll.y[0]))Now integrate the variational system , , over the period obtained by shooting. In this particular cycle, the multiplier close to one corresponds to phase and the other determines transverse stability.
import numpy as np
from scipy.integrate import solve_ivp
period=orbit_fit[-1];start=orbit_fit[:2]
def floquet_rhs(t,z):
u,v=z[:2];M=z[2:].reshape(2,2)
field=np.array([1.-3.3*u+u*u*v,2.3*u-u*u*v])
jac=np.array([[-3.3+2*u*v,u*u],[2.3-2*u*v,-u*u]])
return np.r_[field,(jac@M).ravel()]
sol=solve_ivp(floquet_rhs,(0,period),np.r_[start,np.eye(2).ravel()],rtol=1e-9,atol=1e-11)
if not sol.success: raise RuntimeError(sol.message)
print('multiplicadores:',np.linalg.eigvals(sol.y[2:,-1].reshape(2,2)))
print('cierre de la órbita:',np.linalg.norm(sol.y[:2,-1]-start))The comparison shares the same seed and equation: it checks agreement in this case, not convergence for every parameter. Tools such as AUTO-07p, MatCont and BifurcationKit incorporate additional strategies; they are not run here.
Exercises
Step 1 of 3. What form does a vector w with Mw=0 have?
import numpy as np
def pseudo_arclength(F,J,x0,lam0,ds,n):
pass