Uploaded by Benjamin Breeg

wk5-lecture-notes-5

advertisement
lOMoARcPSD|25470736
Wk5 - Lecture notes 5
Differential Equations for Engineering (National University of Singapore)
Studocu is not sponsored or endorsed by any college or university
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
MA1512 Week 5
Lecture materials
5.1
Partial differential equations
Definition 5.1. A partial differential equation (PDE ) is an equation containing an unknown
function u(x, y, . . . ) of two or more independent variables x, y, . . . and its partial derivatives
with respect to these variables.
Example 5.2. Consider the PDE uxy − 2x + y = 0. A solution is
u(x, y) = x2 y −
1 2
xy + F (x) + G(y),
2
where F (x) and G(y) are arbitrary functions, because then
ux = 2xy −
1 2
y + F ′ (x)
2
and
uxy = 2x −
1
· 2y = 2x − y.
2
Adding to the PDE the conditions u(x, 0) = x3 and u(0, y) = sin(3y) gives
(
x2 · 0 − 21 x · 02 + F (x) + G(0) = u(x, 0) = x3 ,
2
0 ·y−
1
2
2
0 · y + F (0) + G(y) = u(0, y) = sin(3y).
(∗)
(†)
Setting x = 0 or y = 0 reveals that F (0) + G(0) = 0. So adding (∗) to (†) gives
F (x) + G(0) + F (0) + G(y) = x3 + sin(3y).
Hence u(x, y) = x2 y −
1
2
xy 2 + x3 + sin(3y).
Remark 5.3. General solutions to ODEs contain arbitrary constants, while general solutions
to PDEs contain arbitrary functions.
Definition 5.4.
tive.
(1) The order of a PDE is the order of the equation’s highest order deriva-
(2) A first-order linear PDE in u(x, y) has the form
Aux + Buy + Cu = Z,
(‡)
where A, B, C, Z are (possibly constant) functions of x, y (but not u).
(3) A second-order linear PDE in u(x, y) has the form
Auxx + Buxy + Cuyy + Dux + Euy + F u = Z,
where A, B, C, D, E, F, Z are (possibly constant) functions of x, y (but not u).
(4) The PDE in (‡) or (§) is homogeneous if Z ≡ 0.
40
Downloaded by Benjamin Breeg (chankpop@gmail.com)
(§)
lOMoARcPSD|25470736
PDE
4uxx − ut = 0
x2 Ryyy = y 3 Rxx
tutx + 2ux = x2
4uxx − uut = 0
(ux )2 + (uy )2 = 2
order
2
3
2
2
1
linear
yes
yes
yes
no
no
homogeneous
yes
yes
no
N/A
N/A
Table 5.1: Examples of PDEs
Theorem 5.5 (Superposition Principle). If u1 , u2 are solutions to a linear homogeneous DE,
then so is
u = c 1 u1 + c 2 u2 ,
for any constants c1 , c2 .
Proof. This follows from the linearity of differentiation.
Example 5.6. Consider the Laplace equation uxx + uyy = 0, which is a linear homogeneous
PDE. Its solutions include
u(x, y) = x2 − y 2
and
u(x, y) = ex cos y
and
u(x, y) = ln(x2 + y 2 ).
So u(x, y) = 3(x2 −y 2 )−7ex cos y+10 ln(x2 +y 2 ) is again a solution to the DE by Theorem 5.5.
5.2
Separation of variables
Observation 5.7. If u(x, y) = X(x) Y (y) where X, Y are functions of one variable, then
ux (x, y) = X ′ (x) Y (y),
uy (x, y) = X(x) Y ′ (y),
uxx (x, y) = X ′′ (x) Y (y),
uxy (x, y) = X ′ (x) Y ′ (y),
uyy (x, y) = X(x) Y ′′ (y),
etc.
Strategy 5.8 (separation of variables for first-order PDEs). Suppose a first-order
PDE has a solution of the form u(x, y) = X(x) Y (y).
(1) Substitute the expressions for u, ux , uy from Observation 5.7 into the PDE.
(2) Rearrange into the form f (x, X(x), X ′ (x)) = g(y, Y (y), Y ′ (y)).
(3) This implies that f (x, X(x), X ′ (x)) = k = g(y, Y (y), Y ′ (y)), where k is a constant.
(4) Solve these two ODEs for X(x) and Y (y).
(5) Then u(x, y) = X(x) Y (y) is a solution to the PDE.
Remark 5.9. A similar strategy applies to higher-order PDEs with 2 independent variables.
Example 5.10. Solve ux + xuy = 0 by separating the variables.
Solution. Let u(x, y) ..= X(x) Y (y) which satisfies the PDE. Then
X ′ (x) Y (y) + x X(x) Y ′ (y) = 0
X ′ (x)
Y ′ (y)
=−
.
x X(x)
Y (y)
⇔
Let k be a constant such that
Y ′ (y)
X ′ (x)
=k=−
.
x X(x)
Y (y)
41
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
Temperature
u
uxx < 0
↓
uxx < 0
↓
x
0
L
↑
uxx > 0
Figure 5.1: The Heat Equation
• Rewrite the first equation as X ′ /X = kx. Integrating gives ln |X| = kx2 /2 + C, or
equivalently X = A exp(kx2 /2), where A, C are constants.
• Rewrite the second equation as Y ′ /Y = −k. Integrating gives ln |Y | = −ky + D, or
equivalently Y = B exp(−ky), where B, D are constants.
Thus u(x, y) = E exp(kx2 /2 − ky), where E is a constant.
5.3
The Heat Equation
Equation 5.11 (The Heat Equation). Consider the temperature u of a long thin bar of
constant cross section and homogeneous material, oriented along the x-axis and is perfectly
insulated laterally, so that heat only flows in the x-direction. The temperature u(x, t) is given
by
ut = c2 uxx ,
where c2 is a constant called the thermal diffusivity of the substance of which the bar is
made.
Boundary and initial conditions 5.12.
temperature, so that for all t,
(1) The ends x = 0 and x = L are kept at zero
u(0, t) = 0 and
u(L, t) = 0.
(2) At position x, the initial temperature of the bar is f (x), so that
u(x, 0) = f (x).
Solution. The method of separation of variables gives the following solutions to the
Heat Equation with Boundary Conditions 5.12(1):
u(x, t) = B sin
nπ nπ 2 c2 t ,
x exp −
L
L
where B is a constant and n is an integer. One can then fit such solutions to Initial
Condition 5.12(2), using Theorem 5.5 if needed.
Example 5.13. Solve ut = 2uxx , 0 6 x 6 3, t > 0, u(0, t) = 0, u(3, t) = 0, u(x, 0) =
5 sin(4πx).
42
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
Solution. Let u(x, t) = X(x) T (t) be the solution. Then X(x) T ′ (t) = 2X ′′ (x) T (t), or
2X ′′ (x)
T ′ (t)
=k=
,
X(x)
T (t)
where k is a constant. Rewrite the two ODEs as X ′′ − (k/2)X = 0 and T ′ /T = k.
(1) The boundary conditions tell us X(0) T (t) = 0 = X(3) T (t) for all t > 0. If T ≡ 0 or
X ≡ 0, then u = XT ≡ 0, which contradicts the initial condition. So T (t) 6= 0 for
some t > 0. This implies X(0) = 0 = X(3) by the boundary conditions.
√
√
(2) Suppose k/2 > 0. Then 02 − 4 × (−k/2) = 2k > 0. So X = Ce k/2 x + De− k/2 x ,
where
Substituting into X(0) = 0 gives C
Thus X =
√ C, D are constants.
√
√ + D = 0. √
k/2 x
− k/2 x
3 k/2
−6 k/2
Ce
− Ce
. Substituting into X(3) = 0 gives Ce
(1 − e
) = 0.
The second and the third factors on the LHS cannot be 0 because k 6= 0. Hence C = 0.
This implies X ≡ 0, which contradicts point (1) above.
(3) Suppose k/2 = 0. Integrating the first ODE twice gives X = Cx + D, where C, D are
constants. Substituting into X(0) = 0 gives D = 0. Thus X = Cx. Substituting into
X(3) = 0 gives C = 0. This implies X ≡ 0, which contradicts point (1) above again.
(4) The two contradictions here show k/2 < 0. Let a be such that −k/2 = a2 . Then the
ODEs become X ′′ + a2 X = 0 and T ′ /T = −2a2 .
(5) Observe that X = cos(ax) and X = sin(ax) are linearly independent solutions to the
first ODE. So X = c1 cos(ax) + c2 sin(ax), where c1 , c2 are constants. Putting this into
the first boundary condition gives
c1 cos(a · 0) + c2 sin(a · 0) = X(0) = 0.
So c1 = 0. This makes X = c2 sin(ax). Putting this into the second boundary condition
gives
c2 sin(a · 3) = X(3) = 0.
If c2 = 0, then X = 0 · sin(ax) ≡ 0, which is not true by point (1). So sin(3a) = 0, or
equivalently 3a = nπ for some integer n. Fix an integer n such that a = nπ/3.
(6) Integrating both sides of the second ODE with respect to t gives ln |T | = −2a2 t + d
and thus T = A exp(−2a2 t), where A, d are constants.
2
2
(7) Hence u(x, t) = B sin(ax) exp(−2a2 t) = B sin n3 πx exp −2n
9 π t , where B is a constant.
(8) Substituting this into the initial condition gives
n −2n2
n 5 sin(4πx) = u(x, 0) = B sin
πx exp
π 2 · 0 = B sin
πx .
3
9
3
Comparing the two sides gives B = 5 and n/3 = 4. This implies n = 12. Thus
−2 × 122
u(x, t) = 5 sin(4πx) exp
π 2 t = 5 sin(4πx) exp(−32π 2 t).
9
Video materials
Equation 5.14 (The Wave Equation). A light string which lies stretched tightly along the
x-axis has its ends fixed at x = 0 and x = π, and is stationary at t = 0. Assuming tension is
the only force acting on the string, its position y(t, x) in the y-direction follows
ytt = c2 yxx ,
y(t, 0) = 0,
y(t, π) = 0,
y(0, x) = f (x),
yt (0, x) = 0,
where c is a positive constant, and f (x) is a continuous bounded function on [0, π] describing
the initial shape of the string.
43
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
Solution (D’Alembert). The following function satisfies the Wave Equation with the
initial and boundary conditions above when one extends f to an odd function of
period 2π:
1
y(t, x) = f (x + ct) + f (x − ct) .
2
Example 5.15 (2017/18 Semester 1 Exam Question 4(b)(ii)). Let y(t, x) be the solution of
the Wave Equation
ytt = yxx , 0 6 t, 0 6 x 6 π,
with y(t, 0) = y(t, π) = 0, y(0, x) = sin3 x, yt (0, x) = 0. Find the value of y( π6 , π3 ).
Solution. D’Alembert gives the solution y(t, x) = 12 sin3 (x + 1 · t) + sin3 (x − 1 · t) . So
y
π π
π π π π 1 =
sin3
+ sin3
= 0.562 . . . .
,
+
−
6 3
2
3
6
3
6
Summary
Strategy 5.8 (separation of variables for first-order PDEs). Suppose a first-order
PDE has a solution of the form u(x, y) = X(x) Y (y).
(1) Substitute u = XY and ux = X ′ Y and uy = XY ′ into the PDE.
(2) Rearrange into the form f (x, X, X ′ ) = g(y, Y, Y ′ ).
(3) This implies that f (x, X, X ′ ) = k = g(y, Y, Y ′ ), where k is a constant.
(4) Solve these two ODEs for X(x) and Y (y).
(5) Then u(x, y) = X(x) Y (y) is a solution to the PDE.
Remark 5.9. In the notation above,
uxx (x, y) = X ′′ (x) Y (y),
uxy (x, y) = X ′ (x) Y ′ (y),
uyy (x, y) = X(x) Y ′′ (y),
....
A similar strategy applies to higher-order PDEs with 2 independent variables.
Separable solution to the Heat Equation (Equation 5.11). The method of separation
of variables gives the following solutions to the Heat Equation ut = c2 uxx with the boundary
conditions u(0, t) = 0 and u(L, t) = 0:
u(x, t) = B sin
nπ 2 nπ c2 t ,
x exp −
L
L
where B is a constant and n is an integer. One can then fit such solutions to an initial
condition u(x, 0) = f (x), using the Superposition Principle (Theorem 5.5) if needed.
D’Alembert’s solution to the Wave Equation (Equation 5.14). The function
y(t, x) =
1
f (x + ct) + f (x − ct)
2
satisfies the Wave Equation ytt = c2 yxx together with the boundary conditions y(t, 0) = 0
and y(t, π) = 0, and the initial conditions y(0, x) = f (x) and yt (0, x) = 0.
44
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
Matlab materials
5.4
Surface plots
Solutions to the Heat Equation and the Wave Equation have two independent variables. One
way to visualize them is to use a 3-dimensional surface plot.
We can make such plots in Matlab using the surf command. As a demonstration, let
us plot the solution u(x, t) = 5 sin(4πx) exp(−32π 2 t) to Example 5.13 from x = 0 to x = 3
and from t = 0 to t = 0.02. We first need to decide what sample values of x and t we use to
make our plot. After some trials, it seems the following choice works fine.
>> x = 0:0.06:3;
>> t = 0:0.001:0.02;
As we saw before, the first line produces an array x that starts from 0 and progresses to 3 in
steps of 0.06, i.e., this array contains
0,
0.06,
0.12,
0.18,
...,
2.94,
3.
Similarly, the second line produces an array t that starts from 0 and progresses to 0.02 in
steps of 0.001, i.e., this array contains
0,
0.001,
0.002,
0.003,
...,
0.019,
0.02.
We then multiply these into the following grid of (x, t) values
(0, 0)
(0, 0.001)
(0, 0.002)
(0, 0.003)
..
.
(0.06, 0)
(0.06, 0.001)
(0.06, 0.002)
(0.06, 0.003)
..
.
(0.12, 0)
(0.12, 0.001)
(0.12, 0.002)
(0.12, 0.003)
..
.
(0.18, 0)
(0.18, 0.001)
(0.18, 0.002)
(0.18, 0.003)
..
.
...
...
...
...
...
(2.94, 0)
(2.94, 0.001)
(2.94, 0.002)
(2.94, 0.003)
..
.
(3, 0)
(3, 0.001)
(3, 0.002)
(3, 0.003)
..
.
(0, 0.019)
(0, 0.02)
(0.06, 0.019)
(0.06, 0.02)
(0.12, 0.019)
(0.12, 0.02)
(0.18, 0.019)
(0.18, 0.02)
...
...
(2.94, 0.019)
(2.94, 0.02)
(3, 0.019)
(3, 0.02)
on which we calculate the sample values for our plot. This is achieved using the meshgrid
command.
>> [X,T] = meshgrid(x,t);
This creates a matrix X containing
0
0
0
0
..
.
0.06 0.12 0.18
0.06 0.12 0.18
0.06 0.12 0.18
0.06 0.12 0.18
..
..
..
.
.
.
0 0.06 0.12 0.18
0 0.06 0.12 0.18
...
...
...
...
...
...
...
2.94 3
2.94 3
2.94 3
2.94 3
..
..
.
.
2.94 3
2.94 3
and a matrix T containing
0
0.001
0.002
0.003
..
.
0
0
0.001 0.001
0.002 0.002
0.003 0.003
..
..
.
.
0.019 0.019 0.019
0.02
0.02
0.02
0
...
0.001 . . .
0.002 . . .
0.003 . . .
..
...
.
0.019 . . .
0.0)
...
0
0
0.001 0.001
0.002 0.002
0.003 0.003
..
..
.
.
0.019 0.019
0.02
0.02.
45
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
Note that the overlapping of these two matrices gives the matrix of pairs we want. So these
can readily be used calculate the required sample values of u.
>>
>>
>>
>>
>>
U = 5*sin(4*pi*X).*exp(-32*pi*pi*T);
surf(x,t,U)
title(’Analytic solution’)
xlabel(’Distance x’)
ylabel(’Time t’)
One can rotate the plot, zoom in, or zoom out in Matlab.
5.5
Approximating solutions to PDEs using pdepe
We will use the pdepe command to solve numerically PDEs of the form
!
∂u ∂u ∂u
∂u m
−m ∂
+ s x, t, u,
c x, t, u,
x f x, t, u,
,
=x
∂x ∂t
∂x
∂x
∂x
where m is either 0, 1, or 2, and c, f , s are functions. Note that the Heat Equation is of this
form, but the Wave Equation is not. For demonstration, let us use Example 5.13 again. To
fit into the form where pdepe is applicable, let us rewrite the PDE ut = 2uxx there as
∂u
∂u ∂ 0
1·
x ·2
+ 0,
= x−0
∂t
∂x
∂x
so that
m = 0,
∂u = 1,
c x, t, u,
∂x
∂u ∂u
f x, t, u,
=2
,
∂x
∂x
∂u = 0.
s x, t, u,
∂x
Recall that we saw function handles at the end of Section 1.6.
46
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
• Let us store m in a new variable.
>> m=0;
• The command pdepe takes in c, f and s via one function handle, in exactly that order.
>> pdefun = @(x,t,u,dudx) deal(1,2*dudx,0)
The deal here puts the c, f and s into a form (called a comma-separated list in Matlab)
that is suitable to be fed into pdepe.
• We define a function handle for the initial condition u(x, 0) = 5 sin(4πx) via:
>> icfun = @(x) 5*sin(4*pi*x)
• Assume the x’s of interest satisfy
xL 6 x 6 xR ,
where xL , xR are constants. Instead of taking in boundary conditions as u(xL , t) =
uL (t) and u(xR , t) = uR (t), the command pdepe takes in boundary conditions in the
following more general form for the left and the right boundaries respectively:
∂u
pL (xL , t, uL ) + qL (xL , t) f xL , t, uL ,
∂x
∂u
pR (xR , t, uR ) + qR (xR , t) f xR , t, uR ,
∂x
x=xL
x=xR
= 0 and
= 0,
where pL , qL , pR , qR are functions and f is as above.
In our example, we have 0 6 x 6 3, so that
xL = 0 and
xR = 3.
Rewrite our boundary conditions u(0, t) = 0 and u(3, t) = 0 into the required form as
∂u
uL + 0 · f xL , t, uL ,
∂x
∂u
uR + 0 · f xR , t, uR ,
∂x
x=xL
x=xR
= 0 and
= 0,
so that
pL (xL , t, uL ) = uL ,
qL (xL , t) = 0,
pR (xR , t, uR ) = uR ,
qR (xR , t) = 0.
The command pdepe takes in pL , qL , pR , qR via one function handle, in exactly that
order.
>> bcfun = @(xl,ul,xr,ur,t) deal(ul,0,ur,0)
We do not need to include f here as this can be inferred from the other inputs of pdepe.
• One then specifies the x values at which we want the solution approximated. In general,
if these are denser, then the approximation is better, but the computation is heavier.
>> xmesh = linspace(0,3,50);
47
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
This command makes an array (i.e., a row vector) called xmesh with 50 equally spaced
entries starting from 0 and ending at 3. So the array xmesh will contain as entries
approximately
0=0×
3
,
49
1×
3
,
49
2×
3
,
49
3×
3
,
49
...,
48 ×
3
,
49
49 ×
3
= 3.
49
• Finally, we specify the t values at which we want the solutions approximated.
>> tspan = linspace(0,0.02,20);
Feed everything into pdepe. Let us store the approximated solution in sol.
>> sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan)
The approximated solution is returned as a 3-dimensional array, i.e., it is an array in which
each entry has three indices; the (j, k, i)-th entry here is the ith component of approximated
solution at x = the kth entry of xmesh and t = the jth entry of tspan. Since the values of
the solution function u are numbers (not vectors), we only have i = 1 here. Thus we can
turn sol into a more usual 2-dimensional array:
>> uapprox = sol(:,:,1);
Then we can plot the solution using surf as described in Section 5.4.
>>
>>
>>
>>
surf(xmesh,tspan,uapprox)
title(’Numerical solution computed with 50 mesh points’)
xlabel(’Distance x’)
ylabel(’Time t’)
48
Downloaded by Benjamin Breeg (chankpop@gmail.com)
lOMoARcPSD|25470736
Compare this with what we got from the analytic solution in Section 5.4.
We can also extract numerical values from the approximated solution. For instance,
suppose we want to get an approximated value for u(1.1, 0.001). We first find an entry in
xmesh that is closest to 1.1, and an entry in tspan that is closest to 0.001.
>> [xmindiff,xindex]=min(abs(xmesh-1.1));
>> [tmindiff,tindex]=min(abs(tspan-0.001));
Then we extract the approximated u value using the indices obtained. Note that the order
of the inputs in the output of pdepe is different from our usual order.
>> uapprox(tindex,xindex)
ans =
3.7483
One may compare this with the value that is found analytically.
>> 5*sin(4*pi*1.1)*exp(-32*pi*pi*0.001)
ans =
3.4675
49
Downloaded by Benjamin Breeg (chankpop@gmail.com)
Download