I'm trying to solve the following PDE wave equation using method of lines:

Wave Equation: u_tt = u_xx

with initial condition: u(0,x) = sin*pi,u_t(0,x)=0, 0 < x < 1

boundary condition: u(t,0) = 0, u(t,1) = 0, t >= 1

Edited: deleted the old code and will be posting a new one soon. :)

  • 1
    $\begingroup$ There is now no question here at all. $\endgroup$ Nov 14 '15 at 7:48

The problem is that odeint solves first-order ODEs of the form $$\dot u(t) = Au(t),$$ but the wave equation is (after discretization in space) a second-order ODE of the form $$\ddot{u}(t) = Au(t).$$ (And in fact, your plot looks quite reasonable for the solution to a parabolic equation.) To apply a black-box ODE solver (which is really not such a great idea, by the way), you first need to rewrite the wave equation as a system of first-order equations $$ \left\{\begin{aligned} \dot{u}(t) &= v(t),\\ \dot{v}(t) &= Au(t).\end{aligned}\right.$$

At the risk of sounding brusque: Before making more than minor modifications to such code, you should first read up a bit on PDEs to understand what you're trying to solve. A good starting point could be the Appendix E of Randy LeVeque, Finite Difference Methods for Ordinary and Partial Differential Equations, SIAM 2007.


Since the wave equation involves a second derivative in time, two initial conditions are necessary: initial displacement $U(x,0)$ and initial velocity $U_t(x,0)$. I don't see the initial velocity condition specified in your question. This leads me to suspect that there is something wrong with the tutorial you linked to...

As I suspected, the code in the tutorial is for the heat equation, not the wave equation. In order to solve the wave equation, you will also need to use a different time stepping scheme altogether. The one implemented in the tutorial will not work for the wave equation.

  • $\begingroup$ The initial velocity is given as 0 (i.e. ut(0,x) = 0). I'll edit this to make it clearer later, thanks. How might I go about a different time stepping scheme? I'm very new to PDEs by the way, but I'll try to look for tutorials and post them later. $\endgroup$
    – meraxes
    Nov 12 '15 at 18:08
  • $\begingroup$ @meraxes: Any book on finite difference methods should include methods for this equation. A cursory google search of the terms "wave equation finite difference" yields these lecture notes, should be helpful to you: math.ubc.ca/~peirce/M257_316_2012_Lecture_8.pdf $\endgroup$
    – Paul
    Nov 12 '15 at 18:23

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