m4354_wave_eq_examples.mw

 

Some Examples Using Maple to Solve the Wave Equation 

 

Example 1 Wave Equation Dirichlet Conditions 

 

Assignment of system parameters  

 

> restart:
 

> L:=Pi; c:=1;
 

 

Pi
1
 

> with(plots):
 

>
 

These notes are concerned with solving the heat equation using Fourier's method 


 

First we consider Dirichlet boundary conditions:   

u(0, t) = 0; 1u(L, t) = 0 

 

 

>
 

In this case we obtain the following eigenvalues and orthonormal eigenfunctions.  

 

 

 

> mu[n]:=(n*Pi/L); lambda[n]:=-mu[n]^2;
 

 

n
`+`(`-`(`*`(`^`(n, 2))))
 

>
 

for n = 1, 2, 3, ...   Orthonormal eigenfunctions 

 

 

> X[n](x):=sqrt(2/L)*sin(n*Pi/L*x);X[m](x):=subs(n=m,X[n](x)):
 

 

`/`(`*`(`^`(2, `/`(1, 2)), `*`(sin(`*`(n, `*`(x))))), `*`(`^`(Pi, `/`(1, 2))))
 

>
 

Statement of orthonormality  

 

 

> Int(X[n](x)*X[m](x),x=0...L)=delta(n,m);
 

 

Int(`+`(`/`(`*`(2, `*`(sin(`*`(n, `*`(x))), `*`(sin(`*`(m, `*`(x)))))), `*`(Pi))), x = 0 .. Pi) = delta(n, m)
 

Time-dependent solution  

 

 

> T[n](t):=a(n)*cos(c*mu[n]*t)+b(n)*sin(c*mu[n]*t);
 

`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t))))))
 

>
 

> u[n](x,t):=T[n](t)*X[n](x);
 

`/`(`*`(`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t)))))), `*`(`^`(2, `/`(1, 2)), `*`(sin(`*`(n, `*`(x)))))), `*`(`^`(Pi, `/`(1, 2))))
 

>
 

>
 

Eigenfunction expansion  

 

 

> u(x,t):=Sum(u[n](x,t),n=1..infinity);
 

Sum(`/`(`*`(`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t)))))), `*`(`^`(2, `/`(1, 2)), `*`(sin(`*`(n, `*`(x)))))), `*`(`^`(Pi, `/`(1, 2)))), n = 1 .. infinity)
 

 

Evaluation of Fourier coefficients for the specific initial condition  

 

> f(x):=x*(Pi-x);
 

`*`(x, `*`(`+`(Pi, `-`(x))))
 

 

> a(n):=Int(f(x)*X[n](x),x=0..L);a(n):=expand(value(%)):
 

 

Int(`/`(`*`(x, `*`(`+`(Pi, `-`(x)), `*`(`^`(2, `/`(1, 2)), `*`(sin(`*`(n, `*`(x))))))), `*`(`^`(Pi, `/`(1, 2)))), x = 0 .. Pi)
 

>
 

>
 

 

> a(n):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},a(n)));
 

 

`+`(`-`(`/`(`*`(2, `*`(`^`(2, `/`(1, 2)), `*`(`+`(`-`(1), `^`(-1, n))))), `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(n, 3))))))
 

> g(x):=x^2*(Pi-x);
 

`*`(`^`(x, 2), `*`(`+`(Pi, `-`(x))))
 

> b(n):=1/(mu[n]*c)*Int(g(x)*X[n](x),x=0..L);b(n):=expand(value(%)):
 

 

`/`(`*`(Int(`/`(`*`(`^`(x, 2), `*`(`+`(Pi, `-`(x)), `*`(`^`(2, `/`(1, 2)), `*`(sin(`*`(n, `*`(x))))))), `*`(`^`(Pi, `/`(1, 2)))), x = 0 .. Pi)), `*`(n))
 

 

> b(n):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},b(n)));
 

