Sunday, July 14, 2013

Integration: Left-hand Rule against Trapezoid Rule

Two integrating heavyweights, the left-hand rule and the trapezoidal rule, met within a computer terminal today. Both were compiled, run, and compared against one another. Both members emerged relative equals.
The most recent class assignment was to create programs that found the integral value of an equation, f(x)=4-(x-4)^2. Two separate methods of finding the integral value, the left-hand rule and the trapezoidal rule, were permitted. The objective then relied on incorporating both rules into functions which could be utilized within a program. Though progress was rocky, painful, and harrowing, at last I had assembled programs (with assistance from a friend) which carried out the designated tasks.
Difficulty rested not in the premise of functions themselves, but in utilizing functions to perform calculus. I have yet to take a calculus class in school, and thus I was having to learn a new mathematical concept alongside computer science. However, I have emerged with a less vague understanding of integration than I previously possessed, and two rather spiffy programs.
When executed, both methods yield near identical results. Both were programmed to integrate with either 4000 rectangles or trapezoids. The optimal values, minimal error, and optimal value for n (number of rectangles or trapezoids) may be considered below.

Left-hand Rule:
integral value = 10.667030
minimum err = 0.000000
Optimal n = 1025
Optimal val = 10.666667
Trapezoid Rule:
The integral value = 10.667030
minimum err = 0.000000
Optimal n = 2049
Optimal val = 10.666667


 As can be seen, both yield identical integral values. However, they differ over the optimal number for n, with the trapezoid rule finding better success with a higher n-value.

No comments:

Post a Comment