Many integrals are to difficult to solve
out analytically. One such example is the chirp function:
(4)
The inability of the chirp function to be solved analytically
makes it a prime candidate for computational analysis.
Here we allow the computer to sum extremely high numbers of
intervals, in an attempt to achieve a more accurate
result. These methods allow us to estimate the value of
the chirp function with extremely high precision.
Trapezoidal Method [3]
(5)
Where h is the width of each
interval. The Trapezoidal method breaks each segment up
into a trapezoid then sums them together to estimate the
integral. The trapezoidal method converges quickly for
periodic functions, such as cosine.
Simpson's Method [4]
(6)
Where h is the width of each
interval. Simpson's method applies a local quadratic fit
to the function at each segment. It then sums all the
segments together to estimate the integral.
Program 1 was used
to output values, corresponding to the chirp function, into a data
file. From their the information was plotted in
gnuplot. This code was also used to generate the plot for
the dampened chirp function and the dampened chirp function with
cos (x^3) replaced by cos(x^5). Commenting out and in the
proper functions allowed this code to be used in generating values
for the exponential too. Program 1
calculated integrals from 0 to 6 using both the Trapezoidal and
Simpson's methods; with the number of terms being 3001 (max_in).
Program 2 used the Trapezoidal method to
calculate the integral of the function from -6 to 6, using 600,000
terms. It has already been modified to print out the running
sum for the trapez function as the sum is accumulating: shown by figure 4.
Figure 1 shows
how the Trapezoidal and Simpson methods the integral of the
exponential function: e^(-x). Both methods quickly fall
to zero, as the number of terms increases. This is
expected since figure 1 represents
the error each method holds with respect to the number of
terms being added.
Figures 2 and 3 show how the Trapezoidal and
Simpson's methods of integrating the dampened chirp function
compare. Figure 2 uses the
chirp function including the exponential damping term. Figure 3 uses the same integrand with
t^3 replaced by t^5. The largest difference in these
figures is how many intervals they take before
converging. Both figure 2 and
3 appear noisy at first since each
successive term added in the integration causes a drastic
variation in the overall sum (subtractive cancellation -
alternating signs). As the number of intervals, n,
increases each integral converges to some value. In both
figures the Trapezoidal method converges to a stable answer
quicker than the Simpson method. This is in direct
conflict with the prediction made in "Computational Physics"
by Landau and Paez [1]; which claims the
Simpson's method should be more accurate. Since the
Trapezoidal method converges faster it is the one chosen to
calculate the total energy per unit area.