Module 1 : Introductory Programming
Chapter 6 : Numerical integration and differential equations
 
6.3 Program for Simpson’s Rule
Programming for the formula of eq. (6.10) is very straightforward. We need an odd numbered data set of where is odd. If  is even, the integration between the last two data points can be done by trapezoidal rule.

(Since do loops normally start from I = 1,n, the notation has been switched from x0, x1…… to x1, x2….)

c These programs are for well defined functions. Same logic will
c apply for equally spaced data: x(i), y(i), i = 1,2,......N (N odd)
c If n is even, use trapezoidal rule for two points either at the end
c or at the beginning, wherever the values of y(i) are small
c SIMPSON’S METHOD OD INTEGRATION (ARRAY GIVEN)
         PROGRAM Simpson
cSimpson's method of integration
dimension x(1000),y(1000)
write(*,*)'To find the value of integral of a function using
1  Simpsons rule. '
write(*,*)'Enter the limits of integration:'
read(*,*)a,b
write(*,*)'Enter the number of subintervals(an even no.) :'
read(*,*)n
h=(b-a)/n
x(1)=a
y(1)=f(x(1))
DO 10 i=2,n+1
x(i)=x(i-1)+h
y(i)=f(x(i))
10       continue
s=y(1)+y(n+1)
        DO 20 i=2,n,2
         s=s+4*y(i)
20       continue
        DO 30 i=3,n-1,2
           s=s+2*y(i)
30         continue
        s=h*s/3
write(*,40)s
40      format(1x,'The value of the integral is: ',F10.4)
        STOP
        END
function f(x)
f=sin(x)
c   This can be generalised to any other function or simply
c   a set of data points x(i) and y(i), i = 1, n
c   After testing for a few functions, you can use the program
c   for any set of data
return
       END

 
6.4 Differential equations
We will consider only first order differential equations. Higher order differential equations and partial differential equations will not be considered although important applications of numerical methods in chemistry involve not only higher order equations, but also equations involving both derivatives and integrals!

A typical first order differential equation can be represented by

(6.11)