微分方程数值解作业 4
Problem 1


Numerical domain of dependence for each method
The CFL condition require that the numerical domain of dependence should contain the physical domain of dependence, which is
- Can be used. Satifies the CFL condition when
- Cannot be used. It never satisfies the CFL condition.
- Can be used. Satifies the CFL condition when
- Cannot be used. It never satisfies the CFL condition.
Problem 2

Question (a)
Question (b)
The numerical domain of dependence for the Fromm method is
The CFL condition requires that the numerical domain of dependence should contain the physical domain of dependence, which is a single point
that is
To discuss the stability of the Fromm method, we use the assumption
Substitute this into the Fromm method, we have
Divide by
The amplification factor is
To be stable, we need
Therefore,
Finally we have that the Fromm method is stable when

To discuss the monotonicity of the Fromm method, it can be noticed that the four coefficients of the Fromm method can never be all positive at the same
Question (c)
The Fromm method
Determine the truncation error by using Taylor expansion (
Notice that
Therefore, we have
Problem 3

Question (a)
Use the Taylor expansion
Question (b)
The differential equation to solve is
On grid points
Extract
Substitute
Question (c)
To discuss the stability, use the assumption
Substitute this into FDE, we have
The amplification factor is
To be stable, we need
Therefore,
That is, the stable condition is
Problem 4

makeTridiagonal[n_, {a_, b_, c_}] :=
DiagonalMatrix[ConstantArray[c, n - 1], -1] +
DiagonalMatrix[ConstantArray[b, n]] +
DiagonalMatrix[ConstantArray[a, n - 1], 1];
upwind[n_, \[Lambda]_] :=
makeTridiagonal[n, {0, 1 - \[Lambda], \[Lambda]}];
laxFriedrichs[n_, \[Lambda]_] := Module[{mat},
mat =
makeTridiagonal[
n, {1/2 (1 - \[Lambda]), 0, 1/2 (1 + \[Lambda])}];
mat[[n, n - 1]] = \[Lambda];
mat[[n, n]] = 1 - \[Lambda];
Return[mat];
];
laxWendroff[n_, \[Lambda]_] := Module[{mat},
mat =
makeTridiagonal[
n, {-\[Lambda]/2 (1 - \[Lambda]),
1 - \[Lambda]^2, \[Lambda]/2 (1 + \[Lambda])}];
mat[[n, n - 1]] = \[Lambda];
mat[[n, n]] = 1 - \[Lambda];
Return[mat];
];advectionSolve[a_, g_, n_, l_, r_, m_, td_, method_] :=
Module[{x, t, k, h, \[Lambda], mat, u},
h = (r - l)/(n + 1);
x = Range[l + h, r - h, h];
k = td/m;
t = Range[0, td, k];
\[Lambda] = (a k)/h;
mat = method[n, \[Lambda]];
u = ConstantArray[0, {n, m + 1}];
u[[All, 1]] = g /@ x;
Do[u[[All, j]] = mat . u[[All, j - 1]], {j, 2, m + 1}];
Return[
Interpolation[
Join[Flatten[MapThread[List, {Outer[List, x, t], u}, 2], 1],
Map[{{l, #}, 0} &, t], Map[{{r, #}, 0} &, t]],
InterpolationOrder -> 1]];
];Test the code with the following example
a = 1;
g = Function[x, If[0 <= x <= 1, 1., 0.]];
l = -10;
r = 10;
td = 7;
sol = advectionSolve[a, g, 201, l, r, 72, td, laxFriedrichs];
Manipulate[
Plot[sol[x, t], {x, -10, 10}, PlotRange -> {-1, 2}], {t, 0, 7}]
exact = DSolveValue[{D[u[x, t], x] + D[u[x, t], t] == 0,
u[x, 0] == If[0 <= x <= 1, 1, 0]}, u[x, t], {x, t}];
makeFigure411[a_, g_, n_, l_, r_, ms_, td_, method_, exact_] :=
GraphicsColumn[Function[m, Module[{xs, sol},
xs = Subdivide[l, r, n + 1];
sol = advectionSolve[a, g, n, l, r, m, td, method];
ListLinePlot[{sol[#, td] & /@ xs,
exact /. {x -> #, t -> td} & /@ xs},
PlotRange -> {-1, 1.2},
DataRange -> {l, r},
PlotLegends ->
Placed[{StringForm["M = ``", m], "Exact"}, {0.2, 0.1}],
PlotStyle -> {Thick, Directive[Black, Dashed]},
AxesLabel -> {"x", "solution"},
AspectRatio -> 1/3,
ImageSize -> Medium
]
]] /@ ms, ImageSize -> Large];makeFigure411[a, g, 201, l, r, {70, 72}, td, #, exact] & /@ {upwind,
laxWendroff, laxFriedrichs}
For all
That indicates all these methods are unstable. As a result, it can be observed that all three solutions oscillate at the discontinuity. When
That indicates all these methods are stable. It can be seen that the oscillation no longer exists in the solution. Among these three methods, Lax-Wendroff method is not monotonic, while the other two methods are monotonic. This is reflected in the solution, where the Lax-Wendroff method has overshoots at the discontinuity, while other two methods do not.