# Solve 1D Wave Equation

I wanna model 1D wave equation and plot it, Here is my try so far,

 (* length *)
length = 1;
(* Wave Equation *)
weqn = D[WaveEq[x, t], t, t] == 20*D[WaveEq[x, t], x, x];

(* Initial Conditions*)
ic = {WaveEq[x, 0] == Sin[Pi*x], Derivative[0, 1][WaveEq][x, 0] == 0};
(* Boundry Conditions*)
bc = {WaveEq[0, t] == 0, WaveEq[length, t] == 0};

(* Calculation *)

sol1 = NDSolve[{weqn, ic, bc }, WaveEq[x, t], {x, 0, 1}, {t, 0, 1}]


Issue are, Have I declared boundary conditions properly and is implementation right?

Try this

ClearAll[u, x, t];
len = 1;
pde = D[u[x, t], t, t] == 20*D[u[x, t], x, x];
(*Initial Conditions*)
ic = {u[x, 0] == Sin[Pi*x], Derivative[0, 1][u][x, 0] == 0};
(*Boundry Conditions*)
bc = {u[0, t] == 0, u[len, t] == 0};
sol = u[x, t] /. First@DSolve[{pde, ic, bc}, u[x, t], {x, t}]


Which gives

Manipulate[
Plot[sol /. t -> t0, {x, 0, 1}, PlotRange -> {Automatic, {-1, 1}}],
{{t0, 0, "time"}, 0, 2, .01}
]


• Does the manipulation of an interpolating function (sol) like this have 1. Any impact on your ram usage and 2. Any difference from using a table to numerically collate the solution set to then just manipulate through by stepping through the indexes of the collated table? Jul 31, 2019 at 3:36
• @CATrevillian hi., I am not sure on these performance issues you raise. For me, I do not see much RAM use issue. But these are good questions. May be you can post this as separate question and someone more experienced with performance issues can better help. Jul 31, 2019 at 3:57
• oh, I suppose I can ask a question, I was just hoping to hear that it didn’t have much impact (I have a method for collating the data as I inquired to, as my systems are usually large enough to kill my ram (16-32gb) while I play with the manipulate) using DSolve versus NDSolve. I will post a question in the morning maybe then, with a wiki response. Perhaps others will have better recommendations. Mind if I link to this answer when I do? Jul 31, 2019 at 4:05
• @CATrevillian yes, ofcourse you can add link. Only issue I had with manipulate in terms of performance is when I was doing 3D animations and with some options added (I think it was Opacity) That made it very slow. But for basic ones like this, I did not notice any RAM issues so far. Jul 31, 2019 at 4:07
• Thank you @nasser. Highly appriciate it. Jul 31, 2019 at 6:47