Today I was studying partial differential equations and I tried to check if my solution was correct, I thought Mathematica code would be easy, but it wasn't. Here is my problem:
Solve $u_{xx}-2tu-u_t=0$ for $0<x<1/2$ and $t>0$ with the boundary conditions $u_x(0,t)=u(1/2,t)=0$ and initial conditions $u(x,0)=1-2x$.
By hand I obtained $$u(x,t)=\frac{8}{\pi^2}\sum_{n=0}^{\infty}\frac{1}{(2n+1)^2}e^{-t^2-(2n+1)^2\pi^2t}\cos((2n+1)\pi x)$$
Then I tried with the following code in Mathematica:
pde = D[u[x, t], {x, 2}] - 2 t*u[x, t] == D[u[x, t], {t, 1}];
ic = {u[x, 0] == 1 - 2 x};
bc = {u[1/2, t] == 0, Derivative[1, 0][u][0, t] == 0};
sol = First@(u[x, t] /. DSolve[{pde, ic, bc}, u[x, t], {x, t}]);
I don't know why I am getting error. Thanks in advance for your help.
u[x, 0] = 1- 2x
clearly shows that there is a linear slope at x = 0, t = 0, so there must be some change in the x-direction. In fact, if I switch your code toNDSolve
, I get an error "Warning: boundary and initial conditions are inconsistent." It looks to be like it deals with it by simply ignoring one of your boundary conditions. $\endgroup$ – MassDefect Jan 8 at 6:39pde = D[u[x, t], t] == D[u[x, t], {x, 2}]
(heat equation), the code works. $\endgroup$ – yawnoc Jan 8 at 7:43u[x_,t_]:=8/Pi^2 1/(2n+1)^2 E^(-t^2-(2n+1)^2 Pi^2 t) Cos[(2n+1)Pi x]; Simplify[D[u[x, t], {x, 2}] - 2 t*u[x, t] == D[u[x, t], {t, 1}]]
returnsTrue
If I haven't made any mistakes then this might offer some support that the hand solution is correct. $\endgroup$ – Bill Jan 8 at 8:20