Document1 05/28/16 1 End point trap rule

advertisement
Document1
05/28/16
h=(end-beg)/N
ai=h*(fun(beg)+fun(end))/2
for I=1, N-1
x=beg+i x h
ai=ai+h*fun(x)
enddo
ai=ai  h
1
End point trap rule
The use of the end points complicates the evaluation in two ways. First the
end values need to be divided by 2, secondly they need to be calculated and this
may involve analytically expanding functions such as (1-cos(x))/x2.
There are advantages:
1. The points evaluated are the ones actually used.
2. Placing N points in the center of each region allows N2N with N new function evaluations.
3. Evaluations with two different values of N allow the error term to be estimated and removed. Richardson.doc
The code accurate to order h2 for end point trap rule is in the box to the left1.
Start with Midpoint Traprule.doc Equation (10)

end
beg
h2
7h 4
f  x  dx  h f  xmi    f '(end )  f '(beg )  
 f '''(end )  f '''(beg )   O(h6 ) (1)

24
5760
i 1
N
The values of f(xi) need to be found.
Start with the expressions at (hi/2
2
3
4
1 iv
h 1
h 1
h
h
f  xi   f ( xmi )  f '( xmi )    f ''( xmi )    f '''( xmi )   
f ( xmi )   
2 2
2 6
 2  24
2
3
2
4
1 iv
h 
h 1
h 1
h
f  xi 1   f ( xmi )  f '( xmi )    f ''( xmi )    f '''( xmi )  i  
f ( xmi )   
2 2
2 6
2
 2  24
Add these two to find that
2
4
1 iv
h
h
f  xi   f  xi 1   2 f ( xmi )  f ''( xmi )   
f ( xmi )    ... (3)
 2  12
2
Or equivalently
(2)
Document1
f ( xmi ) 
f  xi   f  xi 1 
2
05/28/16
2
1h
1 iv
h
 f ''  xmi    
f  xmi   
2  2  24
2
2
4
(4)
Note that there are only even derivatives in this expansion. Substitute this into (1)to find

end
beg
N
f  xi   f  xi 1 
i 1
2
f  x  dx  h
2
4
1h N
1 h N
   h f ''  xmi     h f iv  xmi 
2  2  i 1
24  2  i 1
2
h
7h4
  f '(end )  f '(beg )  
 f '''(end )  f '''(beg )   O (h 6 )

24
5760
(5)
Use (1) to Integrate f’’

end
beg
N
f ''  x  dx  h f ''  xmi  
i 1
h2
7h 4
 f '''(end )  f '''(beg )  

24
5760
 f
iv

(end )  f iv (beg )   O(h 6 )
  f '  end   f '  beg 
(6)
Or
h2
h f ''  xmi    f '  end   f '  beg    f '''(end )  f '''(beg )   O  h 4  (7)
24
i 1
N
To this accuracy the sum of fiv is the difference of the values of f’’’, so that (5) becomes

end
beg
N
f  x  dx  h
f  xi   f  xi 1 
2
i 1


1 h
 
24  2 
4

1h 
h2
    f '  end   f '  beg     f '''(end )  f '''(beg )  
22 
24

2
2
h
 f '''(end )  f '''(beg )   24
 f '(end )  f '(beg ) 
7h4
 f '''(end )  f '''(beg )   O(h6 )
5760
N f x
 i   f  xi 1  2
 1 1 
 h
 h  f '  end   f '  beg      
2
 8 24 
i 1
(8)
1
7 
 1
6
 h 4  f '''(end )  f '''(beg )  


  O h 
 24  8 24  16 5760 
1
 1 1 
    
12
 8 24 
1
7 
1
8
1
 1



 30  15  7  


5760 720
 24  8 24  16 5760  5760
So that

end
beg
N
f  xi   f  xi 1 
i 1
2
f  x  dx  h
h2
h4
  f '  end   f '  beg   
 f '''(end )  f '''(beg )   O  h 6  (9)
12
720
Document1
05/28/16
The coefficients of the h2 and h4 terms are larger than those in midpoint integration, but the powers of h are the same.
Testing
Let h=1
 dx  1
11
h
 1
 2 
1
1
1
1.
0
x2
2.  xdx 
2
0
1
3.
2
 x dx 
0
1
4.
 x dx 
3
0
1
5.
 x dx 
4
0

0
3 1
1
2
2
1
 0 1 h
h

1  1 

2
 2  12
x
3

1
3
2
1 1 1
 0 1 h
h

2    Checks the - 1/12 in the h2 term

2 6 3
 2  12
x
4

1
4
1 1
1
1 1 1
 3 
6  6   
2 12
720
2 4 4
x
5

1
5
1 1
1
1 1 1
1
1
 4 
24     15  10  1 
2 12
720
2 3 30 30
5
0
4 1
0
5 1
0
Checks the +1/720 in the h4 term
1
x6
6.  x dx 
6
0
1

5
0
1
6
1 1
1
1 5
1
1
1
 5 
60     6  5  1 
2 12
720
2 12 12 12
6
This means that a Lagrange polynomial through 6 points will integrate exactly.
Figure 1 7 points with intervals h, 5 internal points, and 6 half interval points.
h  ( E  B) / ( N  1)
3
Document1
1
05/28/16
A very common error in end point trap rule is an incorrect evaluation of the point at either x 0 or xN. When this happens the integral
has an error equal to (f(x0)-factual(x0))*h. This is determined by plotting ai as a function of h, rather than h 2. A straight line for three
values does not mean that this is a reasonable extrapolation. It means that there is an error in a single function value.
4
Download