There are two different methods for solving the OP"s problem :
The Method of Lines with the option "SpatialDiscretization" -> {"TensorProductGrid"...
The Method of Lines with the option "SpatialDiscretization" -> {"FiniteElement"}
. This solution is the Mathematica 10 implementation of the Finite Element Method for transcient PDEs.
In both cases the Method of Lines does the temporal integration.
Apart from this, the solution will be given for the following cases :
1) OP's equation and initial condition u[x,0] == triangle : u[x,0] == 5 - Abs[x-5]
:
2) Because the exact OP's equation doesn't give a realistic result, the equation is modified by adding some loss and the result is shown
3) initial condition : u[x,0] == 5
:
1) initial condition u[x,0] == triangle, Lossless
Method of Lines with TensorProductGrid
solTensorLossless =
NDSolve[{D[u[x, t], {t, 2}] == 2*D[u[x, t], {x, 2}], u[0, t] == 0,
u[10, t] == 0,
u[x, 0] == 5 - Abs[x - 5], (D[u[x, t], t] /. t -> 0) == 0},
u, {x, 0, 10}, {t, 0, 15},
Method -> {"MethodOfLines", "TemporalVariable" -> t,
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> {50}, "MaxPoints" -> {100},
"DifferenceOrder" -> "Pseudospectral"}}][[1, 1, 2]];
Table[Labeled[
Plot[solTensorLossless[x, t], {x, 0, 10},
PlotRange -> {Automatic, {-5, 5}}], t], {t, 0, 15, 0.2}] //
Export["TensorLossLess.gif", #] &;
SystemOpen["TensorLossLess.gif"]
Method of Lines with Finite Elements
solFEMLossless =
NDSolve[{D[u[x, t], {t, 2}] == 2*D[u[x, t], {x, 2}], u[0, t] == 0,
u[10, t] == 0,
u[x, 0] == 5 - Abs[x - 5], (D[u[x, t], t] /. t -> 0) == 0},
u, {x, 0, 10}, {t, 0, 15},
Method -> {"MethodOfLines", "TemporalVariable" -> t,
"SpatialDiscretization" -> {"FiniteElement"}}][[1, 1, 2]];
Table[Labeled[
Plot[solFEMLossless[x, t], {x, 0, 10},
PlotRange -> {Automatic, {-5, 5}}], t], {t, 0, 15, 0.2}] //
Export["FEMLossLess.gif", #] &;
SystemOpen["FEMLossLess.gif"]
2) initial condition u[x,0] == triangle, Lossy
Method of Lines with TensorProductGrid
solTensorLossy =
NDSolve[{D[u[x, t], {t, 2}] + 0.3 D[u[x, t], {t, 1}] ==
2*D[u[x, t], {x, 2}], u[0, t] == 0, u[10, t] == 0,
u[x, 0] == 5 - Abs[x - 5], (D[u[x, t], t] /. t -> 0) == 0},
u, {x, 0, 10}, {t, 0, 15},
Method -> {"MethodOfLines", "TemporalVariable" -> t,
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> {50}, "MaxPoints" -> {100},
"DifferenceOrder" -> "Pseudospectral"}}][[1, 1, 2]];
Table[Labeled[
Plot[solTensorLossy[x, t], {x, 0, 10},
PlotRange -> {Automatic, {-5, 5}}], t], {t, 0, 15, 0.2}] //
Export["TensorLossy.gif", #] &;
SystemOpen["TensorLossy.gif"]
Method of Lines with Finite Elements
solFEMLossy =
NDSolve[{D[u[x, t], {t, 2}] + 0.3 D[u[x, t], {t, 1}] ==
2*D[u[x, t], {x, 2}], u[0, t] == 0, u[10, t] == 0,
u[x, 0] == 5 - Abs[x - 5], (D[u[x, t], t] /. t -> 0) == 0},
u, {x, 0, 10}, {t, 0, 15},
Method -> {"MethodOfLines", "TemporalVariable" -> t,
"SpatialDiscretization" -> {"FiniteElement"}}][[1, 1, 2]];
Table[Labeled[
Plot[solFEMLossy[x, t], {x, 0, 10},
PlotRange -> {Automatic, {-5, 5}}], t], {t, 0, 15, 0.2}] //
Export["FEMLossy.gif", #] &;
SystemOpen["FEMLossy.gif"]
3) initial condition : u[x,0] == 5
Method of Lines + TensorProductGrid
solTensorProductGrid00 =
NDSolve[{
D[u[x, t], {t, 2}] == 2*D[u[x, t], {x, 2}],
u[0, t] == 0,
u[10, t] == 0,
u[x, 0] == 5,
(D[u[x, t], t] /. t -> 0) == 0
},
u,
{x, 0, 10}, {t, 0, 5},
Method -> {"MethodOfLines",
"TemporalVariable" -> t,
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> {50},
"MaxPoints" -> {100},
"DifferenceOrder" ->"Pseudospectral"
}
}
];
solTensorProductGrid = solTensorProductGrid00[[1, 1, 2]];
Plot3D[solTensorProductGrid[x, t], {x, 0, 10}, {t, 0, 5}]
Method of Lines + Finite Element
solFiniteElementMethod00 =
NDSolve[{
D[u[x, t], {t, 2}] == 2*D[u[x, t], {x, 2}],
u[0, t] == 0,
u[10, t] == 0,
u[x, 0] == 5,
(D[u[x, t], t] /. t -> 0) == 0
},
u,
{x, 0, 10}, {t, 0, 5},
Method -> {"MethodOfLines",
"TemporalVariable" -> t,
"SpatialDiscretization" -> {"FiniteElement"}}
]
solFiniteElementMethod = solFiniteElementMethod00[[1, 1, 2]];
Plot3D[solFiniteElementMethod[x, t], {x, 0, 10}, {t, 0, 5}]
Note : the theorical solution is : two perfect steps propagating from the edges towrad center (hyperbolic PDEs propagate discontinuities). Here the steps are not perfect since we dont have u[0,t]=u[10,t]=0
My version of Mathematica : 10.0.2.0 Windows 64 bits
D[u[x, 0] == 0]
. This does not conform to the syntax of theD
function, as you yourself have used it elsewhere. You should probably start by correcting that. $\endgroup$u[0, t] == 0, u[10, t] == 0, u[x, 0] == 5
the conditions are ill-defined for u[0,0], approaching from one side is 5 but from the other is 0. $\endgroup$