0% found this document useful (0 votes)
9 views14 pages

LM - PDE 1 - Solving Symbolic PDEs

The document provides a comprehensive guide on solving symbolic partial differential equations (PDEs) using Maple software, covering topics such as writing PDEs, using operators, and the pdsolve function. It includes examples of first and second order PDEs, conditions for solutions, and techniques for extracting and plotting solutions. Additionally, it emphasizes best practices for providing conditions and assumptions to improve computational efficiency.

Uploaded by

emad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views14 pages

LM - PDE 1 - Solving Symbolic PDEs

The document provides a comprehensive guide on solving symbolic partial differential equations (PDEs) using Maple software, covering topics such as writing PDEs, using operators, and the pdsolve function. It includes examples of first and second order PDEs, conditions for solutions, and techniques for extracting and plotting solutions. Additionally, it emphasizes best practices for providing conditions and assumptions to improve computational efficiency.

Uploaded by

emad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

LM - PDE 1 - Solving Symbolic PDEs.

mw

Learning Maple: Maximum Productivity - Minimal Coding


PDEs 1: Solving Symbolic Equations
Objective: the basics of writing and solving partial differential equations, symbolically

Recommended previously viewed videos: 1-7, Calculus 1

Topics covered
Concepts : Symbolic solution to a PDE
v v2 v2
Symbols: f , f , f
vx v x2 vxvy
Operators: D
Procedures : pdsolve set of equations, variables, options
op term number, expression

Writing PDEs
Since an partial differential equation means writing an equation with partial derivatives, here are the basics for
entering these entities.

Example: first order partial derivative equation

v v
U x, y C U y =0
vx vy

v
- Using the palette symbol: f
vx
> restart;
v v
eq_1st d U x, y C U x, y =0
vx vy
v v
eq_1st d U x, y C U x, y = 0
vx vy
- Using the diff function
> eq_1st d diff U x, y , x C diff U x, y , y = 0
v v
eq_1st d U x, y C U x, y = 0
vx vy
But note, when using either the palettes or the diff function, the function must include the differentiating variables,
else Maple will consider the function to be a constant. For example, these lines fail because Maple does not know y
is a function of x.
v v
> eq_1st d U C U = 0;
vx vy
eq1_1st d diff U, x C diff U, y = 0
eq_1st d 0 = 0
eq1_1st d 0 = 0

Page 1 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Example: second order ODE

v2 v2
- Using the palette symbol: f , f
v x2 vx vy
v2 v2 v2
> eq_2nd d U z, w C U z, w C U z, w =C
v z2 vzvw v w2
v2 v2 v2
eq_2nd d 2
U z, w C U z, w C U z, w = C
vz vwvz vw2
- Using the diff function: differentiating with respect to x twice.

> eq_2nd d diff U z, w , z, z C diff U z, w , z, w C diff U z, w , w, w = C


v2 v2 v2
eq_2nd d 2
U z, w C U z, w C U z, w = C
vz vwvz vw2

Example: nth order ODE

- Using the diff function - example n = 4.

> eq_4th d diff U x, y , x, x, x, x = U x, y ;


v4
eq_4th d U x, y = U x, y
vx4

Note, the sequence symbol $ can be used as a substitution for a sequence. For example: x$3 = x, x, x

> eq_4th d diff U x, y , x$4 = U x, y ;


v4
eq_4th d U x, y = U x, y
vx4
Or to the nth order:

> eq_nth d diff U x, y , x$n = U x, y ;


vn
eq_nth d U x, y = U x, y
vxn

Writing conditions - Using the D operator


Most of the time, writing equations for the conditions is as as one expect. For example:

> bces d U x, 0 = 0, U 0, y = a :

However, if you need to write the derivative of a function evaluated at some location, one has to use the D
operator. ( See Learning Maple - Ordinary Differential Equations - Symbolic for a discussion of the D
operator.)

In addition, one must tell the D operator which of the variables, e.g., first, second, third, etc., is going to
differentiate the function. For example:

v v
D[1] = D[2] =
v x1 v x2

Page 2 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Here are some examples of evaluating the derivative of the function at different locations using the D operator.

v
U x, y =D 1 U 0, y
vx
x = 0, y = y

v
U x, y =D 2 U x, 0
vy
x = x, y = 0

