FORTRAN 77 Lesson 7: 1 Numerical Integration
FORTRAN 77 Lesson 7: 1 Numerical Integration
Reese Haywood
Ayan Paul
Numerical Integration
1.1
Trapezoidal Rule
If we are given the function that represents the curve, we can evaluate the
function at points spaced along the interval of interest. If we join the points
on the curve with straight line segments, we form a group of trapezoids whose
combined areas approximate the are under the curve. The closer the points
are together on the curve the more trapezoids there are in the interval, and
thus the more accurate will be our approximation to the integral.
Recall that the area of a trapezoid is equal to one-half the base times the
sum of the two heights (or sides): area = 12 base(height1 + height2). Thus,
the area of the trapezoid is computed using the pair of points (x1 , y1 ) and
(x2 , y2): A = 21 (x2 x1 )(y1 + y2 ). If all of our points are equally spaced, then
(x2 x1 ) is a constant, and if there are N trapezoids that represent the curve
then the integral can be approximated by:
N
X
base
(y1 + 2
yk + yN +1 )
2
k=2
(1)
together or far apart. Another possibility is that the points are experimentally collected; in this case, we have discrete x and y values, and we cannot
change the size of the base, it is fixed by x, but this does not keep us from
using the trapezoid rule.
1.2
Simpsons Rule
The Simpsons Rule (or Simpsons 13 Rule) makes the assumption that the
function can be approximated by a series of overlapping second order curves.
Thus we always need even number of intervals to do an integral by this
method. The detailed derivation of this method can be found in any book
on Numerical Integration or Statistics. The formula for the integration is
Z xN+1
h
y(x)dx = [y1 + 4 (y2 + y4 + . . .) + 2 (y3 + y5 + . . .) + yN +1 ] (2)
3
x1
with N odd. The Simpsons Rule is more accurate as it uses second order approximation as compared to the first order approximation used by
the Trapezoidal Rule and thus uses more computing time and resources.
For most problems the Trapezoidal Rule will be good enough, however, you
might sometime have to appeal to the Simpsons Rule for more complicated
integrals.
(3)
(4)
(5)
(6)
(7)
(8)
2.1
The Euler method was the first method used to find numerical solutions to
differential equaitons. In spite of the fact that it is rarely used in practice, we
need to study it because it serves as a model for more complicated methods
such as the Rung-Kutta method, an all purpose method we will write our
program with.
Suppose we want to construct a solution to equation (5) above. If we
know the solution exactly, and that it is twice differentiable, we can write
the Taylor expansion as
y(t1 ) = y(t0 ) + (t1 t0 )y (t0 ) +
3
(t1 t0 )2
y (t0 )
2
(9)
h2
y (t0 )
2
(10)
where we have just substituted equation (5) evaluated at (t0 , y0 ) for y (t0 )
and also substituted h for (t1 t0 ). With h small this becomes simply
y(t1 ) y(t0 ) + hf (t0 , Y0 )
(11)
(12)
(13)
2.2
(14)
where
a1,n = f (tn , Yn )
h
h
a2,n = f (tn + , Yn + a1,n )
2
2
h
h
a3,n = f (tn + , Yn + a2,n )
2
2
a4,n = f (tn + h, Yn + h a3,n )
4
(15)
2.3
(16)
t y = 2et 1 t
0.0
1.00000 00
0.1
1.11034 18
0.2
1.24280 55
0.3
1.39971 76
0.4
1.58364 94
0.5
1.79744 25
0.6
2.04423 76
3. Writing the the acceleration of a mass under the influence of Hookes
Law we get the following second order differential equation.
x + 2 x = 0
(17)
k
where 2 = m
. We already know the answer, upto normalization constants and phase angles. The general solution is
x = C1 cos t + C2 sin t
(18)
The initial conditions determine which function cos or sin gives the
final answer. We will let = 1. Then we have the equation
d
dt
x! + x = 0
dx
+x = 0
dt
(19)