Вы находитесь на странице: 1из 8

Partial Derivatives MAT538

Trapezoidal Rule and Simpson’s Rule are the numerical methods to approximate the definite integral
especially when the integral is difficult to be solved by using ordinary integral method.

1 Trapezoidal Rule
For the definition of the Trapezoidal Rule, let
Z b
h
f (x)dx ≈ Tn = [f (x0 ) + 2f (x1 ) + . . . + 2f (xn−1 ) + f (xn )]
a 2

b−a
where h = and n is the subintervals of equal length [a, b] .
n
Z 2
1
Example 1. Use the Trapezoidal Rule with n = 5 to approximate the integral dx.
1 x
Solution
2−1
Let n = 5, a = 1 and b = 2 and h = = 0.2. From the definition,
5
Z 2
1 0.2
dx ≈ T5 = [f (1) + 2f (1.2) + 2f (1.4) + 2f (1.6) + 2f (1.8) + f (2)] ;
1 x 2
            
1 1 1 1 1 1
= 0.1 1 +2 +2 +2 +2 +1 ;
1 1.2 1.4 1.6 1.8 2
 
2 2 2 2
= 0.1 1 + + + + + 0.5 ;
1.2 1.4 1.6 1.8
≈ 0.6956.

The use of Python Programming is useful as assistance to compute the integral numerically. The
following is the syntax for the problem in example 1.

Syntax integral =h*s


f=lambda x:1/x print(’integral=%.4f’ %integral)
a=1
b=2 Output
n=5
h=(b-a)/n integral=0.3167
s=0.5*(f(a)+f(b)) integral=0.4595
for i in range (1,n): integral=0.5845
s +=f(a+i*h) integral=0.6956

2 Simpson’s Rule
For the definition of Simpson’s Rule 1 , let
Z b
f (x)dx ≈ Sn
a
h
= [f (x0 ) + 4f (x1 ) + 2f (x2 ) + 4f (x3 ) + . . . + 2f (xn−2 ) + 4f (xn−1 ) + f (xn )]
3
b−a
where h = and n is the even subintervals.
n

1
Thomas Simpson is an English mathematician in the 18th century.

Page 1 of 8
Partial Derivatives MAT538

Z 2
1
Example 2. Use the Simpson’s Rule with n = 10 to approximate the integral dx.
1 x
Solution
2−1
Let n = 10, a = 1 and b = 2, we have h = = 0.1, from the definition,
10
Z 2
1
dx ≈ Sn
1 x
0.1
= [f (1) + 4f (1.1) + 2f (1.2) + 4f (1.3) + . . . + 2f (1.8) + 4f (1.9) + f (2)] ;
3  
0.1 4 2 4 2 4 2 4 2 4
= 1+ + + + + + + + + + 0.5 ;
3 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
≈ 0.6932.

algebraically
Z 2
1 2
dx = ln(x) = ln(2) − ln(1) ≈ 0.6932.

1 x 1

Z 5
cos(2x)
Example 3. Evaluate dx with 8 subintervals by using the Trapezoidal Rule and Simpson’s
1 x
Rule. Give the answer correct to four decimal places. (8 marks : Jan2018)

Solution
5−1 cos(2x)
h= = 0.5 and f (x) = .
8 x
cos(2x)
x cos(2x) f (x) = Coef (Coef)∗f (x) Coef (Coef)∗f (x)
x
1.0 -0.4161 -0.4161 1 -0.4161 1 -0.4161
1.5 -0.9900 -0.6600 2 -1.3200 4 -2.6400
2.0 -0.6536 -0.3268 2 -0.6536 2 -0.6536
2.5 0.2837 0.1135 2 0.2270 4 0.4540
3.0 0.9602 0.3201 2 0.6402 2 0.6402
3.5 0.7540 0.2154 2 0.4308 4 0.8616
4.0 -0.1455 -0.0364 2 -0.0728 2 -0.0728
4.5 -0.9111 -0.2025 2 -0.4050 4 -0.8100
5.0 -0.8391 -0.1678 1 -0.1678 1 -0.1678
-1.7373 -2.8045

Note that, do the calculation in radian for the trigonometric functions.


(i) Trapezoidal rule
Z 5
cos(2x) 0.5
≈ (−1.7373);
1 x 2
≈ −0.4343.

(ii) Simpson’s rule


Z 5
cos(2x) 0.5
≈ (−2.8045);
1 x 3
≈ −0.4674.

