Beruflich Dokumente
Kultur Dokumente
Consider the function f(x) shown below. The purpose of the exercise is to integrate the function
between the limits a and b.
1
f( x ) := a := 1 b := 3
x
b
⌠
A symbolic integration is shown next: ⎮ f( x ) dx → ln( 3 )
⌡
a
b
Using the equal sign, Mathcad calculates ⌠
⎮ f( x ) dx = 1.099
its own numerical approximation: ⌡
a
b−a
The interval a<x<b is divided into n equally-spaced intervals of size: Δx :=
n
Using rectangles with the height of the rectangle given by the left-hand side of each
subinterval results in the following approximation for the integral. The graph illustrates
the area being calculated. The index j runs from zero to n. The arrays x and y are
used for both calculating the integrals as well as for plotting . The array t is used for
the graphs only.
j := 0 .. n x := a + j⋅ Δx
j
y := f x
j ( j) t := a , a + 0.01 .. b
0.8
f( t)
yj
0.6
yj
0.4
0.2
1 1.5 2 2.5 3
t, x j , x j
n− 1
0.8
f( t)
yk+ 1
0.6
yk+ 1
0.4
0.2
1 1.5 2 2.5 3
t , xk , xk
n− 1
∑ ⎡⎣(f(xk+1))⋅Δx⎤⎦
The approximation for the integral is:
IR := IR = 1.035
k= 0
The figure below illustrates the approximation of the integral using the trapezoidal rule.
0.8
f( t)
yj
0.6
yj
0.4
0.2
1 1.5 2 2.5 3
t, x j , x j
n− 1
⎡1 ⋅ f x + f x ⎤
IT :=
∑ ⎢ ( ( k) ( k+1) ) ⋅ Δx⎥ IT = 1.102
The approximation for the integral is: ⎣2 ⎦
k=0
⎛ n n
−1 ⎞
⎜ 2 2 ⎟
⎜
IS := f( x ) + 4 ⋅ f( x f( x ) + f( x )⎟ ⋅
Δx
⎜ 0 ∑ 2 ⋅ k − 1) + 2⋅
∑ 2 ⋅ k n ⎟ 3
IS = 1.099
⎝ k= 1 k=1 ⎠
n− 1
⎡f⎛ a + k⋅ b − a ⎞ ⋅ ⎛ b − a ⎞⎤
IL( n ) :=
∑ ⎢⎜
⎣⎝
⎟⎜
n ⎠ ⎝ n ⎠⎦
⎟⎥
k= 0
n− 1
⎡f⎡a + ( k + 1 ) b − a⎤ ⋅ ⎛ b − a ⎞⎤
IR( n ) :=
∑ ⎢⎢
⎣⎣
⎥⎜
n ⎦ ⎝ n ⎠⎦
⎟⎥
k=0
Trapezoidal approximation:
n− 1
⎡ 1 ⋅ ⎡f⎛ a + k⋅ b − a ⎞ + f⎡a + ( k + 1) b − a⎤⎤ ⋅ ⎛ b − a ⎞⎤
IT( n ) :=
∑ ⎢ ⎢⎜
⎣2 ⎣ ⎝ n ⎠
⎟ ⎢
⎣
⎥⎥ ⎜
n ⎦⎦ ⎝ n ⎠⎦
⎟⎥
k= 0
⎡ n n
−1
⎤
⎢ 2 2 ⎥
⎢ ⎡ ⎡ b − a⎤⎤ ⎛ b − a⎞ ⎥ b−a
⎢ ∑
IS ( n ) := f( a) + 4 ⋅ f⎢a + ⎢( 2 ⋅ k − 1 ) ⋅
⎣ ⎣
⎥⎥ + 2⋅
n ⎦⎦ ∑f⎜ a + 2k ⋅
⎝ n ⎠
⎟ + f( b )⎥ ⋅
3⋅ n
⎣ k= 1 k=1 ⎦
IL( 10) = 1.168 IR( 10) = 1.035 IT( 10) = 1.102 IS ( 10) = 1.099
Next, we produce an array of values of n, making sure it includes only even numbers to satisfy
the requirement of Simpson's rule. Subsequently, we produce array of values of IL, IR, IT, and
IS to verify how the integral converges to a value as n increases:
n := 2 , 4 .. 10
n := 2 , 4 .. 24
n = 0 0 0 0
0 0 0 0 0 0 0 0
2
1 1.5 1 0.833 1 1.167 1 2
4
2 1.283 2 0.95 2 1.117 2 1.1
6
3 1.218 3 0.996 3 1.107 3 1.099
8
4 1.187 4 1.02 4 1.103 4 1.099
10
12 ILL = 5 1.168
IRR = 5 1.035
ITT = 5 1.102
ISS = 5 1.099
6 1.156 6 1.045 6 1.101 6 1.099
14
7 1.148 7 1.053 7 1.1 7 1.099
16
8 1.141 8 1.058 8 1.1 8 1.099
18
9 1.137 9 1.062 9 1.1 9 1.099
20
10 1.133 10 1.066 10 1.099 10 1.099
22
11 1.13 11 1.069 11 1.099 11 1.099
24
12 1.127 12 1.071 12 1.099 12 1.099
Extending the range of n to 24 shows the trapezoidal rule converging to the value of the
integral for n = 20 sub-intervals.
ILL n
2
IRR n 1.5
2
ITT n
2
1
ISS n
2
0.5
0 5 10 15 20
n, n, n, n
IL( 50) = 1.112 IR( 50) = 1.085 IL( 800 ) = 1.099 IR( 800 ) = 1.098
IL( 100 ) = 1.105 IR( 100 ) = 1.092 IL( 1600) = 1.099 IR( 1600) = 1.098
IL( 200 ) = 1.102 IR( 200 ) = 1.095 IL( 3600) = 1.099 IR( 3600) = 1.098
IL( 400 ) = 1.1 IR( 400 ) = 1.097 IL( 6000) = 1.099 IR( 6000) = 1.099
Notice that the left-hand side rectangular approach (IL) converges by n = 800, while the
right-hand side rectangular approach (IR) converges by n = 6000.
⎛ 2.3 3.6 5.2 6.1 8.2 11.3 14.3 15.2 18.4 19.3 ⎞
XY := ⎜ ⎟
⎝ 12.5 17.2 11.5 9.2 6.3 4.8 9.2 10.5 11.3 12.8 ⎠
〈〉
x := XY( T )0 (
y := XY
T
〈〉
)1
20
15
y
10
y
5
0
2 4 6 8 10 12 14 16 18 20
x, x
n := length ( x ) − 1 n=9
n− 1
⎡1 ⋅ y + y ⎤
ITD :=
∑ ⎢ ( k k+1) ⋅ ( x k+1 − x k)⎥ ITD = 160.65
⎣ 2 ⎦
k=0
b
⌠
P( a < X < b ) = ⎮ f( x ) dx
⌡
a
Suppose that the random variable X follows the normal distribution with mean μ and standard
deviation σ, then, the pdf is given by
⎡ −( x − μ ) 2⎤
⋅ exp⎢ ⎥,
1
f( x ) =
σ ⋅ 2⋅ π ⎢ 2 ⎥
⎣ 2⋅ σ ⎦
for −∞ < x < ∞. This function has no closed-form integral, therefore, it's well suited for a
numerical integration.
3 3
μ := 1500 σ := 300 a := μ − σ a = 1.2 × 10 b := μ + σ b = 1.8 × 10
⎡ −( x − μ ) 2⎤
⋅ exp⎢ ⎥
1
f( x ) :=
σ ⋅ 2⋅ π ⎢ 2 ⎥
⎣ 2⋅ σ ⎦
b
⌠
A plot of the pdf and the area represented by the integral P( a < X < b ) = ⎮ f( x ) dx is shown
⌡
a
below:
x := μ − 4 ⋅ σ , μ − 4 ⋅ σ + 10 .. μ + 4 ⋅ σ xs := ( a b ) ys := ( f( a) f( b ) )
0.002
f( x)
0.001
ys
0
0 1000 2000 3000
x , xs
Next, we borrow the definitions of functions IL, IR, IT, and IS:
n− 1
⎡f⎛ a + k⋅ b − a⎞ ⎛b − a ⎞⎤
IL( n ) :=
∑ ⎢⎜
⎣⎝ n
⎟ ⋅⎜
⎠⎝ n
⎟⎥
⎠⎦
k= 0
n− 1
⎡f⎡a + ( k + 1 ) b − a⎤ ⋅ ⎛ b − a ⎞⎤
IR( n ) :=
∑ ⎢⎢
⎣⎣
⎥⎜
n ⎦ ⎝ n ⎠⎦
⎟⎥
k=0
n− 1
⎡ 1 ⋅ ⎡f⎛ a + k⋅ b − a ⎞ + f⎡a + ( k + 1) b − a⎤⎤ ⋅ ⎛ b − a ⎞⎤
IT( n ) :=
∑ ⎢ ⎢⎜
⎣2 ⎣ ⎝ n ⎠
⎟ ⎢
⎣
⎥⎥ ⎜
n ⎦⎦ ⎝ n ⎠⎦
⎟⎥
k= 0
⎡ n n
−1
⎤
⎢ 2 2 ⎥
IS ( n ) := ⎢f( a) + 4 ⋅ ⎡ ⎡ b − a⎤⎤ ⎛ b − a⎞ ⎥ b−a
⎢ ∑ f⎢a + ⎢( 2 ⋅ k − 1 ) ⋅
⎣ ⎣
⎥⎥ + 2⋅
n ⎦⎦ ⎝ ∑
f⎜ a + 2k ⋅
n ⎠
⎟ + f( b )⎥ ⋅
3⋅ n
⎣ k= 1 k=1 ⎦
n = 0 0 0 0
0 0 0 0 0 0 0 0
2
1 0.641 1 0.641 1 0.641 1 1.016
4
2 0.673 2 0.673 2 0.673 2 0.683
6
3 0.678 3 0.678 3 0.678 3 0.683
8
4 0.68 4 0.68 4 0.68 4 0.683
10
5 0.681 5 0.681 5 0.681 5 0.683
12 ILL = IRR = ITT = ISS =
6 0.682 6 0.682 6 0.682 6 0.683
14
7 0.682 7 0.682 7 0.682 7 0.683
16
8 0.682 8 0.682 8 0.682 8 0.683
18
9 0.682 9 0.682 9 0.682 9 0.683
20
10 0.682 10 0.682 10 0.682 10 0.683
22
11 0.682 11 0.682 11 0.682 11 0.683
24
12 0.682 12 0.682 12 0.682 12 0.683
The following graph shows the variation of the different integral approximations with n in the
interval 0 < n < 24:
ILL n
2
0.685
IRR n
2
ITT n 0.68
2
ISS n
0.675
2
0.67
0 5 10 15 20
n, n, n, n
b
⌠
⎮ f( x ) dx = 0.683
⌡
a
Although the normal distribution pdf does not have a closed-form expression, it can be evaluated
symbolically by using Cntl . (control period) -- instead of the equal sign -- in the expression
above, i.e.,
⎛ 1⎞
⌠
b ⎜ 1 2⎟
⎮ f( x ) dx → erf ⎜ ⋅ 2 ⎟
⌡ ⎝2 ⎠
a
The function erf shown in the right-hand side of this result is referred to as the error function.
To see the definition of the error function, select the option Help>Mathcad Help, and click on
the Index button. Type erf in the search field and select the entry erf function in the list of
references shown. This will open the Mathcad Help facility entry for the erf function.
erf ( x) 0
1
5 0 5
To see Mathcad's version of the integral of xthe normal distribution pdf, we write it using mean
value η and standard deviation ω, instead of μ and σ (since those variables have been already
defined with numeric values):
⎛⎜ 1
1⎞⎟
⌠
⎜ 1 2
2
1 η 2 ⎟
⎮ ⎡ 2⎤ erf ⎜ ⋅ ⋅ξ − ⋅ ⋅2 ⎟
−( ξ − η ) ⎥ ⎝2 ω 2 ω ⎠
⋅ exp⎢
⎮ 1 1
dξ → ⋅ ω ⋅
⎮ s⋅ 2 ⋅ π ⎢ 2 ⎥ 2 s
⎮ ⎣ 2⋅ ω ⎦
⌡