Application Center - Maplesoft

App Preview:

PDE Boundary Value Problems Solved Numerically with pdsolve

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Numerical Solutions to PDE Boundary Value Problems in Maple 8

Copyright 2002 Waterloo Maple Inc.

Maple 8 can now compute numerical solutions to linear PDE systems over rectangular regions.  One application of this feature is the solution of classical boundary-value problems from physics, such as the heat conduction equation and the wave equation.

Example 1: Heat flow in a rod

Let's compute the temperature u(x,t)  over a rod, where t is time and x  is distance along the rod. We assume the ends of the rod maintain a constant temperature.  For each instance of the problem, we must specify the initial heat distribution g(x)  and the thermal diffusivity alpha  of the rod.  

We use the time-dependent, one-dimensional heat equation in cartesian coordinates:

diff(u(x,t),t) = alpha*diff(u(x,t),`$`(x,2)) ,

subject to the boundary conditions

u(0,t) = 0 ,
u(1,t) = 0 , and

u(x,0) = g(x)

The Laplacian  function in Maple 8's new VectorCalculus  package is useful for writing down 2nd-order PDEs, so we first load that package.

>    with(VectorCalculus);

Warning, the assigned names <,> and <|> now have a global binding

Warning, these protected names have been redefined and unprotected: *, +, ., Vector, diff, int, limit, series