`+`(`-`(`/`(`*`(2, `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(2, `/`(1, 2)), `*`(`+`(1, `*`(2, `*`(`^`(-1, n)))))))), `*`(`^`(n, 4)))))
 

>
 

>
 

>
 

>
 

Check Fourier coefficients  

 

 

> plot({f(x),sum(a(n)*X[n](x),n=1..3)},x=0..L);
 

Plot_2d
 

>
 

>
 

> plot({g(x),sum(mu[n]*c*b(n)*X[n](x),n=1..5)},x=0..L);
 

Plot_2d
 

>
 

>
 

 

Our simple solutions 

 

> u[n](x,t):=eval(T[n](t)*X[n](x));
 

`/`(`*`(`+`(`-`(`/`(`*`(2, `*`(`^`(2, `/`(1, 2)), `*`(`+`(`-`(1), `^`(-1, n)), `*`(cos(`*`(n, `*`(t))))))), `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(n, 3))))), `-`(`/`(`*`(2, `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(2,...
 

 

Series solution 

 

> u(x,t):=Sum(u[n](x,t),n=1..infinity);
 

 

Sum(`/`(`*`(`+`(`-`(`/`(`*`(2, `*`(`^`(2, `/`(1, 2)), `*`(`+`(`-`(1), `^`(-1, n)), `*`(cos(`*`(n, `*`(t))))))), `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(n, 3))))), `-`(`/`(`*`(2, `*`(`^`(Pi, `/`(1, 2)), `*`(`^...
 

 

First few terms of sum 

 

> u(x,t):=sum(u[n](x,t),n=1..3);
 

 

`+`(`/`(`*`(`+`(`/`(`*`(4, `*`(`^`(2, `/`(1, 2)), `*`(cos(t)))), `*`(`^`(Pi, `/`(1, 2)))), `*`(2, `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(2, `/`(1, 2)), `*`(sin(t)))))), `*`(`^`(2, `/`(1, 2)), `*`(sin(x)))), ...
`+`(`/`(`*`(`+`(`/`(`*`(4, `*`(`^`(2, `/`(1, 2)), `*`(cos(t)))), `*`(`^`(Pi, `/`(1, 2)))), `*`(2, `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(2, `/`(1, 2)), `*`(sin(t)))))), `*`(`^`(2, `/`(1, 2)), `*`(sin(x)))), ...
 

Animation 

 

> animate(plot,[u(x,t),x=0..L],t=0..15,color=red,thickness=3);
 

 

 

 

Plot_2d
 

>
 

 

 

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)):
 

> u(x,4):=subs(t=4,u(x,t)):u(x,5):=subs(t=5,u(x,t)):
 

> plot({u(x,0),u(x,1),u(x,2),u(x,3),u(x,4),u(x,5)},x=0..L,thickness=3);
 

Plot_2d
 

> plot3d(u(x,t),x=0..L,t=0..5,axes=boxed);
 

Plot_2d
 

>
 

 

Example 2 Wave Equation Neumann Conditions 

 

Assignment of system parameters  

 

> restart:
 

> L:=Pi; c:=1;
 

 

Pi
1
 

> with(plots):
 

In this section  we consider Neumann  boundary conditions:   

u_x(0, t) = 0; 1u_x(L, t) = 0 

>
 

>
 

In this case the eigenvalues and orthonormal eigenfunctions are given by 

 

 

> mu[n]:=(n*Pi/L); lambda[n]:=-mu[n]^2; lambda[0]:=0;
 

 

 

n
`+`(`-`(`*`(`^`(n, 2))))
0
 

>
 

for n = 1, 2, 3, ...   Orthonormal eigenfunctions 

 

 

> X[n](x):=sqrt(2/L)*cos(n*Pi/L*x);X[m](x):=subs(n=m,X[n](x)):
 

 

`/`(`*`(`^`(2, `/`(1, 2)), `*`(cos(`*`(n, `*`(x))))), `*`(`^`(Pi, `/`(1, 2))))
 

> X[0](x):=1/sqrt(L);
 

`/`(1, `*`(`^`(Pi, `/`(1, 2))))
 

Statement of orthonormality  

 

> Int(X[n](x)*X[m](x),x=0...L)=delta(n,m);
 

 

Int(`+`(`/`(`*`(2, `*`(cos(`*`(n, `*`(x))), `*`(cos(`*`(m, `*`(x)))))), `*`(Pi))), x = 0 .. Pi) = delta(n, m)
 

Time-dependent solution  

 

 

> T[n](t):=a(n)*cos(c*n*t)+b(n)*sin(c*n*t);
 

`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t))))))
 