And how Maple will return the expressions:

> D 1 U 0, y ,
D 2 U x, 0
D1 U 0, y , D2 U x, 0

Symbolic pdsolve

The basic function to solve a partial differential equation is pdsolve.

pdsolve equations, variables, options

where the set of functions that Maple is solving for is optional. However, it is good practice to include them. In
addition, one can include the optional command series to generate a series solution.

Example : first order PDE of multiple dimensions with no conditions


With no initial or boundary conditions, all Maple can do is return a family (or type) of solutions

v v
> pdsolve U x, y C U x, y = 0 , U x, y
vx vy
U x, y = f1 Lx C y
The function f1 is generated by Maple.

Another example:
v v 2
> pde d U x, y C U x, y = U x, y :
vx vy
sol d pdsolve pde ;

1
sol d U x, y =
Lx C f1 Lx C y

Example: second order PDE of multiple dimensions with no conditions


With a second order PDE, two functions may be generated:
v2 2 v
> pde d y x, t C x $y x, t = L y x, t :
vx
2
vt
sol d pdsolve pde ;
d d2
sol d y x, t = f1 x f2 t where f2 t = Lf2 t _c1, 2 f1 x = _c1 f1 x L x2 f1 x
dt dx

Page 3 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

The two functions to be solved are: f1 , f2 . These functions are solved by solving the two ODEs. In addition, there is
a constant that can only be solved for with the conditions.

Another example:
v v v2
> pde d U x, y C U x, y C U x, y =0:
vx vy vxvy

sol d pdsolve pde


d d _c1 f2 y
sol d U x, y = f1 x f2 y where f1 x = _c1 f1 x , f2 y = L
dx dy _c1 C 1

Best practice : always have the solutions be assigned to a variable so that you can easily refer to the solutions
without cutting and pasting.

PDE with Conditions


If a complete set of conditions is provided, a single equation may be generated if the equation can be solved.
However, to do so, all conditions must be provided. pdsolve accepts a set of equations to evaluate.

Example: first order PDE with one condition


v v
> pde d U x, y C U x, y = 0 :
vx vy
bce d U x, 0 = C :

sol d dsolve pde, bce ;


sol d U x, y = C

Example: 2nd order ODE with two condition equations.


v v
> pde d U x, y C U x, y = 0 :
vx vy
bce d U x, 0 = C1, U 0, y = C2 :

sol d dsolve pde, bce ;

1
sol d U x, y = C2 C LC2 C C1 L L1 sy
, s, x
e s

Practice Problems
1. a) What is the function that satisfies the partial differential equation:

v
y x, t = y x, t $t2
vx

b) Will a single function be returned, or a family of functions?

Ll t2
2. Return to the previous problem. You are told that at the location x = 0, the value of y x, t is e .
Now what is y x, t ?

Page 4 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Solutions
1) a)
> restart;
v 2
pde d y x, t = k$y x, t $t :
vx
sol d pdsolve pde, y x, t ;
2x
sol d y x, t = f1 t ek t
b) This is a first order differential equation, i.e., it has only a first order derivative in it. Because no
conditions are provided, we expect a family of solutions.

2) The second equation is a boundary condition.


Ll$t2
> bce d y 0, t = e :
sol d pdsolve pde, bce , y x, t ;
2 k xLl
sol d y x, t = et

Helping Maple Solve PDEs


In solving PDEs, it is always helpful to provide information to Maple about properties of the system. What is
most common is to tell Maple to constants are positive or nonnegative. To do this, include the assume condition
in implementing the pdsolve procedure.

Consider the following example of a PDE with both boundary and initial conditions.
> restart;
v2 2 v2
pde d 2
Z x, t = c $
2
Z x, t :
vt vx
bceqs d Z 0, t = 0, Z L, t = 0 :
iceqs d Z x, 0 = Z0 x ,
D 2 Z x, 0 = 0 :
2
L
Z0 x d h$exp La$ x L :
2

Here is a call to pdsolve providing no information about the constants.


> CodeTools:-Usage pdsolve pde, iceqs, bceqs :
memory used=1.09GiB, alloc change=492.00KiB, cpu time=8.76s, real time=
9.50s, gc time=546.88ms

Here is a call to pdsolve including the assume condition.