[`&x`, `*`, `+`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProduct, Curl, Curvature, Del, DirectionalDiff, Divergence, DotProduct, Flux, GetCoordinateParameters, GetCoor...
[`&x`, `*`, `+`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProduct, Curl, Curvature, Del, DirectionalDiff, Divergence, DotProduct, Flux, GetCoordinateParameters, GetCoor...
[`&x`, `*`, `+`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProduct, Curl, Curvature, Del, DirectionalDiff, Divergence, DotProduct, Flux, GetCoordinateParameters, GetCoor...
[`&x`, `*`, `+`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProduct, Curl, Curvature, Del, DirectionalDiff, Divergence, DotProduct, Flux, GetCoordinateParameters, GetCoor...

We write down the heat equation using the Laplacian  function. We assume alpha = 1/10

>    Heat_Eqn := { diff( u(x,t), t) = Laplacian( u(x,t), 'cartesian'[x]) / 10 };

Heat_Eqn := {diff(u(x,t),t) = 1/10*diff(u(x,t),`$`(x,2))}

Next we write down the boundary conditions:  The ends of the rod are kept at a constant temperature (0), and we assume the initial temperature distribution is g(x) = (1-x)*(1-exp(-50*x))

>    BCs:={u(x,0) = (1-x)*(1-exp(-50*x)), u(0,t) = 0, u(1,t) = 0};

BCs := {u(0,t) = 0, u(1,t) = 0, u(x,0) = (-x+1)*(-exp(-50*x)+1)}

Now we solve the PDE boundary-value problem numerically with the pdsolve  command and numeric  option specified.  We can set the accuracy of the solution by specifying the time step and space step of the discretization over the distance-time rectangle.  

>    Heat_Solution := pdsolve( Heat_Eqn, BCs, numeric, timestep=1/100, spacestep=1/100);

Heat_Solution := module () local INFO; export plot, plot3d, animate, value, settings; option `Copyright (c) 2001 by Waterloo Maple Inc. All rights reserved.`; end module

Note that Maple delivered the solution as a Maple module.  The module provides functions for viewing the solution as plots ( plot  and plot3d ), animations over time ( animate ) and numerical values ( value ).

Here's an animation of the temperature distribution

>    Heat_Solution :- animate( u(x,t) ,t=0..1.5, frames=80, labels=["x", "u(x,t)"], labelfont=[TIMES,ROMAN,14]);

[Maple Plot]

And a plot of the solution space.

>    Heat_Solution :- plot3d(u(x,t), t=0..2, shading=zhue, axes=boxed, labels=["x","t","u(x,t)"], labelfont=[TIMES,ROMAN,16]);

[Maple Plot]

To get numerical values, we can create a procedure using the value  procedure from the solution's module.

>    RodTemperature := Heat_Solution :- value();

RodTemperature := proc () local tv, xv, solnproc, stype, ndsol, vals, dvarn, i; option `Copyright (c) 2001 by Waterloo Maple Inc. All rights reserved.`; Digits := trunc(evalhf(Digits)); solnproc := pro...

The temperature at x = .5 , t = 3

>    RodTemperature( .5, 3 );

[x = .5, t = 3., u(x,t) = .328426142599065954e-1]

Let's model a more complicated physical system.  Here the right end of the rod is more dissipative than the left, and the rod's dissipativity decreases with time.

>    Heat_Eqn := {diff(u(x,t),t)=exp(-2*t)*(0.01+5*x)/10*diff(u(x,t),x,x)};

Heat_Eqn := {diff(u(x,t),t) = 1/10*exp(-2*t)*(5*x+.1e-1)*diff(u(x,t),`$`(x,2))}

>    BCs:={u(x,0)=sin(Pi*x), u(0,t)=0, u(1,t)=0};

BCs := {u(x,0) = sin(Pi*x), u(0,t) = 0, u(1,t) = 0}

>    Heat_Solution := pdsolve( Heat_Eqn, BCs, numeric, timestep=1/100, spacestep=1/100);

Heat_Solution := module () local INFO; export plot, plot3d, animate, value, settings; option `Copyright (c) 2001 by Waterloo Maple Inc. All rights reserved.`; INFO := INFO; plot := proc () if nargs = 0...

>    Heat_Solution :- animate( u(x,t) ,t=0..3.5, frames=50, labels=["x", "u(x,t)"], labelfont=[TIMES,ROMAN,14]);

[Maple Plot]

>   

Example 2: Vibration of a cord

Let's compute the vertical displacement u(x,t)  of a cord with length 1 and fixed endpoints, where t is time and x  is distance along the cord. For each instance of the problem, we must specify the initial displacement of the cord g(x) , the initial speed of the cord f(x)  and the horizontal wave speed c.

We use the one-dimensional wave equation in cartesian coordinates:

diff(u(x,t),`$`(t,2)) = diff(u(x,t),`$`(x,2))/(c^2) ,

subject to the boundary conditions

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

u(x,0) = g(x) , and

diff(u(x,0),t) = f(x)

We write down the wave equation using the Laplacian  function with c = sqrt(10) .

>    Cord_Eqn := { diff( u(x,t), t, t) = Laplacian( u(x,t), 'cartesian'[x])/10 };

Cord_Eqn := {diff(u(x,t),`$`(t,2)) = 1/10*diff(u(x,t),`$`(x,2))}

We specifiy that the cord is fixed at both ends and has 0 initial speed.

>    BC1 := {u(0,t) = 0, u(1,t) = 0, D[2](u)(x,0)=0};

BC1 := {D[2](u)(x,0) = 0, u(0,t) = 0, u(1,t) = 0}

Case 1:  Cord is plucked from the center

>    BC2 := {u(x,0)=piecewise( x >= 0 and x <= 1/2, x, x > 1/2 and x <= 1, 1-x)};

BC2 := {u(x,0) = PIECEWISE([x, -x <= 0 and x-1/2 <= 0],[-x+1, -x < -1/2 and x-1 <= 0])}

>    sol:=pdsolve( Cord_Eqn, BC1 union BC2, numeric, spacestep=1/200, timestep=1/100):

>    sol:-animate( u(x,t) ,t=0..2*Pi, frames=30, labels=["x","u(x,t)"], labelfont=[TIMES,ROMAN,14], scaling=constrained);

[Maple Plot]

Case 2:  Cord starts in the shape of a trigonometric function

>    BC2 := {u(x,0)=sin(4*Pi*x)/2};

BC2 := {u(x,0) = 1/2*sin(4*Pi*x)}

>    sol := pdsolve( Cord_Eqn, BC1 union BC2, numeric, spacestep=1/200, timestep=1/100);

sol := module () local INFO; export plot, plot3d, animate, value, settings; option `Copyright (c) 2001 by Waterloo Maple Inc. All rights reserved.`; INFO := INFO; plot := proc () if nargs = 0 then erro...

>    sol:-animate( u(x,t), t=0..Pi/2, frames=30,
              labels=["x","u(x,t)"], labelfont=[TIMES,ROMAN,14],
              scaling=constrained);

[Maple Plot]

You can also display functions of the solution, or several functions of the solution on the same set of axes .

>    sol:-animate( [[u(x,t) + sin(120*x)/10, color=red],
               [-u(x,t)/2 + sin(120*x)/20, color=blue]], t=0..Pi/2, frames=30,
              labels=["x","u(x,t)"], labelfont=[TIMES,ROMAN,14],
              scaling=constrained);


[Maple Plot]

To learn more about Maple 8's numeric PDE solver, see the help pages at:

>    ?pdsolve, numeric

>   

>