Pick the solution that Newton’s method finds¶
Use this when a nonlinear stationary equation has more than one solution, and you want another one than pdemagic returns by itself.
Steps¶
Solve without a starting value first. Newton’s method then starts from zero and finds the solution it reaches from there.
Write down a rough shape of the solution you want: a formula in the coordinates that fits the boundary conditions.
Pass it as
guess={u: formula}and solve again.Check which solution you got, by a value you know or by a plot.
Example¶
The problem of Bratu, \(v'' + e^v = 0\) on a string that is fixed at both ends, has two solutions: a low one and a high one.
import sympy as sp
import pdemagic as pm
x = sp.Symbol("x", real=True)
v = sp.Function("v")(x)
string = pm.Box({x: (0, 1)})
bratu = sp.Eq(v.diff(x, 2) + sp.exp(v), 0)
lower = pm.solve(pm.Problem(bratu, domain=string, boundary=sp.Eq(v, 0)))
upper = pm.solve(
pm.Problem(bratu, domain=string, boundary=sp.Eq(v, 0), guess={v: 16 * x * (1 - x)})
)
upper.plot()
assert lower.plan.method.kind == "collocation_newton"
assert abs(lower(0.5) - 0.1405392) < 1e-6
assert abs(upper(0.5) - 4.0914672) < 1e-6
assert "from zero" in lower.plan.notes[-1]
assert "from the given starting value" in upper.plan.notes[-1]
assert upper.diagnostics["newton_steps"] < 10
Notes¶
The starting value need not be accurate. Here the constant
guess={v: 4}leads to the upper solution as well.If Newton’s method does not arrive, pdemagic raises
ConvergenceErrorand returns nothing. Give a starting value that is closer, or raiseplan.method.max_steps.A starting value is a formula or a number. In free space, on periodic boxes and on shapes in the plane it can be an array, a
pm.GridData. On boxes with walls and on round domains it cannot yet.In free space the planner puts the box around the starting value. A solution that reaches further shows in the diagnostic
source_boundary_ratio, and the box can be widened in the plan.pdemagic finds one solution for each start. It does not follow a solution as a parameter changes.
Nonlinear stationary equations explains what the equation may hold. The gallery has the two states of Bratu, and the method is on the page about Newton’s method.