Matlab
Matlab
10
Partial Differential
Equations
10.1 Introduction
Most scientific and engineering problems are governed by
partial differential equations for which the dependent variable u
varies with the three coordinates of x, y, z, and time t. Solving the
partial differential equations is more difficult than the ordinary
differential equations learned earlier in the preceding chapters.
Their exact solutions are not available, in general, and numerical
methods are used to obtain the approximate solutions.
The widely used numerical methods are the finite
difference, finite element and finite volume methods. The finite
element method is the popular one because it can handle
complicated boundary conditions and domain geometries
effectively. MATLAB contains a toolbox that uses the finite
element method to solve for approximate solutions of the partial
differential equations in two dimensions.
332 Chapter 10 Partial Differential Equations
hu r
where h and r are constants or function of x, y and u.
(b) Specifying gradient value of the dependent variable u
along the boundary (Neumann condition) ,
u
c qu g
n
where c, q and g are constants or function of x, y and u. The letter
n denotes a unit vector normal to the boundary.
Solving the elliptic equation does not need the initial
condition while the parabolic equation needs an initial condition of
u x, y,0 at time t 0 . The hyperbolic equation needs two initial
conditions of u x, y,0 and u x, y,0 t at time t 0 .
Icons in the tool bar under the menu bar perform the same
tasks through the graphic interface. We will be familiar with this
graphic interface by solving examples in the following sections.
10.4 Elliptic Equations 335
1
u=0 u=0
x
u=0
2
It is noted that the exact solution for this problem which is derived
in the next example is,
sin x 2 sinh y 2
u x, y
sinh 2
336 Chapter 10 Partial Differential Equations
y u f x
2u 2u
w u0 0 u0
x 2 y 2
x
u0
1 d2X 1 d 2Y
X dx 2
Y dy 2
Since X is only function of x while Y is only function of y, then
both sides of this equation must be equal to a constant,
1 d2X 1 d 2Y
2
X dx 2
Y dy 2
Thus, the given partial differential equation becomes two ordinary
differential equations which should be solved easier.
If we consider the first ordinary differential equation,
d2X
2 X 0
dx 2
Its general solution is in the form of sine and cosine functions,
X x A sin x B cos x
where A and B are constants. These two constants are determined
as follows. Since the left edge boundary condition is u0, y 0 ,
then X 0 Y y 0 , or X 0 0 , so that B 0 . Similarly, the
right edge boundary condition is u, y 0 , then X Y y 0 ,
or X 0 . Then, X x above becomes,
X 0 A sin
But A cannot be zero, thus,
n
n and
where n is an integer. Hence, in general,
n
n n 1, 2, 3, ...
which are called the eigenvalues.
Similarly, if we consider the second ordinary differential
equation,
d 2Y
2 Y 0
dy 2
which has the general solution of,
10.4 Elliptic Equations 343
Y y E sinh y F cosh y
where E and F are constants. The constant F is determined from
the bottom edge boundary condition of u x,0 0 , i.e.,
X x Y 0 0 . Then Y 0 0 , which leads to F 0 . Thus, the
general solution of the partial differential equation is,
u x, y X x Y y A sin x E sinh y
Or, u x, y C sin x sinh y
where C AE denotes a new constant. Since there are n values of
, i.e, 1 , 2 , 3 , ..., n , thus, the general solution can be written
in the summation form for n values of as,
u x, y C
n 1
n sin n x sinh n y
Or, D
n 1
n sin n x f x
n x m x , m n
sin
sin
dx
0, m n
which is known as the orthogonal properties.
Then, the equation above reduces to,
n x
Dn
f x sin
dx
1 n x 2 n x
Or, Dn
f x sin
dx
f x sin
0
dx
sin x 2 sinh y 2
Or, u x, y
sinh 2
This exact solution can be plotted to show the distribution
of u x, y by using the meshgrid and mesh commands as follows,
xx = 0:.05:2; yy = 0:.05:1;
[x,y] = meshgrid(xx,yy);
u = sin(pi.*x/2).*sinh(pi.*y/2)/sinh(pi/2);
mesh(x,y,u); view(-37.5,30);
0.5
0
1
2
0.5 1.5
1
0.5
0 0
Exact solution
0.5
0
1
2
0.5 1.5
1
0.5
0 0
Approximate solution
346 Chapter 10 Partial Differential Equations
P-2
201214540 Example Use the PDE toolbox to solve the elliptic partial differen-
tial equation,
2u 2u
3 2 2 5u 8
x y
for an arbitrary two-dimensional domain as shown in the figure.
The domain has the specified boundary condition of u 0 for all
the edges. The problem statement is equivalent to the two-
dimensional steady-state heat transfer in a plate. The plate material
has its thermal conductivity coefficient of 3 units and is subjected
to surface convection with the convection coefficient of 5 units.
The plate is also subjected to a surface heating with the magnitude
of 8 units.
u0
u0
u0
u0
u0
u0
u0
u u u
d c c au f
t x x y y
P-3 Example Use the PDE toolbox to solve the parabolic partial
201361710 differential equation in the form,
u 2u u 2
2 3 2 2 8
t x y
for a circular domain with a unit radius. The domain has the
specified boundary condition of u 0 along the edge as shown in
the figure and the initial condition of u x, y,0 0 at time t 0 .
u0
u
n̂ 0
n
u0
P-4 Example Use the PDE tool to solve the parabolic partial
201421800 differential equation,
u 2u u 2
2 2 2 3u 4
t x y
on the 3 2 rectangular domain with small ellipse and rectangular
holes inside. The initial condition is u x, y,0 0 while the
boundary conditions are shown in the figure.
The procedure for solving this problem is similar to that
explained the preceding example. The domain geometry, however,
is more complicated with the boundary condition along the left
edge changes abruptly from u 0 to u 1 at t 0 . A finite
element mesh can be constructed as shown in the figure. We select
Parabolic as the type of PDE to be solved in the PDE Specification
dialog box under the PDE menu with the parameters of c 2,
a 3, f 4 and d 1 . To obtain the transient solution, we enter
0:0.01:0.5 in the Time box of the Solve Parameters dialog box as
shown in the figure.
354 Chapter 10 Partial Differential Equations
n̂
u
0 u x , y ,0 0 n̂
n
u 1 u0
u
n̂ 0
n
u
0
n
n̂
t 0 .1
t 0 .3
u0
u 2u u 2
0
t x 2 y 2
w u0 u0
u x, y , 0 f x, y
x
u0
X 2 X 0, Y 2Y 0 and T 2 2 T 0
At the same time, the given boundary conditions become,
X 0 0, X 0, Y 0 0 and Y w 0
By using the same procedure as shown in the preceding example of
the elliptic differential equation, the eigenvalues and eigenvectors
are obtained,
m m x
m , X m x sin
n n y
and n , Yn y sin
w w
The ordinary differential equation related to the time t is,
T 2 2 T 0
Its general solution is in the form,
T Amn e mn t
2
m n
2 2
where 2
mn
2
m
2
n
w
Thus, the general solution is,
u x, y, t X
m 1 n 1
m Yn T
m x n y mn2 t
A sin sin e
w
mn
m 1 n 1
where the constants Amn are determined from the initial condition
of u x, y,0 f x, y by using the orthogonal properties,
w
m x n y
f x, y sin
4
Amn
w 0 0 sin
w
dx dy
w
m x n y
x x 2 y w y sin
4
Amn
w 0 0 sin
w
dx dy
m x n y m2
sin
2 n 2 w2 2t
sin e
w
xx = 0:1/60:1; yy = 0:1/60:1;
[x,y] = meshgrid(xx,yy); meshgrid
t = 0.02; u = 0;
for m = 1:50;
for n = 1:50;
a = (-1)^m; b = (-1)^n - 1;
c = sin(m*pi.*x); d = sin(n*pi.*y);
ee= (m*m+n*n)*pi*pi*t; e = exp(-ee);
fac = 48/(m^3*n^3*pi^6);
u = u + fac*a*b.*c.*d*e;
end
end
mesh(x,y,u); view(-37.5,30); mesh
0.07
0.06
0.05
0.04
0.03
0.02
0.01
0
1
0.8 1
0.6 0.8
0.4 0.6
0.4
0.2 0.2
0 0
Exact solution
Time=0.02 Height: u
0.07
0.06
0.05
0.04
0.03
0.02
0.01
0
1
0.8 1
0.6 0.8
0.4 0.6
0.4
0.2 0.2
0 0
Approximate solution
10.6 Hyperbolic Equations 361
P-5 Example Use the PDE toolbox to solve the hyperbolic partial
201426040 differential equation in the form,
2u 2u 2u
0
t 2 x 2 y 2
for a 2 2 unit square domain. The boundary conditions are u 0
on the left and right edges while u y 0 on the top and bottom
edges as shown in the figure.
y
u
0
1, 1 y 1, 1
u0 u0
x
1, 1 u 1, 1
0
y
362 Chapter 10 Partial Differential Equations
too crude, we can click the sub-menu Refine Mesh for couple
times so that elements become smaller as shown in the figure.
To solve the problem, we choose the menu Solve and sub-
menu Parameters, and enter values in the Time box as 0:2:40. We
also need to provide the initial conditions of u x, y,0 and
u x, y,0 t in the next two small boxes as shown in the figure.
t 10 t 20
364 Chapter 10 Partial Differential Equations
P-6 Example Use the PDE toolbox to solve the hyperbolic partial
201578370
differential equation,
2u 2 u 2u
5 4 2 2 3u 2
t 2
x y
for a unit square domain with two small holes inside as shown in
the figure. The boundary conditions are u 0 on the left and right
edges, and u y 0 on the top and bottom edges while u n 0
along inner edges of the holes. The two initial conditions are,
y
u
0
1, 1 y 1, 1
u0 n̂ u0
x
n̂
1, 1 u
0
1, 1
y
t 10 t 40
u0
2u 2u u 2
0
t 2 x 2 y 2
w u0 u x, y , 0 f x, y u0
u
x, y , 0 0
t
x
u0
u x, y, t X x Y y T t
By substituting it into the differential equation, we obtain,
X Y T X Y T X Y T 0
where the prime symbol ( ) denotes the derivative order. We
divide the equation through by X Y T and move some terms to get,
T Y X
T Y X
Since the terms on the left-hand-side of the equation are only
functions of t and y while the term on the right-hand-side of the
equation is only function of x, then they must be equal to a
constant,
T Y X
2
T Y X
T Y
which leads to, 2 2
T Y
10.6 Hyperbolic Equations 369
w
m x n y
f x, y sin
4
Amn
w 0 0 sin
w
dx dy
16 2 w 2
1m 1 1n 1
m n 2 3
m x n y
sin sin cos mnt
w
The exact solution above is in the form of infinite series.
To solve for the solution of u x, y, t at t 0.35 for a unit square
domain w 1 , a MATLAB script file can be created with
details as follows,
xx = 0:1/60:1; yy = 0:1/60:1;
[x,y] = meshgrid(xx,yy); meshgrid
t = 0.35; u = 0;
for m = 1:50;
for n = 1:50;
a = (-1)^m - 1; b = (-1)^n - 1;
c = sin(m*pi.*x); d = sin(n*pi.*y);
al= sqrt(m^2*pi^2+n^2*pi^2); e = cos(al*t);
fac = 16/(m^3*n^3*pi^6);
u = u + fac*a*b.*c.*d*e;
end
end
mesh(x,y,u); view(-30,-10); mesh
10.6 Hyperbolic Equations 371
-1
-2
0
-3
0 0.2 0.5
0.4 0.6 0.8 1 1
Exact solution
Time=0.35 Height: u
-3
x 10
-1
-2
0
-3
0 0.2 0.5
0.4 0.6 0.8 1 1
Approximate solution
372 Chapter 10 Partial Differential Equations
Exercises
u
u x,0 1 , x,1 u x,1 2 0 x 1
y
u u
0, y 0 , 1, y 0 0 y 1
x x
Plot to compare the solution with the exact solution of,
y
u x, y 1
2
10. Use the PDE toolbox to solve the elliptic partial differential
equation,
2u 2u
2x x3 6xy 6xy2 1
x 2 y 2
376 Chapter 10 Partial Differential Equations
11. Use the PDE toolbox to solve the elliptic partial differential
equation,
2u 2u
20
x 2 y 2
for a circular domain with a unit radius. The boundary
condition along the edge is u 0 . Compare the solution with
the exact solution of,
u x, y 5 1 x2 y2
12. Use the PDE toolbox to solve Problem 11 again if the circular
domain contains a small circular hole with radius of 0.3 unit
and a square hole with dimension of 0.2 0.2 units as shown
in the figure. The boundary conditions for the edges of the
circular hole and square hole are u 0 and u n 0 ,
respectively. Plot the solution u x, y in form of the carpet
plot.
Exercises 377
.4 .4
13. Use the PDE toolbox to solve the elliptic partial differential
equation,
2u 2u
0
x 2 y 2
y
u0
u 100
u0
8 x
2
u0
u0
14. Due to symmetry of the solution in Problem 13, only the upper
right quarter of the domain as shown in the figure can be used
for the analysis. Solve the problem again with the boundary
conditions as shown in the figure. Plot the solution in form of
the carpet plot.
y
u0
u
0
n
u0
2
u 100
x
u
0
n
15. Use the PDE toolbox to solve the elliptic partial differential
equation which is in form of the Helmholtz equation,
2u 2u
a x, y u f x, y
x 2 y 2
for a unit square domain of 0 x 1 and 0 y 1 . The four
edges have the specified boundary conditions of u 0 . Find
the solution if a 2 and
f x, y xy x2 71 y 2 1 x2 y 2 7
Plot to compare the solution with the exact solution of,
u x, y x x3 y y3
Exercises 379
16. Use the PDE toolbox to solve the parabolic partial differential
equation,
u 2 u 2 u
0
t x 2 y 2
for a rectangular domain with the dimensions of 0.3 units,
i.e., 0 x and 0 y 0.3 . The boundary conditions along
the four edges are u n 0 and the initial condition is,
u x, y,0 cos x
Plot to compare the solution with the exact solution of,
u x, y, t et cos x
when t 0.2 .
P-8 17. Use the PDE toolbox to solve the parabolic partial differential
201693480 equation,
u 2u 2u
2
t x 2 y 2
for the rectangular domain of 0 x 1 and 0 y 0.2 . The
boundary conditions are shown in the figure. The initial
condition is,
u x, y,0 sin x x1 x
Plot to compare the solution with the exact solution of,
u x, y, t e 2t sin x x1 x
when t 0.1 . Study the solution behavior from animation in
the form of carpet plot.
y
u n 0
0 .2 u 0 u0
x
u n 0
1 .0
380 Chapter 10 Partial Differential Equations
18. Solve Problem 17 again when the domain contains two square
holes and a circular hole as shown in the figure. The boundary
conditions along the edges of the holes are u n 0 . Provide
comments on the solution behavior which is different from that
obtained in Problem 17.
y
P-9 19. Use the PDE toolbox to solve the parabolic partial differential
201734070 equation,
u 2u 2u
0
t x 2 y 2
for the rectangular domain of 0 x 1 and 0 y 0.2 with
the boundary conditions of,
u u
x,0, t 0, x,0.2, t 0 , 0 x 1
y y
when t 0.01, 0.02 and 0.05 .
Exercises 381
P-10 20. Use the PDE toolbox to solve the parabolic partial differential
202205120 equation,
u 2u 2u
7 4 2 2 3 u 12
t x y
for the 4 4 unit square domain with two holes as shown in
the figure. The boundary conditions along the outer four edges
are u 0 . The initial condition is given by u x, y,0 0 . Find
the solutions at t 0.2, 0.5 and 1.0 when the boundary
conditions along the hole edges are: (a) u 0 and (b)
u n 0 . Plot the solutions in form of the carpet plot.
y
1 .2
1 .2
.5
4
.7
1 .5
x
1 .5
4
P-11
21. Use the PDE toolbox to solve the hyperbolic partial differential
202205160
equation,
2u 2u 2u
0
t 2 x 2 y 2
382 Chapter 10 Partial Differential Equations
y
u n 0
0 .2 u 0 u0
x
u n 0
1 .0
23. Use the PDE toolbox to solve the hyperbolic partial differential
equation,
2u 2u 2u
2e sin x
t
t 2 x 2 y 2
for a rectangular domain of 0.3 units, i.e., 0 x and
0 y 0.3 with the boundary conditions of,
u u
x,0, t 0 , x,0.3, t 0 0 x
y y
u0, y, t 0 , u , y, t 0 0 y 0.3
and the initial conditions of,
u
u x, y,0 sin x and x, y,0 sin x
t
Plot to compare the solution with the exact solution of,
u x, y, t et sin x
when t 0.2 and 0.5 .
24. Use the PDE toolbox to solve the hyperbolic partial differential
equation,
2u 2u 2u
0
t 2 x 2 y 2
for a rectangular domain of 1 0.2 units, i.e., 0 x 1 and
0 y 0.2 with the boundary conditions of,
u u
x,0, t 0, x,0.2, t 0 0 x 1
y y
u0, y, t 0, u1, y, t 0 0 y 0.2
and the initial conditions of,
u
u x, y,0 sin2 x and x, y,0 2 sin2 x
t
Plot to compare the solution with the exact solution of,
u x, y, t sin2 xsin2 t cos2 t
when t 0.3 and 0.6 .
384 Chapter 10 Partial Differential Equations
P-13 25. Use the PDE toolbox to solve the hyperbolic partial differential
202205200 equation,
2u 2u 2u 2u
3 5 x 2 y 2 4
t 2
for a rectangular domain of 6 4 units with the boundary
conditions along the outer edges as shown in the figure. The
boundary conditions along the hole edges are u n 0 . The
initial conditions are given by,
u
u x, y,0 0 and x, y,0 0
t
Find the solutions for the interval of 0 t 1 . Display the
solutions at t 0.3, 0.5 and 1.0 in form of the carpet plot.
3
.75 u n 0
.75
2.5
u0
4
.75
u 1
1.5
x
u n 0 2
6