1
$\begingroup$

I'm attempting to solve a PDE with initial and boundary conditions numerically, but my code produces a message saying I have an insufficient number of initial conditions. This is indeed false, as I can even solve the PDE with these conditions analytically. The code I'm using is,

Clear[nsol];
Clear[t];
nsol = 
  NDSolve[
    {D[u[x, t], {x, 2}] == D[u[x, t], {t, 2}], 
     u[x, 0] == x*E^(-x^2), 
     Derivative[0, 1][u][x, 0] == 0, 
     u[0, t] == 0}, 
    u, {x, -10, 10}, {t, 0, 12}]

My code is posted in a screenshot below. If anyone can help that'd be great! :)

enter image description here

$\endgroup$
  • $\begingroup$ Your conditions could be u[x, 0] == x*E^(-x^2), Derivative[0, 1][u][x, 0] == 0, u[-10, t] == u[10, t] == 0 $\endgroup$ – user36273 Sep 28 '16 at 13:11
  • $\begingroup$ Hey thanks for the comment! That doesn't seem to provide a solution either, and I think those boundary conditions may affect my solution if it were to work otherwise. $\endgroup$ – charl1e Sep 28 '16 at 13:23
2
$\begingroup$

For a numerical solution you have to add a boundary condition. Now with DSolveValue we get:

sol = DSolveValue[{D[u[x, t], {x, 2}] == D[u[x, t], {t, 2}],
   u[x, 0] == x*E^(-x^2), Derivative[0, 1][u][x, 0] == 0,
   u[0, t] == 0},
  u, {x, -10, 10}, {t, 0, 12}]

enter image description here

Plot3D[sol[x, t], {x, 0, 10}, {t, 0, 12}, PlotRange -> All, AxesLabel -> Automatic]

enter image description here

With a second boundary condition we get;

nsol = NDSolve[{D[u[x, t], {x, 2}] == D[u[x, t], {t, 2}],
   u[x, 0] == x*E^(-x^2), Derivative[0, 1][u][x, 0] == 0,
   u[0, t] == u[10, t] == 0},
  u, {x, 0, 10}, {t, 0, 12}];

Plot3D[u[x, t] /. nsol, {x, 0, 10}, {t, 0, 12}, PlotRange -> All, 
 AxesLabel -> Automatic]

enter image description here

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks so much for helping out! It's very much appreciated, I'm also very thankful that you showed how to get the analytical solution too. Thanks so much for your time :) $\endgroup$ – charl1e Sep 29 '16 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.