2
$\begingroup$

I am trying to solve the wave PDE with NDSolve. Below is the equation:

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, 0] == 0]}, 
u[x, t], {x, 0, 10}, {t, 0, 5}]

When I try to get the solution I get the following error:

NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent.

NDSolve::ndinpd: The initial conditions did not evaluate to an array of numbers of depth 1 on the spatial grid. Initial conditions for partial differential equations should be specified as scalar functions of the spatial variables.

My Boundary conditions are:

  • when x=0 (at t=0) is zero
  • when x=10 (at t=0) is also zero

My Initial conditions are:

  • u when $t=0$ g[x]=5
  • derivative of u when t=0 is zero

By this initial condition it means the string is stretched in vertical direction by 5 units at its center, initial velocity being zero and then let go.

I want to check the wave pattern of the string with these conditions.

$\endgroup$
  • 1
    $\begingroup$ Notice that your last equation corresponding to "derivative of u when t=0 is zero" doesn't seem to be syntactically correct: D[u[x, 0] == 0]. This does not conform to the syntax of the D function, as you yourself have used it elsewhere. You should probably start by correcting that. $\endgroup$ – MarcoB Apr 22 '16 at 16:17
  • $\begingroup$ I get it now. I need to add t in that derivative, which would mean derivative w.r.t time, which would complete the D function. Thanks MarcoB for pointing this out. $\endgroup$ – Vikalp Luthra Apr 22 '16 at 18:11
  • $\begingroup$ u[0,0] == 5 == 0? $\endgroup$ – tsuresuregusa Apr 22 '16 at 19:15
  • 1
    $\begingroup$ @MarcoB 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$ – tsuresuregusa Apr 22 '16 at 20:17
  • 1
    $\begingroup$ I think you would spend your time more wisely if go again to a book and read how to solve the wave equation in 1D. This problem is analytical so can be solved easily by normal modes. Furthermore, your initial condition is unphysical, it implies the string is discontinuous which doesn't make sense. $\endgroup$ – tsuresuregusa Apr 23 '16 at 2:14
6
$\begingroup$

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] :

enter image description here

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 :

enter image description here

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"] 

enter image description here

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"]

enter image description here

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"]

enter image description here

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"]

enter image description here

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}]

enter image description here

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}]

enter image description here

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

$\endgroup$
  • 1
    $\begingroup$ If you replace the "TensorProductGrid" with "FinteElement" and remove "MaxPionts" you'll get FEM $\endgroup$ – user21 Apr 22 '16 at 22:42
  • $\begingroup$ Andre, in MMA 10.4.0 on Win7-64 your code seems to throw some errors and refuses to execute (output). What version are you using? $\endgroup$ – MarcoB Apr 23 '16 at 0:08
  • $\begingroup$ in my machine keeps on running forever, even after fixing the boundary conditions. $\endgroup$ – tsuresuregusa Apr 23 '16 at 2:10
  • $\begingroup$ I think the question was unclear about the initial condition. It's probably supposed to be u[x,0] == 5 - Abs[x-5] to get a triangle shape. I would have voted to close it if you hadn't already put in the work... Maybe you could try it for this more physical initial condition instead. $\endgroup$ – Jens Apr 24 '16 at 17:40

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.