Solve
Initial conditions
Boundary conditions
Let
The solution is
Substituting the above in (1) gives
With boundary conditions
Substituting this into (3) gives
Expanding
Applying orthogonality
But
But
Therefore
This is an ODE in
From (3A)
To find
Hence
Therefore (5) becomes
And since
To simulate
ClearAll[t, x, n] k = 1; L0 = 5; max = 400; u[x_, t_] = Sum[(((2*L0^2*(k*n^2*Pi^2))/(n*Pi*(L0^4 + k^2*n^4*Pi^4)))* Exp[(-k)*((n^2*Pi^2)/L0^2)*t] - (2*L0^2*(k*n^2*Pi^2*Cos[t] + L0^2*Sin[t]))/(n* Pi*(L0^4 + k^2*Pi^4*n^4)))*Sin[((n*Pi)/L0)*x], {n, 1, max}] + ((L0 - x)/L0)*Sin[t]; Manipulate[Grid[{{"Analytical solution"}, {Plot[Evaluate[u[x,t]],{x,0,5},PlotRange->{{0,5},{-1.1,1.1}}, ImageSize->400]}}], {{t,0,"t"},0,100,.01} ]
Here is the animation from the above
![]() |
Here is the numerical solution to compare with
ClearAll["Global`*"]; pdeset = {Derivative[1, 0][U][t, x] == Derivative[0, 2][U][t, x]} ics = {U[0, x] == 0}; bcs = {U[t, 0] == Sin[t], U[t, 5] == 0}; ibcAll = {ics, bcs}; numericalSol = NDSolve[{pdeset, ibcAll}, U, {t, 0, 100}, {x, 0, 5}]; Manipulate[Grid[{{"Numerical solution"}, {Plot[Evaluate[U[t, x] /. numericalSol], {x, 0, 5}, PlotRange -> {{0, 5}, {-1, 1}}, ImageSize -> 400]}}], {{t, 0, "t"}, 0, 100, .01} ]
Here is the animation from the above
![]() |
Reference: stokes second problem question and answer