>
 

> u[n](x,t):=T[n](t)*X[n](x);
 

`/`(`*`(`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t)))))), `*`(`^`(2, `/`(1, 2)), `*`(cos(`*`(n, `*`(x)))))), `*`(`^`(Pi, `/`(1, 2))))
 

> u[0](x,t):=(a(0)+b(0)*t)/2*X[0](x);
 

`+`(`/`(`*`(`/`(1, 2), `*`(`+`(a(0), `*`(b(0), `*`(t))))), `*`(`^`(Pi, `/`(1, 2)))))
 

>
 

Eigenfunction expansion  

 

 

> u(x,t):=u[0](x,t)+Sum(u[n](x,t),n=1..infinity);
 

`+`(`/`(`*`(`/`(1, 2), `*`(`+`(a(0), `*`(b(0), `*`(t))))), `*`(`^`(Pi, `/`(1, 2)))), Sum(`/`(`*`(`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t)))))), `*`(`^`(2, `/`(1, 2)), `...
 

 

Evaluation of Fourier coefficients for the specific initial condition  

 

> f(x):=x*(Pi-x);
 

`*`(x, `*`(`+`(Pi, `-`(x))))
 

>
 

> a(0):=Int(f(x)*X[0](x) ,x=0..L);a(0):=expand(value(%)):
 

Int(`/`(`*`(x, `*`(`+`(Pi, `-`(x)))), `*`(`^`(Pi, `/`(1, 2)))), x = 0 .. Pi)
 

> a(0):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},a(0)));
 

`+`(`*`(`/`(1, 6), `*`(`^`(Pi, `/`(5, 2)))))
 

 

> a(n):=Int(f(x)*X[n](x),x=0..L);a(n):=expand(value(%)):
 

 

Int(`/`(`*`(x, `*`(`+`(Pi, `-`(x)), `*`(`^`(2, `/`(1, 2)), `*`(cos(`*`(n, `*`(x))))))), `*`(`^`(Pi, `/`(1, 2)))), x = 0 .. Pi)
 

 

> a(n):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},a(n)));
 

 

`/`(`*`(`+`(`-`(1), `-`(`^`(-1, n))), `*`(`^`(Pi, `/`(1, 2)), `*`(`^`(2, `/`(1, 2))))), `*`(`^`(n, 2)))
 

>
 

Check Fourier coefficients  

 

 

> plot({f(x), a(0)*X[0](x)+sum(a(n)*X[n](x),n=1..7)},x=0..L);
 

Plot_2d
 

>
 

> g(x) := 0;
 

0
 

>
 

> b(0):=Int(g(x)*X[0](x),x=0..L);b(0):=expand(value(%)):
 

Int(0, x = 0 .. Pi)
 

> b(0):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},b(0)));
 

0
 

>
 

> b(n):=Int(g(x)*X[n](x),x=0..L);b(n):=expand(value(%)):
 

Int(0, x = 0 .. Pi)
 

> b(n):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},b(n)));
 

0
 

>
 

>
 

Check Fourier coefficients  

 

 

> plot({g(x), b(0)*X[0](x)+sum(b(n)*X[n](x),n=1..7)},x=0..L);
 

Plot_2d
 

>
 

 

Our simple solutions 

 

> u[n](x,t):=eval(T[n](t)*X[n](x));
 

`+`(`/`(`*`(2, `*`(`+`(`-`(1), `-`(`^`(-1, n))), `*`(cos(`*`(n, `*`(t))), `*`(cos(`*`(n, `*`(x))))))), `*`(`^`(n, 2))))
 

> u[0](x,t):=(a(0)+b(0)*t)/2*X[0](x);
 

`+`(`*`(`/`(1, 12), `*`(`^`(Pi, 2))))
 

 

Series solution 

 

> u(x,t):=u[0](x,t)+Sum(u[n](x,t),n=0..infinity);
 

 

`+`(`*`(`/`(1, 12), `*`(`^`(Pi, 2))), Sum(`+`(`/`(`*`(2, `*`(`+`(`-`(1), `-`(`^`(-1, n))), `*`(cos(`*`(n, `*`(t))), `*`(cos(`*`(n, `*`(x))))))), `*`(`^`(n, 2)))), n = 0 .. infinity))
 

 

First few terms of sum 

 

> u(x,t):=u[0](x,t)+sum(u[n](x,t),n=1..3);
 

 

`+`(`*`(`/`(1, 12), `*`(`^`(Pi, 2))), `-`(`*`(cos(`+`(`*`(2, `*`(t)))), `*`(cos(`+`(`*`(2, `*`(x))))))))
 

Animation 

 

> animate(plot,[u(x,t),x=0..L],t=0..15,color=red,thickness=3);
 

 

 

 

Plot_2d
 

 

 

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)):
 

> u(x,4):=subs(t=4,u(x,t)):u(x,5):=subs(t=5,u(x,t)):
 

> plot({u(x,0),u(x,1),u(x,2),u(x,3),u(x,4),u(x,5)},x=0..L,thickness=3);
 

Plot_2d
 

> plot3d(u(x,t),x=0..L,t=0..5,axes=boxed);
 

Plot_2d
 

>
 

 

Example 3 Wave Equation Dirichlet-Neumann Conditions 

 

Assignment of system parameters  

 

> restart:
 

> L:=1; c:=1;
 

 

1
1
 

> with(plots):
 

>
 

In this section  we consider Dirchlet and Neumann  boundary conditions:   

u(0, t) = 0; 1u_x(L, t) = 0 

>
 

>
 

In this case the eigenvalues and orthonormal eigenfunctions are given by  

 

 

 

> mu[n]:=((2*n-1)*Pi/(2*L)); lambda[n]:=-mu[n]^2;
 

 

`+`(`*`(`/`(1, 2), `*`(`+`(`*`(2, `*`(n)), `-`(1)), `*`(Pi))))
`+`(`-`(`*`(`/`(1, 4), `*`(`^`(`+`(`*`(2, `*`(n)), `-`(1)), 2), `*`(`^`(Pi, 2))))))
 

>
 

for n = 1, 2, 3, ...   Orthonormal eigenfunctions 

 

 

> X[n](x):=sqrt(2/L)*sin(mu[n]*x);X[m](x):=subs(n=m,X[n](x)):
 

 

`*`(`^`(2, `/`(1, 2)), `*`(sin(`+`(`*`(`/`(1, 2), `*`(`+`(`*`(2, `*`(n)), `-`(1)), `*`(Pi, `*`(x))))))))
 

>
 

Statement of orthonormality  

 

 

 

 

 

> Int(X[n](x)*X[m](x),x=0...L)=delta(n,m);
 

 

Int(`+`(`*`(2, `*`(sin(`+`(`*`(`/`(1, 2), `*`(`+`(`*`(2, `*`(n)), `-`(1)), `*`(Pi, `*`(x)))))), `*`(sin(`+`(`*`(`/`(1, 2), `*`(`+`(`*`(2, `*`(m)), `-`(1)), `*`(Pi, `*`(x)))))))))), x = 0 .. 1) = delta...
 

> radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},int(X[n](x)^2,x=0..L)));
 

1
 

Time-dependent solution  

 

 

> T[n](t):=a(n)*cos(c*n*t)+b(n)*sin(c*n*t);
 

`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t))))))
 