Page 2 of 8
Partial Derivatives MAT538

Practice
Use the Trapezoidal Rule and Simpson’s Rule to approximate the given integral with the specific value
of n. (Round down the answer to four decimal places)
Z 2 Z 4
1. xdx, n = 4. 2. (x + 1)dx, n = 6.
1 0
Z 2p Z 4
3. x3 − 1dx, n = 10. 4. ln(x)dx, n = 6.
1 1

4 4

Z Z
3
5. x sin(x)dx, n = 8. 6. y cos(y)dy, n = 8.
0 0

1 4
x2
Z Z
7. dx, n = 10. 8. ln(1 + ex )dx, n = 8.
0 1 + x4 0

3 Fourth Order Runge-Kutta


A Fourth Order Runge-Kutta method (abbreviated as RK4) is a numerical method which is used to
find the approximate solution to a first-order initial value problem
dy
y0 = = f (x, y) , y (xn ) = yn .
dx
The algorithm summarized for the solution of first-order initial value problem by using the RK4
method is stated as
h
yn+1 = yn + (k1 + 2k2 + 2k3 + k4 ) ;
6

k1 = f (xn , yn ); k2 = f (xn + 12 h, yn + 12 hk1 );


k3 = f (xn + 12 h, yn + 21 hk2 ); k4 = f (xn + h, yn + hk3 ).

which h = xn+1 − xn is the step size.


Example 4. Use the RK4 method with h = 0.1 to obtain an approximation to y(1.1) for the solution
of y 0 = 2xy, y(1) = 1. Give the answer correct to 4 decimal places.
Solution
Let f (x, y) = 2xy, xn = 1, yn = 1 and the stepsize, h = 0.1,

k1 = f (1, 1) = 2[1][1] = 2;
 
1 1
k2 = f 1 + [0.1], 1 + [0.1][2] = f (1.05, ) = 2[1.05][1.1] = 2.3100;
2 2
 
1 1
k3 = f 1 + [0.1], 1 + [0.1][2.31] = f (1.05, 1.1155) = 2[1.05][1.1155] = 2.3426;
2 2
k4 = f (1 + 0.1, 1 + [0.1][2.3426]) = f (1.1, 1.2343) = 2[1.1][1.2343] = 2.7155.

and therefore
0.1
y(1.1) = yn + (k1 + 2k2 + 2k3 + k4 ) ;
6
0.1
= 1+ [2 + 2[2.31] + 2[2.3426] + 2.7155] ;
6
0.1
= 1+ [14.0207];
6
≈ 1.2337.

Page 3 of 8
Partial Derivatives MAT538

We can verify the solution of y 0 = 2xy, y(1) = 1 algebraically.

dy Substitute y(1) = 1 into (1) yields


y0 = = 2xy;
dx 2 −1
1 y = ex (2)
dy = 2xdx;
y
Z
1
Z Substitute x = 1.1 into (2) yields
dy = 2xdx;
y 2 −1
2 y(1.1) = e(1.1) ;
ln(y) = x + c;
2 +c ≈ 1.2337
y = ex (1)
dy
Example 5. Consider the differential equation = sin(x + y) with initial condition y(0) = 2 and
dx
stepsize h = 0.1. If x10 = 1.0 and y10 = y(0.1) = 2.3375, estimate the value of y11 = y(1.1) using the
Runge-Kutta Fourth order method. Give the answer to four decimal places. (8 marks : Jul2017)

Solution
Let f (x, y) = sin(x + y), x10 = 1.0, y10 = 2.3375 and the stepsize h = 0.1,

k1 = f (x10 , y10 ) = sin(1 + 2.3375) = −0.1947;


 
0.1 0.1
k2 = f 1 + , 2.3375 + [−0.1947] = f (1.05, 2.3278) = sin(1.05 + 2.3278) = −0.2340;
2 2
 
0.1 0.1
k3 = f 1 + , 2.3375 + [−0.2340] = f (1.05, 2.3258) = sin(1.05 + 2.3258) = −0.2320;
2 2
k4 = f (1 + 0.1, 2.3375 + [0.1][−0.2320]) = f (1.1, 2.3143) = sin(1.1 + 2.3143) = −0.2693.

and therefore
0.1
y11 = y10 + (k1 + 2k2 + 2k3 + k4 ) ;
6
0.1
= 2.3375 + [−0.1947 + 2[−0.2340] + 2[−0.2320] + (−0.2693)] ;
6
0.1
= 2.3375 + [−1.3960];
6
≈ 2.3142.

