Lecture 10
Lecture 10
h
a xi xi+1 b
i = 0,1,, n xi x j i
In our application, y i = f (x i )
n n x xk n n s k
b
a p(x) dx = f (x i ) ab dx = f (x i ) 0
n
hds
i= 0 k = 0,k i x i x k i= 0 k = 0,k i i k
where x = a + sh
n s k
Note that
n
0 hds = i h
k = 0,k i i k
So i is just a number depending on i,n
Winter Semester 2006/7 Computational Physics I Lecture 10 3
Newton-Cotes Formulas
n
So,
b
a p(x) dx = h f (x i ) i
i= 0
x x1 x x0
n =1 p(x) = f (x 0 ) + f (x1 )
x 0 x1 x1 x 0
1 s k s 1 12
1
0 = 0
1
ds = 0
1
ds = + 1 =
k = 0,k i i k 0 1 2 2
1 s k s 0 12
1
1 = 0
1
ds = 0
1
ds = =
k = 0,k i i k 1 0 2 2
n 1 1 h
b
a p(x) dx = h f (x i ) i = hf (x 0 ) + hf (x1 ) = ( f (x 0 ) + f (x1 ))
i= 0 2 2 2
Trapezoidal rule
Winter Semester 2006/7 Computational Physics I Lecture 10 4
Trapezoidal Rule
Graphically: f(x1)
A=f(x0)h+1/2[f(x1)-f(x0)]h
f(x0)
h
x0 x1
Of course, we can apply this to many subdivisions (composite
trapezoidal rule) :
m
b
a f (x) dx = zz f (z) dz where z0 = a, zm +1 = b
i
i +1
i= 0
[ ]
n 1 1 B
F(i) =
n
0 F(s) ds [ F(0) + F(n)] + 2k F (2k 1) (n) F (2k 1) (0)
i=1 2 k =1 (2k)!
where
F (k ) is the k - th derivative of F and the B2k are the Bernoulli numbers
n Bn
0 1
1 /2 = .5 Bn=0 for n3, odd
2 1/6 0.1667
4 /30 .0333
6 1/42 0.02381
8 /30 .0333
10 5/66 0.07576
12 91/2730 .2531
14 7/6 1.1667
[ ]
n 1 1 b 1 B
f (x i ) = a f (x) dx [ f (a) + f (b)] + 2k f
(2k 1)
(b) f ( 2k 1) (a) h 2k
i=1 h 2 k =1 (2k)!
or
n 1 2
h h
a f (x) dx = h f (x i ) + [ f (a) + f (b)] [ f (b) f (a)] + O(h )
b 4
i=1 2 12
Trapezoidal Rule
We see that the error from the trapezoidal rule is of order h2.
b
a f (x) dx 2h ( f (a + h) + f (a + 3h) + + f (b h))
Let Rij be our estimate of the integral when 2i-1 intervals are used
and j is the order of the interpolating polynomial (previously n).
E.g., j=1 is Trapezoidal Rule, j=2 is Simpson’s Rule.
Look at the error formula:
b
a f (x) dx = TS (h) + 2 h 2 + 4 h 4 +
h
where TS (h) is e.g. the Trapezoidal rule. Now take h
2
a f (x) dx = TS (h /2) + 2 h /4 + 4 h /16 +
b 2 4
so
4TS (h /2) TS (h)
b
a f (x) dx = 4 h 4 /4 +
3
i.e., can get a higher order error by combining results from
different step sizes (recall extrapolation method for derivatives).
Winter Semester 2006/7 Computational Physics I Lecture 10 10
Extrapolation Method
Ri+1, j Ri, j
Ri+1, j +1 = Ri+1, j + See Scherer lecture notes
4 1
j
for derivation
K = 0 / 2 1 k 2 sin 2 d
Next example:
K = 02 4 x 2 dx =
Convergence much
slower because of infinite
slope at x=2
d 4 x 2 1 2x x
= = x
2
dx 2 4 x 2
4 x 2
L μ I r sin L μ I x
B = Bˆy, B = 0
dz =
0
dz
L 4 L 4 (x 2 + z 2 ) 2
3 3
r
μ0I
Consider L, x small: Ampere’s Law gives B = where r is
2r
the distance from the wire. Try our numerical calculations.
Winter Semester 2006/7 Computational Physics I Lecture 10 14
Magnetic Field
x 1 x 1
r = x = 1, 3 2 = 3 2 , 3 2 = 3 2
x + z min 1 + L x + z max 1 + 0
2 2 2
x
3 2
x + z 2 min 1
= 3 2
x 1 + L2
3 2
x + z 2 max
23 13
for this ratio , L > 1
For L = 1000, = 10 9
Rounding errors
Winter Semester 2006/7 Computational Physics I Lecture 10 16
Magnetic Field
Try double precision: L=10000
fg = 1
1
f (x)g(x) dx
Now consider an orthogonal set of polynomials on this interval,
such that
Pi P j = ij
E.g., Legendre polynomials (1,x,x2-1/3,…)
w j = 1
1
L j dx
Note what we have achieved: 2n-1 accuracy using a polynomial of
degree n by picking sampling points in special way.
Procedure (Legendre polynomials):
1. Choose which order you want to use (n)
2. Find the n roots of Pn (look them up in a table)
3. Find the corresponding Lagrange Polynomials
4. Calculate the weight factors
6. Evaluate the integral
Winter Semester 2006/7 Computational Physics I Lecture 10 20
Gaussian Quadrature
/2 /2 /2 /2 1 /2 /2 1
e.g., K = 1 sin 2 d cos + cos + 3
0
2 2 2 3 2 2
= [0.9454092 + 0.3258856] = 0.9984726
4
Winter Semester 2006/7 Computational Physics I Lecture 10 22
Gaussian Quadrature
Of course, can apply composite Gaussian Quadrature, or use a
higher order Legendre polynomial.
n xi wi
1 0 2
2 ±1/3 1
0 8/9
3
±3/5 5/9
±0.339981 0.652145
4
±0.861136 0.347855
0 0.568889
5 ±0.538569 0.478629
±0.906180 0.236927
[-1,1] 1 Legendre
d
8 0 m
cos cos m