> CodeTools:-Usage pdsolve pde, iceqs, bceqs assuming L O 0, c O 0, a O 0 :
memory used=449.85MiB, alloc change=32.00MiB, cpu time=3.77s, real
time=4.26s, gc time=328.12ms

Informing Maple about the properties of the constant cut the calculation time in half.

Page 5 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Extracting and Plotting Solutions


Obtaining a solution is wonderful. But being be able to apply it is even more useful. There are several versions of
possible solutions.

Solution with a Simple Expression


Often it is useful to extract the results of pdsolve and to either plot or check its values at different location. For
example,
> restart :
v
pde d y x, t = k$y x, t $x :
vt
ice d y x, 0 = x :

Here is the solution:


> sol d pdsolve pde, ice , y x, t ;
sol d y x, t = x ek x t
Now extract out the solution and call it ysol .
> ysol d eval y x, t , sol ;
ysol d x ek x t
And make a function out of it
> ysol d MakeFunction ysol, x, t
ysol d x, t ↦ x$ek$x$t
Now we can plot.
> plot eval ysol x, 1 , k = L1 , x = 0 ..8, 0 ..0.4
0.4

0.3

0.2

0.1

0
1 2 3 4 5 6 7 8
x

We can also check to see if the solution satisfies the initial ODE. Here we can evaluate the equation with the
condition that y x is the solution.
> pde_test d eval pde, y x, t = ysol x, t
pde_test d x2 k ek x t = x2 k ek x t

And confirming the left-hand-side of the equation is equivalent to the right-hand-side.


> is pde_test ;
true

Page 6 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Solution with a Single Summation


Some solutions contain a summation. For example:

> restart;
v v2
pde d u x, t = k$ 2
u x, t :
vt vx
2 2
ice d u x, 0 = L L x :
bces d u LL, t = 0, u L, t = 0 :

sols d pdsolve pde, ice, bces assuming positive;


k p2 n2 t
n p xCL Q
4 L2 n
N sin e Q1 L1
16 L 2
>
n =1
2L
n3
sols d u x, t = Q 3
p
Our goal is to create a function u x, t, N where u is the solution at x, t for N number of terms in the summation.

Substitution Technique
The first technique consists of simply evaluating, in the solution, infinity as a variable, N. The process is
three steps, which could be combined into a single function:

1) Extract out the solution which is the right-hand-side of the equation.

2) Evaluate the solution with the variables that the user provides in the function.

3) Either calculate the value of the result or evaluate the result as a floating point, i.e., evalf .

> sol d rhs sols :

usol c, t, N d value eval sol, N = N, x = c, t = t ;


usol d c, t, N ↦ value sol
t = t, x = c, N = N

Here is the answer using 3 terms.


> usol x, t, 3
9 k p2 t
3 p xCL Q
4 L2
k p2 t 2 sin e
2 p xCL Q
4 L2 2L
16 L Q 2 sin e L
2L 27
Q 3
p
Which, if we expand, looks like this:
> expand usol x, t, 3
k p2 t 9 k p2 t
2 px Q
4 L2 2
Q
4 L2 3px
32 L cos e 32 L e cos
2L 2L
3
L 3
p 27 p

Page 7 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Copy and Paste Technique


Another simple, but more readable solution, to create a function using copy and paste. To do so:

1) Combine all terms into a single summation.


> sols_combine d combine sols
k p2 n2 t
n p xCL Q
4 L2
N 16 L2 sin e Q1 n
L1
sols_combine d u x, t = >
n=1
Q
2L
3
p n3
2) Define usol x, t as:

N
usol x, t, N d >
n =1
f

N is the number of terms to be used in the solution since we cannot use an infinite number of terms.

3) Copy the operands (elements) of the summation into f.

k p2 n2 t
n p Lx C L L
4 L2
N 16 sin e L2 L1 n
L1
2L
> usol x, t, N d >
n =1
3
p n3
k$p2$n2$t
p$n$ Q x C L Q
4$L2
N 16$sin $e $L2$ Q1 n
L1
2$L
usol d x, t, N ↦ >
n =1
3
p $n3
With this function, we can generate a solution for N = 3 terms.
> usol x, t, 3
k p2 t 9 k p2 t
p QxCL Q
4 L2 2 3 p QxCL Q
4 L2
32 sin e L 32 sin e L2
2L 2L
Q 3
L 3
p 27 p