Practice

dy sin(x) − xy 2
JUN16 If = and y(0) = 5, use the Fourth-Order Runge-Kutta method with a step size
dx 3
h = 0.3 to approximate y when x = 0.3. Give the answer correct to 5 decimal places. (ans:
4.66485)

DEC16 In a chemical reaction, the amount y grams of a substance after t hours is modeled
dy
= e−2t − 2y, y(0) = 0.
dt
Use the Fourth-Order Runge-Kutta method with the step size h = 2 to estimate y(2). (ans:
-3.4802)

JUL17 Consider the Differential Equation y 0 = sin(x + y) with initial condition y(0) = 2 and step size
h = 0.1. If x10 = 1 and y10 = 2.3375, estimate the value of y11 = y(1.1) by using the Fourth-
Order Runge-Kutta method. Give the answer correct to four decimal places. (ans: 2.3142)

Page 4 of 8
Partial Derivatives MAT538

4 Fourier Analysis
In this section, we will study the Fourier analysis which is widely used in the study of wave. We will
limit our discussion to Fourier series and the related topics.

4.1 Odd and Evan Functions


A function is said to be even when its graph is symmetric with respect to the y-axis and odd when
its graph is symmetric with respect to the origin. Generally,

(i) A fucntion y = f (x) is even when for each x in the domain of f such that f (−x) = f (x).

(ii) A fucntion y = f (x) is odd when for each x in the domain of f such that f (−x) = −f (x).

Example 6. Determine
√ whether the given function is even, odd or neither.
(a) f (x) = 2 + x2 (b) g(x) = x1/3 − sin(x) (c) k(x) = e2x

Solution p p
(a) f (−x) = 2 + (−x)2 = 2 + x2 = f (x).
f (x) is an even function.
h i
(b) g(−x) = (−x)1/3 − sin(−x) = −x1/3 + sin(x) = − x1/3 − sin(x) = −g(x).

g(x) is an odd function.


(c) k(−x) = e2(−x) = e−2x .
g(x) is neither an even nor an odd function.
2x
Example 7. State whether the function f (x) = 2 − is even, odd or neither even nor odd. (1 mark
π
: Jan2018)

Solution
2(−x) 2x
f (−x) = 2 − =2+
π π
f (x) is neither an even nor an odd function.

4.2 Fourier Series


A Fourier series is an expansion of a periodic function in terms of an infinite sum of sine and cosine
functions.
Definition: Let f be a function defined on the interval [−T, T ], the Fourier series of f is the
trigonometric series which is given by
∞ ∞
1 X  nπx  X  nπx 
f (x) = a0 + an cos + bn sin ; (1)
2 T T
n=1 n=1

which
Z T
1
a0 = f (x)dx; (2)
T −T
Z T
1  nπx 
an = f (x) cos dx; n = 0, 1, 2, ... (3)
T −T T
Z T
1  nπx 
bn = f (x) sin dx; n = 1, 2, ... (4)
T −T T

a0 is a constant coefficient, an is a Fourier Cosine coefficient and bn is a Fourier Sine coefficient.

Page 5 of 8
Partial Derivatives MAT538

Example 8. Compute the Fourier series for f (x) = x, 0 < x < π.

Solution
1 π x2 π
Z
π
a0 = xdx = = .
π 0 2π 0 2
Z π
1
an = x cos(nx)dx;
π 0
 Z π 
1 x sin(nx) π sin(nx)
= − dx ;
π n 0 0 n
cos(nπ) 1
= 2
− 2 ;
n π n π
1
= [cos(nπ) − 1] , n = 1, 2, ...
n2Zπ
1 π
bn = x sin(nx)dx;
π 0
 Z π 
1 x cos(nx) π cos(nx)
= − + dx ;
π n 0 0 n
cos(nπ)
= − , n = 1, 2, ...
n
∞  
π X 1 cos(nπ)
Therefore f (x) = + [cos(nπ) − 1] cos(nx) − sin(nx) ;
4 n2 π n
n=1
   
π 2 1
= + − cos(x) + sin(x) + − sin(2x) + ...
4 π 2
π 2 1
= − cos(x) + sin(x) − sin(2x) + ...
4 π 2
Example 9. Let f (x) be a periodic function with period 2π. Find the Fourier series expansion for
f (x) until the first three non-zero terms. (13 marks : Jul2017)

0, −π < x < 0,
f (x) =
π − x, 0 < x < π.

