>    # two examples plot solution of wave equation
# the initial data: u(x,0)=f(x), u_t(x,0)=g(x)  
#

>    # example 1:   f(x)=sin(2*x);  g(x)=x*cos(x);

>    L:=Pi; C:=1; T:=2*Pi; N:=20;
f:=x->sin(2*x); # f:=x->piecewise(x<1/3,3*x/10,x>1/3,3*(1-x)/20);
g:=x->x*cos(x);
for n from 1 to N do
b[n]:=(2/L)*int(f(x)*sin(n*Pi*x/L),x=0..L);
d[n]:=(2/L)*int(g(x)*sin(n*Pi*x/L),x=0..L);
end do:
L := Pi

C := 1

T := 2*Pi

N := 20

f := proc (x) options operator, arrow; sin(2*x) end proc

g := proc (x) options operator, arrow; x*cos(x) end proc

>    # solution u(x,t): click on figure, then go to "Animation" and click on "Play"

>    u:=(x,t)->sum( sin(m*Pi*x/L)*(b[m]*cos(m*Pi*C*t/L) + (L*d[m]/(m*Pi*C))*sin(m*Pi*C*t/L) ), m=1..N);
with(plots): animate( u(x,t), x=0..L, t=0..T, frames=50);

u := proc (x, t) options operator, arrow; sum(sin(m*Pi*x/L)*(b[m]*cos(m*Pi*C*t/L)+L*d[m]/m/Pi/C*sin(m*Pi*C*t/L)),m = 1 .. N) end proc

[Maple Plot]

>   

>    # example 2:

>    # the example plots solution of wave equation
# the initial data: u(x,0)=f(x), u_t(x,0)=g(x)  
#
L:=Pi; C:=1; T:=2*Pi; N:=20;
f:=x->piecewise(x<1/3,3*x/10,x>1/3,3*(1-x)/20);
g:=x->0; ## g:=x->x*cos(x);
for n from 1 to N do
b[n]:=(2/L)*int(f(x)*sin(n*Pi*x/L),x=0..L);
d[n]:=(2/L)*int(g(x)*sin(n*Pi*x/L),x=0..L);
end do:
u:=(x,t)->sum( sin(m*Pi*x/L)*(b[m]*cos(m*Pi*C*t/L) + (L*d[m]/(m*Pi*C))*sin(m*Pi*C*t/L) ), m=1..N);
with(plots): animate( u(x,t), x=0..L, t=0..T, frames=50);

L := Pi

C := 1

T := 2*Pi

N := 20

f := proc (x) options operator, arrow; piecewise(x < 1/3,3/10*x,1/3 < x,3/20-3/20*x) end proc

g := 0

u := proc (x, t) options operator, arrow; sum(sin(m*Pi*x/L)*(b[m]*cos(m*Pi*C*t/L)+L*d[m]/m/Pi/C*sin(m*Pi*C*t/L)),m = 1 .. N) end proc

[Maple Plot]

>