L-34 MCS 494 Wednesday 13 November 2002

> restart;

Partial Differential Equations in Maple

The command to solve PDEs in Maple is pdsolve . Maple offers some tools to handle PDEs in the package PDEtools :

> with(PDEtools);

[PDEplot, build, casesplit, charstrip, dchange, dco...

In this worksheet we illustrate the command pdsolve and some of these tools.

Plotting a wave

The command PDEplot from PDEtools can handle first-order PDEs.

The first PDE we encountered provided a simplistic model for air quality. It occurs in our textbook on page 218 and has applications to traffic flow.

> wave := diff(u(x,t),t) + diff(u(x,t),x) = 0;

wave := diff(u(x,t),t)+diff(u(x,t),x) = 0

At the beginnin of time, we consider the wave 1-x^4 over the interval [-1,1]. We plot for (x,t) in [-1,3]x[0,2].

> PDEplot(wave,[s,0,1-s^4],s=-1..1,x=-1..3,t=0..2,animate=true);

[Maple Plot]

Notice that in the command above we invoked the animate flag. If we click on the picture and then on the animation toolbar above to start the animation we see the initial wave flowing over the surface. The following two instructions create an animation which shows the build up of the surface:

> frames := seq(PDEplot(wave,[s,0,1-s^4],s=-1..1,x=-1..3,t=0..k/20),k=1..20):

> plots[display](frames,insequence=true);

[Maple Plot]

Unfortunately, this PDEplot only works for first-order PDEs and not for second-order PDEs like the heat equation.

Solving the heat equation

When calling pdsolve on a PDE, Maple attempts to separate the variables.

Consider the heat equation, to model the change of temperature in a rod.

> heat := diff(u(x,t),t) = diff(u(x,t),x$2);

heat := diff(u(x,t),t) = diff(u(x,t),`$`(x,2))

The Maple command to solve PDEs is pdsolve:

> ans := pdsolve(heat,u(x,t));

ans := `&where`(u(x,t) = _F1(x)*_F2(t),[{diff(_F2(t...

We see that Maple proposes the separation of variables and presents the decoupled ODEs. It is not so hard to select the ODEs:

> ode1 := op([2,1,1],ans);

ode1 := diff(_F2(t),t) = _c[1]*_F2(t)

> ode2 := op([2,1,2],ans);

ode2 := diff(_F1(x),`$`(x,2)) = _c[1]*_F1(x)

We can now solve the ODEs:

> f1 := op(2,rhs(ode1));

f1 := _F2(t)

> sol1 := dsolve(ode1,f1);

sol1 := _F2(t) = _C1*exp(_c[1]*t)

> f2 := op(2,rhs(ode2));

f2 := _F1(x)

> sol2 := dsolve(ode2,f2);

sol2 := _F1(x) = _C1*exp(sqrt(_c[1])*x)+_C2*exp(-sq...

> sol := rhs(sol1)*rhs(sol2);

sol := _C1*exp(_c[1]*t)*(_C1*exp(sqrt(_c[1])*x)+_C2...

Let us use the boundary and initial conditions:

> conds := u(0,t) = 0, u(1,t) = 0, u(x,0) = 1;

conds := u(0,t) = 0, u(1,t) = 0, u(x,0) = 1

> pde := [heat,conds];

pde := [diff(u(x,t),t) = diff(u(x,t),`$`(x,2)), u(0...

> pdsolve(pde,u(x,t));

{u(x,t) = _C3*exp(_c[1]*t)*_C1*exp(sqrt(_c[1])*x)+_...

We recognize the solution we derived in class, but apparently Maple is unable to take advantage of the conditions to arrive at the series solution we obtained on Monday.

Let us try to apply the fourier transforms, abbreviated as ft and ift:

> alias(ft = inttrans[fourier]):

> alias(ift = inttrans[fourier]):

First we apply the Fourier transform with respect to the space coordinate:

> ft_heat_x := ft(heat,x,omega);

ft_heat_x := diff(fourier(u(x,t),x,omega),t) = -ome...

> ode := subs(fourier(u(x,t),x,omega) = U(t), ft_heat_x);

ode := diff(U(t),t) = -omega^2*U(t)

> sol_t := dsolve(ode, U(t));

sol_t := U(t) = _C1*exp(-omega^2*t)

We must assume time is positive, otherwise Maple cannot determine whether the integral converges or not:

> assume(t>0);

> uf := ift(rhs(sol_t),omega,x);

uf := _C1*sqrt(Pi/t)*exp(-1/4*x^2/t)

> u1 := subs(_C1=1,uf);

u1 := sqrt(Pi/t)*exp(-1/4*x^2/t)

> plot3d(u1,x=0..1,t=0..20,axes=boxed);

[Maple Plot]

Note that this is a solution of the heat equation as an initial value problem. We have to separate variables to solve the equation with boundary conditions.

> t := 't': # remove the assumption on t

Change of Coordinates

With dchange of PDEtools we can change coordinates easily:

> LaplacePDE := diff(F(x,y),x$2) + diff(F(x,y),y$2) = 0;

LaplacePDE := diff(F(x,y),`$`(x,2))+diff(F(x,y),`$`...

Let us change to polar coordinates:

> polar_PDE := dchange({x=r*cos(phi),y=r*sin(phi)},LaplacePDE);

polar_PDE := (2*sin(phi)*cos(phi)*diff(F(phi,r),phi...
polar_PDE := (2*sin(phi)*cos(phi)*diff(F(phi,r),phi...
polar_PDE := (2*sin(phi)*cos(phi)*diff(F(phi,r),phi...

taking the numerator simplifies the equation a lot:

> numer(lhs(polar_PDE)) = 0;

diff(F(phi,r),`$`(phi,2))+diff(F(phi,r),r)*r+diff(F...

We encounter the Laplacian when studying the vibrations of a circular drum (see Problem 5 on page 204 of the textbook):

> drum := subs(F(phi,r) = u(r,phi,t),numer(lhs(polar_PDE)));

drum := diff(u(r,phi,t),`$`(phi,2))+diff(u(r,phi,t)...

Just as in the textbook, we are going to assume that we strike the drum at the very center so that the vibration is radially symmetric and we can ignore the angle phi.

> drum := subs(diff(u(r,phi,t),phi$2) = 0,drum);

drum := diff(u(r,phi,t),r)*r+diff(u(r,phi,t),`$`(r,...

> drum := normal(drum/r) = diff(u(r,phi,t),t);

drum := diff(u(r,phi,t),r)+diff(u(r,phi,t),`$`(r,2)...

> ans := pdsolve(drum,u(r,phi,t));

ans := `&where`(u(r,phi,t) = _F1(r)*_F3(t)*_F0(phi)...
ans := `&where`(u(r,phi,t) = _F1(r)*_F3(t)*_F0(phi)...

The equation in r is interesting as it leads to Bessel's equation:

> ode_r := op([2,1,3],ans);

ode_r := diff(_F1(r),`$`(r,2)) = _F1(r)/r*_c[1]-dif...

Careful here: if you execute the above command, the interesting ODE in r may be at a different location...

> n_ode_r := normal(r^2*ode_r);

n_ode_r := r^2*diff(_F1(r),`$`(r,2)) = r*(_c[1]*_F1...

We need to suggest the right type of constant to arrive at the Bessel equation:

> bessel := subs(_c[1] = -1,_F1(r)=y(r),n_ode_r);

bessel := r^2*diff(y(r),`$`(r,2)) = r*(-y(r)-diff(y...

> b_sol := dsolve(bessel,y(r));

b_sol := y(r) = _C1*BesselJ(0,2*sqrt(r))+_C2*Bessel...

> j0 := rhs(subs(_C1 = 0,_C2 = 1,b_sol));

j0 := BesselY(0,2*sqrt(r))

> plot(j0,r=0..20);

[Maple Plot]

So we can think of the solution to the Bessel equation as a damped cosine.

>