Solution
Z π Z 0 Z π 
1 1
a0 = f (x)dx = f (x)dx +f (x)dx ;
π −π π −π 0
Z 0 Z π 
1
= (0)dx + (π − x)dx ;
π −π 0
1 π
Z
= 0+ (π − x)dx;
π 0

x2

1
= πx − ;
π 2 0
π
= .
2

Page 6 of 8
Partial Derivatives MAT538

Z π Z 0 Z π 
1 1
an = f (x) cos(nx)dx = f (x) cos(nx)dx + f (x) cos(nx)dx ;
π −π π −π 0
Z 0 Z π 
1
= (0) cos(nx)dx + (π − x) cos(nx)dx ;
π −π 0
1 π
Z
= 0+ (π − x) cos(nx)dx;
π 0
1 (π − x) sin(nx) cos(nx) π
 
= − ; n = 1, 2, ...
π n n2 0
 
1 cos(πn) 1
= − + 2 ;
π n2 n
1 − cos(nπ)
= 2
.
Z π Zn 0π Z π 
1 1
bn = f (x) sin(nx)dx = f (x) sin(nx)dx + f (x) sin(nx)dx ;
π −π π −π 0
Z 0 Z π 
1
= (0) sin(nx)dx + (π − x) sin(nx)dx ;
π −π 0
1 π
Z
= 0+ (π − x) sin(nx)dx;
π 0
(π − x) cos(nx) sin(nx) π
 
1
= − − ; n = 1, 2, ...
π n n2 0
 
1 sin(πn) π
= − + ;
π n2 n
1 sin(πn)
= − .
n πn2

a0 X
Therefore f (x) = + [an cos(nx) + bn sin(nx)] ;
2
n=1
∞    
π X 1 − cos(nπ) 1 sin(πn)
= + cos(nx) + − sin(nx);
4 n2 π n πn2
n=1
   
π 2 1
= + cos(x) + 0 + · · · + sin(x) + sin(2x) + · · · ;
4 π 2
π 2
= + cos(x) + sin(x) + · · ·
4 π
A Fourier series is just not only represents the function on the interval (−T, T ) but also gives the
periodic extension of f outside of this interval.

Example 10. Sketch the periodic extension of f (x) = x in example 8 for −π < x < 2π.

Solution
y

x
−π π 2π

Page 7 of 8
Partial Derivatives MAT538

In-Class Tutorial

1. Find the Fourier series for the function



0, −π < x < 0,
f (x) =
1, 0 ≤ x < π.

1 1 X 1 − cos(nπ)
ans:f (x) = + sin(nx)
2 π n
n=1

2. Find the Fourier series for the function



1, −1 < x < 0,
f (x) =
x, 0 ≤ x < 1.
∞ ∞
3 X cos(nπ) − 1 X 1
ans:f (x) = + cos(nπx) − sin(nπx)
4 n2 π 2 nπ
n=1 n=1

3. Find the Fourier series for the function f (x) = x + π, −π < x < π.

X − cos(nπ)
ans:f (x) = π + 2 sin(nx)
n
n=1

2x
JAN 2018 Consider the function f (x) = 2 − for −π < x < π and f (x + 2π) = f (x).
π
(i) Sketch the graph of f (x) if −3π < x < 3π.
(ii) State whether the function f (x) is even, odd or neither even nor odd.
(iii) Find the Fourier series of f (x) if a0 = 4.

X 4
ans:(ii) neither odd nor even, (iii)f (x) = 2 + cos(nπ) sin(nx).

n=1

t2
DEC 2016 A function f (t) is defined by f (t) = for 0 < t < 2π and f (t + 2π) = f (t).
2
(i) Sketch the graph of f (t) if −4π < t < 4π.
8π 2
(ii) Given a0 = , obtain the Fourier series for f (t).
3
∞ 
4π 2 X 2


ans:f (t) = + cos(nt) − sin(nt) .
3 n2 n
n=1

DEC 2015 A function f (t), f (t + 2π) = f (t) is defined by


(
0, −π < t < 0,
f (t) = π−t
, 0 < t < π.
2
1
Find the fourier series for f (t) up to the first three non-zero terms if bn = .
2n
∞  
π X 1 − cos(nπ) sin(nt) π cos(t) sin(t)
ans:f (t) = + 2
cos(nt) − = + + + · · ·.
8 2n π 2n 8 π 2
n=1

Page 8 of 8

Вам также может понравиться