>
 

> u[n](x,t):=T[n](t)*X[n](x);
 

`*`(`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t)))))), `*`(`^`(2, `/`(1, 2)), `*`(sin(`+`(`*`(`/`(1, 2), `*`(`+`(`*`(2, `*`(n)), `-`(1)), `*`(Pi, `*`(x)))))))))
 

>
 

>
 

Eigenfunction expansion  

 

 

> u(x,t):=Sum(u[n](x,t),n=1..infinity);
 

Sum(`*`(`+`(`*`(a(n), `*`(cos(`*`(n, `*`(t))))), `*`(b(n), `*`(sin(`*`(n, `*`(t)))))), `*`(`^`(2, `/`(1, 2)), `*`(sin(`+`(`*`(`/`(1, 2), `*`(`+`(`*`(2, `*`(n)), `-`(1)), `*`(Pi, `*`(x))))))))), n = 1 ...
 

 

Evaluation of Fourier coefficients for the specific initial condition  

 

> f(x):=x*sin(Pi*x);
 

`*`(x, `*`(sin(`*`(Pi, `*`(x)))))
 

 

> a(n):=Int(f(x)*X[n](x),x=0..L);a(n):=expand(value(%)):
 

 

Int(`*`(x, `*`(sin(`*`(Pi, `*`(x))), `*`(`^`(2, `/`(1, 2)), `*`(sin(`+`(`*`(`/`(1, 2), `*`(`+`(`*`(2, `*`(n)), `-`(1)), `*`(Pi, `*`(x)))))))))), x = 0 .. 1)
 

 

> a(n):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},a(n)));
 

 

`+`(`/`(`*`(4, `*`(`^`(2, `/`(1, 2)), `*`(`+`(`-`(`*`(8, `*`(n))), 4, `-`(`*`(3, `*`(`^`(-1, n), `*`(Pi)))), `*`(4, `*`(`^`(-1, n), `*`(`^`(n, 2), `*`(Pi)))), `-`(`*`(4, `*`(`^`(-1, n), `*`(n, `*`(Pi)...
 

>
 

Check Fourier coefficients  

 

 

> plot({f(x),sum(a(n)*X[n](x),n=1..5)},x=0..L);
 

Plot_2d
 

>
 

> g(x):=0;
 

0
 

 

> b(n):=1/(n*c)*Int(g(x)*X[n](x),x=0..L);b(n):=expand(value(%)):
 

 

`/`(`*`(Int(0, x = 0 .. 1)), `*`(n))
 

 

> b(n):=radsimp(subs({sin(n*Pi)=0,cos(n*Pi)=(-1)^n},b(n)));
 

 

0
 

>
 

Check Fourier coefficients  

 

 

> plot({g(x),sum(b(n)*X[n](x),n=1..5)},x=0..L);
 

Plot_2d
 

>
 

>
 

>
 

>
 

 

Our simple solutions 

 

> u[n](x,t):=eval(T[n](t)*X[n](x));
 

`+`(`/`(`*`(8, `*`(`+`(`-`(`*`(8, `*`(n))), 4, `-`(`*`(3, `*`(`^`(-1, n), `*`(Pi)))), `*`(4, `*`(`^`(-1, n), `*`(`^`(n, 2), `*`(Pi)))), `-`(`*`(4, `*`(`^`(-1, n), `*`(n, `*`(Pi)))))), `*`(cos(`*`(n, `...
 

 

Series solution 

 

> u(x,t):=Sum(u[n](x,t),n=1..infinity);
 

 

Sum(`+`(`/`(`*`(8, `*`(`+`(`-`(`*`(8, `*`(n))), 4, `-`(`*`(3, `*`(`^`(-1, n), `*`(Pi)))), `*`(4, `*`(`^`(-1, n), `*`(`^`(n, 2), `*`(Pi)))), `-`(`*`(4, `*`(`^`(-1, n), `*`(n, `*`(Pi)))))), `*`(cos(`*`(...
 

 

First few terms of sum 

 

> u(x,t):=sum(u[n](x,t),n=1..3);
 

 

`+`(`/`(`*`(`/`(8, 9), `*`(`+`(`-`(4), `*`(3, `*`(Pi))), `*`(cos(t), `*`(sin(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(x))))))))), `*`(`^`(Pi, 2))), `/`(`*`(`/`(8, 25), `*`(`+`(`-`(12), `*`(5, `*`(Pi))), `*`(cos...
`+`(`/`(`*`(`/`(8, 9), `*`(`+`(`-`(4), `*`(3, `*`(Pi))), `*`(cos(t), `*`(sin(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(x))))))))), `*`(`^`(Pi, 2))), `/`(`*`(`/`(8, 25), `*`(`+`(`-`(12), `*`(5, `*`(Pi))), `*`(cos...
 

Animation 

 

> animate(plot,[u(x,t),x=0..L],t=0..15,color=red,thickness=3);
 

 

 

 

Plot_2d
 

 

 

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)):
 

> u(x,4):=subs(t=4,u(x,t)):u(x,5):=subs(t=5,u(x,t)):
 

> plot({u(x,0),u(x,1),u(x,2),u(x,3),u(x,4),u(x,5)},x=0..L,thickness=3);
 

Plot_2d
 

> plot3d(u(x,t),x=0..L,t=0..5,axes=boxed);
 

Plot_2d
 

>