5
$\begingroup$

I'm brand new to Mathematica. I am trying to solve a heat equation problem, but I keep getting back the input on the output line.

The problem:

Consider the equation

$\qquad u_t = u_{xx} - 9 u_x$, $0\lt x\lt1 , t\gt0$,

with boundary condition $u(0,t) = 0 ,\ u(1,t) = 0$

and initial condition

$u(x,0) = e^{4.5x}\!\left(5\sin\!\left(\pi\,x\right)+9\sin\!\left(2\,\pi\,x\right)+2\sin\!\left(3\,\pi\,x\right)\right)$.

Solve for $u(x,t)$

My try at the code:

heqn = D[u[x, t], t] == D[u[x, t], {x, 2}] - 9*D[u[x, t], x]; 
ic = 
  {u[x, 0] == E^(4.5x)*(5 Sin[Pi*x] + 9 Sin[2*Pi*x] + 2 Sin[3*Pi*x]), 
   u[0,t] == 0, u[1,t] == 0};
sol = DSolveValue[{heqn, ic}, u[x, t], {x, t}]

The output is just a simplified version of my input.

What am I doing wrong?

$\endgroup$
  • $\begingroup$ One thing is that you need square brackets for Sin, for example Sin[Pi x] $\endgroup$ – MelaGo Apr 26 at 23:52
  • $\begingroup$ @MelaGo Adding square brackets still gives me back the input $\endgroup$ – CA1998 Apr 26 at 23:56
  • 1
    $\begingroup$ never use real numbers when using exact solvers like DSolve and Solve and Integrate, etc.. This is the first rule of thumb I learned using Mathematica long time ago. $\endgroup$ – Nasser Apr 27 at 7:00
4
$\begingroup$
Clear["Global`*"]

heqn = D[u[x, t], t] == D[u[x, t], {x, 2}] - 9*D[u[x, t], x];
ic = {u[x, 0] == E^(9 x/2)*(5 Sin[Pi*x] + 9 Sin[2*Pi*x] + 2 Sin[3*Pi*x]),
   u[0, t] == 0, u[1, t] == 0};

sol[x_, t_] = DSolveValue[{heqn, ic}, u[x, t], {x, t}] //
  FullSimplify

(* E^(-(9/4) ((9 + 4 π^2) t - 2 x)) (5 E^(8 π^2 t) Sin[π x] + 
   9 E^(5 π^2 t) Sin[2 π x] + 2 Sin[3 π x]) *)

Verifying the solution,

{heqn, ic} /. u -> sol // Simplify

(* {True, {True, True, True}} *)

Plotting the solution,

Plot3D[sol[x, t], {x, 0, 1}, {t, 0, 0.15},
 AxesLabel -> (Style[#, 12, Bold] & /@ {"x", "t", "sol"}),
 PlotRange -> All]

enter image description here

Limit[sol[x, t], t -> Infinity]

(* 0 *)
$\endgroup$
  • 1
    $\begingroup$ Funny, the only modification here is 4.5 -> 9/2? $\endgroup$ – xzczd Apr 27 at 6:12
3
$\begingroup$

This finds a solution very quickly.

uF =
  NDSolveValue[
    {D[u[x, t], t] == D[u[x, t], {x, 2}] - 9*D[u[x, t], x], 
     u[x, 0] == E^(4.5 x) (5 Sin[Pi x] + 9 Sin[2 Pi x] + 2 Sin[3 Pi x]),
     u[0, t] == 0, u[1, t] == 0},
    u, {x, 0, 1}, {t, 0, 1}]

and gives the following plot:

Plot3D[uF[x, t], {x, 0, 1}, {t, 0, 0.1}, 
  AxesLabel -> {"x", "t", "u"}, PlotRange -> All]

plot

$\endgroup$
  • $\begingroup$ Thank you for the solution. $\endgroup$ – CA1998 Apr 27 at 3:55
  • 1
    $\begingroup$ @CA1998. I have made major corrections to the code. $\endgroup$ – m_goldberg Apr 27 at 4:14

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.