Numerically solve PDEs with constraints and without boundary solution
Linear PDEs typically are solved by the method of characteristics. For the PDE in the question, the ODEs of the characteristics are
{x2'[s] == Sin[x1[s]] + x2[s], x1'[s] == x2[s], h'[s] == h[s]}
Attempting to solve these ODEs with DSolve
is unsuccessful, returning the Solve::ifun
error message. That this is the same error cited in the question is not surprising, because DSolve
itself undoubtedly uses the method of characteristics when attempting to solve a linear or quasilinear PDE. (See questions 238346 and 238808 for examples in which the characteristics, and therefore the PDE, can be solved symbolically.) However, NDSolve
can evaluate the characteristics with little difficulty. Focus first on the ODEs for (x1, x2}
.
sp = ParametricNDSolveValue[{x2'[s] == Sin[x1[s]] + x2[s], x1'[s] == x2[s],
x1[0] == x10, x2[0] == x20}, {x1[s], x2[s]}, {s, -10, 10}, {x10, x20}];
Table[sp[n, -2], {n, -4.03, 2, .1}];
pt = ParametricPlot[%, {s, -10, 10}, PlotRange -> {{-2, 2}, {-2, 2}},
ImageSize -> Large, FrameLabel -> {x1, x2}, LabelStyle -> {15, Bold, Black},
PlotStyle -> RGBColor[0.368417, 0.506779, 0.709798]];
Before displaying the result, let us superimpose (in black) the two stream lines that pass through the origin.
NDSolveValue[{x2'[s] == Sin[x1[s]] + x2[s], x1'[s] == x2[s], x1[10^-5] == 10^-5,
x2[10^-5] == 10^-5 1/2 (1 - Sqrt[5])}, {x1[s], x2[s]}, {s, -50, 50}];
pt0 = ParametricPlot[%, {s, -50, 50}, PlotStyle -> Black,
PlotRange -> {{-2, 2}, {-2, 2}}];
Show[pt, pt /. Line[z_] -> Line[-z], pt0, pt0 /. Line[z_] -> Line[-z]]
(The substitution, Line[z_] -> Line[-z]
reflects the solution in the origin, reducing computations by a factor of two.) Now, the point of evaluating the characteristics is that h2[x1, x2]
satisfies
DSolveValue[h'[s] == h[s], h[s], s]
(* E^s C[1] *)
along each stream line, with C[1]
a constant that can vary from stream line to stream line. Consequently, if the value of h2[x1, x2]
is known anywhere on each stream line, its value is known everywhere. The question above specifies only that the gradient of h2[x1, x2]
vanishes at the origin. From the PDE, it immediately follows that h2[0, 0]
also vanishes, and the value of h2[x1, x2]
must be zero everywhere along the black lines. Moreover, h[x1, x2]
also must vanish on characteristics passing infinitesimally close to the origin. However, values of h2[x1, x2]
on other stream lines are unspecified.
For completeness, here is a plot of the stream lines over a larger domain.
rl = Table[{Line[z_] :> Line[{2 nn Pi + #[[1]], #[[2]]} & /@ z]} /.
nn -> n, {n, -2, 2}];
Table[sp[n, -4], {n, -6 Pi, 3 Pi, Pi/5}];
ParametricPlot[%, {s, -10, 10}, PlotRange -> {{-10, 10}, {-4, 4}},
ImageSize -> Large, FrameLabel -> {x1, x2}, LabelStyle -> {15, Bold, Black},
PlotStyle -> RGBColor[0.368417, 0.506779, 0.709798]];
Show[%, % /. Line[z_] -> Line[-z], Replace[{pt0, pt0 /. Line[z_] -> Line[-z]},
rl, All]]
As would be expected, the structure of the stream lines is periodic in x1
with period 2 Pi
. Finally, it should be noted that StreamPlot
can produce similar plots, although with less detail.
Response to OP's comment
Le ZHENG asked in a comment below about the initial conditions in
NDSolveValue[{x2'[s] == Sin[x1[s]] + x2[s], x1'[s] == x2[s], x1[10^-5] == 10^-5,
x2[10^-5] == 10^-5 1/2 (1 - Sqrt[5])}, {x1[s], x2[s]}, {s, -50, 50}];
used above. They were obtained by combining the first two characteristic equations at the beginning of the answer to obtain
x2'[x1] == (Sin[x1] + x2[x1])/x2[x1]
For stream lines passing through the origin, x2'[x1]
is equal to x2[x1]/x1
. With these expressions set to a
for convenience, the preceding equation becomes a == 1/a + 1
, which has the solutions
Solve[a == 1/a + 1, a] // Flatten
(* {a -> 1/2 (1 - Sqrt[5]), a -> 1/2 (1 + Sqrt[5])} *)
Hence, very near the origin x2 = x1 1/2 (1 - Sqrt[5])
for one stream line and x2 = x1 1/2 (1 + Sqrt[5])
for the other. I chose "very near" to be x1 = 10^-5
. And, because the set of characteristic equations is autonomous (not explicitly dependent on s
), I could choose s
corresponding to x1 = 10^-5
to be any value whatsoever. I chose it equal to x1
.
By the way, no stream lines pass through {2 PI n, 0}
. with n
an odd integer. Instead, they spiral around those points with exponentially decreasing radii.
Sample Complete Numerical Solution
As a sample solution, choose h[x1,x2] = (x1^2 +x2^2)/4
along the x and y axes, which is sufficient to completely determine h
and satisfies the requirements that h
and its gradients vanish at the origin. It is convenient for this computation to eliminate s
from the characteristic ODEs in favor of x1
or x2
.
sp1 = ParametricNDSolveValue[{x2'[x1] == (Sin[x1] + x2[x1])/x2[x1],
h'[x1] == h[x1]/x2[x1], x2[0] == x0, h[0] == x0^2/4,
WhenEvent[x2[x1] > 3.5, "StopIntegration"]}, {x1, x2[x1], h[x1]}, {x1, -2, 2}, x0];
sp2 = ParametricNDSolveValue[{x1'[x2] == x2/(Sin[x1[x2]] + x2),
h'[x2] == h[x2]/(Sin[x1[x2]] + x2), x1[0] == x0, h[0] == x0^2/4,
WhenEvent[x1[x2] > 2, "StopIntegration"]}, {x1[x2], x2, h[x2]}, {x2, -2, 2}, x0];
plt1 = Show@Table[tem = sp1[n]; ParametricPlot3D[tem,
Evaluate[Join[{x1}, Flatten[Last[tem] /. x1 -> "Domain"]]],
PlotRange -> {{-2, 2}, {-2, 2}, {0, 1.5}}, AxesLabel -> {x1, x2, h},
ImageSize -> Large, LabelStyle -> {15, Bold, Black}], {n, .01, 3.5, .05}];
plt2 = Show@Table[tem = sp2[n]; ParametricPlot3D[tem,
Evaluate[Join[{x2}, Flatten[Last[tem] /. x2 -> "Domain"]]],
PlotRange -> {{-2, 2}, {-2, 2}, {0, 1.5}}, AxesLabel -> {x1, x2, h},
ImageSize -> Large, LabelStyle -> {15, Bold, Black}], {n, .01, 2, .05}];
Show[plt1, plt1 /. Line[z_] :> Line[Map[{-#[[1]], -#[[2]], #[[3]]} &, z]],
plt2, plt2 /. Line[z_] :> Line[Map[{-#[[1]], -#[[2]], #[[3]]} &, z]]]
As expected, h = 0
on the stream lines passing through the origin and those infinitesimally close. The solution also can be displayed with Plot3D
.
Flatten[Cases[%, Line[z_] -> z, Infinity], 1];
ListPlot3D[%, PlotRange -> {{-2, 2}, {-2, 2}, {0, 1.5}}, AxesLabel -> {x1, x2, h},
ImageSize -> Large, LabelStyle -> {15, Bold, Black}]