I wish to solve the following second order partial differential equation

$$u_{tt}=c^2 u_{xx}$$

with the initial conditions

$$u(x,0)=e^x,\quad u_t(x,0)=\sin x$$

In Mathematica, I evaluated the following code:

DSolve[{D[p[x, t], {t, 2}] == c^2 *(D[p[x, t], {x, 2}]), 
        p[x, 0] == Exp[x], D[p[x, t], t] == Sin[x]},
      p[x, t], {x, t}]

Mathematica responded with

DSolve::deqx: Supplied equations are not differential equations of the given functions.

I think the problem lies in the initial conditions. How can I fix this code?

  • $\begingroup$ Hi Scorpio19891119! Welcome to Mathematica.SE! I formatted your post for more convenient to read. Please do check the source code to see how I did it by click the time above my avatar at the left bottom. Additionally please refer to this for more detail. $\endgroup$
    – Silvia
    Commented Jan 19, 2013 at 22:26
  • $\begingroup$ You should use Derivative[0, 1][p][x, 0] == Sin[x] instead of D[p[x, t], t] == Sin[x] in your code. (Although this correction did not seem to be sufficient to give a solution.) $\endgroup$
    – Silvia
    Commented Jan 19, 2013 at 22:45
  • 1
    $\begingroup$ @Silvia That notation doesn't really matter (OK, one has to add /.t->0 in his approach, but it's not the main problem). I feel tempted to answer, but it looks a lot like a homework problem. As a hint: first solve without the initial conditions, leading to two functions C[1] and C[2]. Then find those functions by imposing the initial conditions at t = 0. This can be done by converting both conditions to a set of equations only involving C'[i] at x and -x. $\endgroup$
    – Jens
    Commented Jan 19, 2013 at 23:57
  • $\begingroup$ @Jens +1 btw I'm aware of the standard method for dealing with so-called traveling wave solutions, but wondering why DSolve can't handle this.. $\endgroup$
    – Silvia
    Commented Jan 20, 2013 at 0:31
  • $\begingroup$ @Silvia That's a valid question - but for now the only answer seems to be: it just can't be done. At least looking at the DSolve documentation, it states that the acceptable form for PDEs is only DSolve[eqn, y, {x1, x2, ...}] and not DSolve[{eqn1, eqn2 ...}, y, {x1, x2, ...}] with multiple equations as would be the use case here. $\endgroup$
    – Jens
    Commented Jan 20, 2013 at 7:01

3 Answers 3


Looking at the DSolve documentation, it states that the acceptable form for partial differential equations is only DSolve[eqn, y, {x1, x2, ...}] and not DSolve[{eqn1, eqn2 ...}, y, {x1, x2, ...}] with multiple equations as would be the use case here.

The documentation may in fact not be quite consistent here: there is an example of an "initial condition" in a first-order PDE on this page, but the wording of the docs indicates that there's no guarantee that DSolve can handle arbitrary PDEs with initial or boundary conditions. That makes sense because most such PDEs have no closed-form solutions.

So you have to solve the PDE without the initial conditions first. That will give you a well-known result but in terms of functions named in Mathematica's standard way, C[1] and C[2]. Then you'll need to figure out a way to determine these unknown functions from the initial conditions. Since I don't know if this is a homework problem, I'll leave it at that for now.

Another approach would be to use NDSolve, which does allow you to specify initial conditions (see under "Applications", "Partial Differential Equations").

  • $\begingroup$ +1 Indeed! Never noticed that statement before.. Thanks $\endgroup$
    – Silvia
    Commented Jan 20, 2013 at 11:36

I'd like to post a LaplaceTransform-based solution:

eqn = D[p[x, t], {t, 2}] == c^2*(D[p[x, t], {x, 2}]);
ic = {p[x, 0] == Exp[x], D[p[x, t], t] == Sin[x] /. t -> 0};

teqn = LaplaceTransform[eqn, t, s] /. Rule @@@ ic

(* Notice that p[x, t] in the following equation implies the Laplace transform of p[x, t] *)
tsol = DSolve[teqn /. HoldPattern@LaplaceTransform[a_, t, s] :> a, p[x, t], x]

sol = InverseLaplaceTransform[tsol[[1, 1, 2]], s, t] // FullSimplify
E^x Cosh[c t] + C[2] DiracDelta[t - x/c] + C[1] DiracDelta[t + x/c] + (Sin[c t] Sin[x])/c

Since OP doesn't mention anything about x, I'll leave those constants there.

I've wrap the above procedure into a function pdeSolveWithLaplaceTransform here and now the problem can be solved like:

pdeSolveWithLaplaceTransform[eqn, ic, p[x, t], t, x]

Replacing D[p[x, t], t] == Sin[x] in the OP's code with (D[p[x, t], t]/.x->0) == Sin[x] in Mathematica 10.3 gives me

{{p[x,t]->1/2 (E^(-Sqrt[c^2] t+x)+E^(Sqrt[c^2] t+x))+(Sin[Sqrt[c^2] t] Sin[x])/Sqrt[c^2]}}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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