LM - PDE 1 - Solving Symbolic PDEs
LM - PDE 1 - Solving Symbolic PDEs
mw
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.
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
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.
Note, the sequence symbol $ can be used as a substitution for a sequence. For example: x$3 = x, x, x
> 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
> D 1 U 0, y ,
D 2 U x, 0
D1 U 0, y , D2 U x, 0
Symbolic pdsolve
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.
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
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
Best practice : always have the solutions be assigned to a variable so that you can easily refer to the solutions
without cutting and pasting.
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
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.
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
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
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
Page 6 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw
> 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 :
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:
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 .
Page 7 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw
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.
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
:
Page 8 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw
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:
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 :
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
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
s d op 1, term2 :
N
usum d >s :
n =1
> 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
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
N N
end proc:
Page 13 of 14
LM - PDE 1 - Solving Symbolic PDEs.mw
Page 14 of 14