Improved Efficiency
One can also build an expression maker before making the function. This one takes values for k, L and the
number of terms, N. It then creates an expression with the number of terms desired. Finally, we this
expression, we create a function. The expression is made only once instead of every time the function is
called.
k p2 n2 t
n p Lx C L L
4 L2 2 n
N 16 sin e L L1 L1
2L
> uexpression k, L, N d >
n =1 p n
3 3
:

usol d uexpression k0, L0, 3 :

usol3 d MakeFunction usol, x, t ;

Page 8 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

k $p2$t 9$k $p2$t


0 0
Q Q
p$ Q x C L0 4$L 2 3$p$ Q x C L0 4$L 2
0 2 0 2
32$sin $e $L0 32$sin $e $L0
2$L0 2$L0
usol3 d x, t ↦ Q 3
L 3
p 27$p
The processes is a bit more cumbersome, but if efficiency is required, it is will help. With the speeds of
computers these days, I rarely need to resort to this type of efficiency.

Maple Code Solution


If you prefer to not copy and paste because the solution may change, you can ask Maple to extract the
operand of the solution. Here is a procedure that creates a solution for N terms given a expression at some
location and time.

> usol dproc x0, t0, N


global sols;
local s, u;

s d combine rhs sols ; # combine everthing into the summation from the solutions
s d op 1, s ; # extract out the summation expression
s d MakeFunction s, x, t, n ; # function out of position, time and index

return >
n =1
s x0, t0, n ; # add up all terms using an internal counter, n1

end proc:

Testing it for 3 terms at the location, time of x0, t0 .


> usol x0, t0, 3
k p2 t 9 k p2 t
0 0
p x0 C L Q
4 L2
3 p x0 C L Q
4 L2
32 L2 sin e 32 L2 sin e
2L 2L
3
C 3
p 27 p
This solution works well enough. But, like before, if you wish more efficiency, create an expression with the
number of terms and then build a function from the expression.

Regardless how the solution function is built, one should be able to plot and make an animation of if. Plotting the
solution for N = 20 where k = 1, L = 1 at t = 0:

> kd1 : L d1 :

plot usol x, 0, 20 , x = L1 ..1

Page 9 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

0.8

0.6

0.4

0.2

L1 L0.5 0 0.5 1
x

animating it for some period of time

> plots:-animate plot, usol x, t, 20 , x = L1 ..1 , t = 0 ..2

t = 0.00000
1

0.8

0.6

0.4

0.2

L1 L0.5 0 0.5 1
x

WARNING: Be careful though, make sure you have all terms in the summation. You may get a solution that is
part expression and part summation. For example, what if your solution looks like this:

> restart;
k p2 n2 t
n p Lx C L L
4 L2 2 n
N sin e L L1 L1
2L
A$x
16 >
n =1 n
3

sols d u x, t = L 3
:
t C1 p

The simplest technique to create a function is to use the "substitution" technique because combining the solution
isn't going to put every term within the summation. However, if you do want to build the function by hand, it is
necessary to extract out each term, one with the summation and the ones without. One can do this with copy and
paste or use the op procedure.

Page 10 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

> term1 d op 1, rhs sols ;


term2 d op 2, rhs sols ;
Ax
term1 d
t C1
k p2 n2 t
n p Lx C L L
4 L2
N sin e L2 L1 n
L1
16 >
n =1
2L
n3
term2 dL 3
p
Now, apply the technique for working with the summation on term2 .

> term2 d combine term2 :

s d op 1, term2 :
N

usum d >s :
n =1

usol d MakeFunction term1 C usum, x, t, N ;


k$p2$n2$t
n$p$ Lx C L L
4$L2
N 16$sin $e $L2$ L1 n
L1
A$x 2$L
usol d x, t, N ↦
t C1
C
n =1
L > p $n3
3

Testing the solution:


> usol X, T, 3
k p2 T 9 k p2 T
p LX C L L
4 L2 3 p LX C L L
4 L2
32 sin e L2 32 sin e L2
AX 2L 2L
C 3
C 3
T C1 p 27 p

Extracting a Double Summation Solution


Here is a hypothetical solution involving a double summation:

> restart;
N N L l C m $t
A e
sols d Z x, y, t =
lCm
$ >>
n1 = 1 n = 1 n$x
2
C n1$y
2
C1
:

