
Nonhomogeneous Partial Differential Equations 527
The integrals for C(n) and D(n) are
> C(n):=Int((f(x)−s(x,0))*X[n](x),x=0..a);C(n):=expand(value(%)):
C(n) :=
1
0
0dx (8.107)
> C(n):=simplify(subs({sin(n*Pi)=0,cos(n*Pi)=(−1)ˆn},C(n)));
C(n) := 0 (8.108)
> D(n):=Int((g(x)−s[t](x,0))/(c*n*Pi/a)*X[n](x),x=0..a);D(n):=expand(value(%)):
D(n) :=
1
0
2(−1 +x)
√
2 sin(nπx)
nπ
dx (8.109)
> D(n):=simplify(subs({sin(n*Pi)=0,cos(n*Pi)=(−1)ˆn},D(n)));
D(n) := −
2
√
2
n
2
π
2
(8.110)
for n = 1, 2, 3,....
Final solution (linear plus variable portion)
> u(x,t):=simplify(Sum(eval(v[n](x,t)),n=1..infinity))+s(x,t);
u(x, t) :=
∞
n=1
4
−sin
1
2
nπt
nπ +2 sin(t)
sin(nπx)
nπ
n
2
π
2
−4
−sin(t)x +sin(t) (8.111)
First few terms of sum
> u(x,t):=simplify(sum(eval(v[n](x,t)),n=1..3)+s(x,t)):
ANIMATION
> animate(u(x,t),x=0..a,t=0..5,thickness=3);
The preceding animation command displays the spatial-time-dependent solution of u(x, t) for
the given boundary conditions and initial conditions. The animation sequence here and in
Figure 8.6 shows snapshots of the animation at times t = 0, 1, 2, 3, 4, 5. Note how the solution
satisfies the given boundary and initial conditions.
ANIMATION SEQUENCE
> u(x,0):=subs(t=0,u(x,t)):u(x,1):=subs(t=1,u(x,t)):
> u(x,2):=subs(t=2,u(x,t)):u(x,3):=subs(t=3,u(x,t)):