The processes available for a double summation are similar to the ones for a single summation.

Substitution Technique
Swap out the variables, including infinity.
> Zsol c, y, t, N d value eval rhs sols , x = c, y = y, t = t, N = N ;
Zsol d c, y, t, N ↦ value rhs sols
t = t, x = c, y = y, N = N

Page 11 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Testing:
> Zsol x, y, t, 2
lC m t lC m t lC m t lC m t
eQ eQ eQ eQ
A C C C
x2 C y2 C 1 4 x2 C y2 C 1 x2 C 4 y2 C 1 4 x2 C 4 y2 C 1
lCm

Copy and Paste Technique


For the copy and paste technique:

1) Combine all terms.


> sols d combine sols ;
N N
lC m t
A eQ
sols d Z x, y, t = >>
n1 = 1 n = 1 lCm n2 x2 C n12 y2 C 1
2) Create a function from the sum of two counters
N N

> Zsol x, y, t, N d > >


n1 = 1 n =1
f :

3) Copy and paste in the summation expression.


N N lC m t
A eL
> Zsol x, y, t, N d > >
n1 = 1 n =1 lCm n2 x2 C n12 y2 C 1
N N l C m $t
A$eQ
Zsol d x, y, t, N ↦ >>
n1 = 1 n = 1 lCm $ n2$x2 C n12$y2 C 1
Testing
> Zsol2 d Zsol X, Y, T, 2
Q lC m T Q lC m T Q lC m T
Ae Ae Ae
Zsol2 d C C
2 2 2 2 2 2
lCm X CY C1 lCm 4 X CY C1 lCm X C4 Y C1
Q lC m T
Ae
C
2 2
lCm 4 X C4 Y C1

Improved Efficiency
Like in the previous section, if efficiency is required, you can use the function to build an expression
from which you can build a function specifically for that number of terms.
> Zsol2 d MakeFunction Zsol x, y, t, 2 , x, y, t
Q l C m $t Q l C m $t
A$e A$e
Zsol2 d x, y, t ↦ C
2 2 2 2
lCm $ y Cx C1 lCm $ 4$x C y C 1
Q l C m $t Q l C m $t
A$e A$e
C C
2 2 2 2
lCm $ x C 4$y C 1 lCm $ 4$x C 4$y C 1

Page 12 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

Maple Code Solution


If you prefer to not copy and paste because the solution may change, you can ask Maple to extract the
operand of the solution. Here is a procedure that creates an expression for N terms. It can be used to create
function.

> Zsol d proc x0, y0, t0, N


global sols;
local s, n_1, n1_1;

s d combine rhs sols ; # combine everything into the double summation

s d op 1, s ; # extract out the inner summation from the outer summation

s d op 1, s ; # extract out the summation expression from the summation

s d MakeFunction s, x, y, t, n, n1 ; # make function of key elements

N N

return > >


n =1 n1 = 1
s x0, y0, t0, n, n1 ; # create a double summation

end proc:

Testing it for 2 terms.


> Zsol X, Y, T, 2
Q lC m T Q lC m T Q lC m T
Ae Ae Ae
C C
2 2 2 2 2 2
lCm X CY C1 lCm 4 X CY C1 lCm X C4 Y C1
Q lC m T
Ae
C
2 2
lCm 4 X C4 Y C1
Which can be converted into a function
> Zsol2 d MakeFunction Zsol x, y, t, 2 , x, y, t
Q l C m $t Q l C m $t
A$e A$e
Zsol2 d x, y, t ↦ C
2 2 2 2
lCm $ y Cx C1 lCm $ 4$x C y C 1
Q l C m $t Q l C m $t
A$e A$e
C C
2 2 2 2
lCm $ x C 4$y C 1 lCm $ 4$x C 4$y C 1

From the solution, results can be plotted or animated:


> A d 0.01 : l d 0.1 : m d 0.1 :
Ld2:

Page 13 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw

> plot3d Zsol x, y, 0, 20 , x = LL ..L, y = LL ..L,


size = 500, 500

> plots:-animate plot3d, Zsol x, y, t, 20 , x = LL ..L, y = LL ..L , t = 0 ..10,


size = 500, 500 ;
t = 0.00000

Page 14 of 14

You might also like