x:undefined,y:undefinedRectangle0.0003.1426.284-6-5-4-3-2-10123456xyRectanglex:undefined,y:undefinedTrapezoid0.0003.1426.284-6-5-4-3-2-10123456xyTrapezoidx:undefined,y:undefinedParabola0.0003.1426.284-6-5-4-3-2-10123456xyParabola

Integral: algorithms of numerical approximation

As an example for numerical integration we choose the sine function y = sin x ;  its graph is shown in blue. The definite integral is to be calculated between an initial abscissa x1 and an end abscissa x2.
The analytic solution of the indefinite integral (antiderivative) is
y = ∫ sinxdx  = -cos x +C
Its graph is shown in red, with C as the initial value at the initial abscissa.
The analytic definite integral is -(cos x2-cosx1). It corresponds to a point on the analytic curve at the end abscissa x2.
In the approximate numerical calculation the interval x2 - x1 is divided into n sub intervals of width delta. For clear demonstration of the principle n = 2 is chosen. Arrows show the value of the function in the three points of the double interval 2 delta.
Three numerical algorithms are visualized in three windows. They differ in how the approximative value of the function is defined between consecutive points in the sub interval delta.
1.)  Rectangle approximation: y is taken as constant within the interval. The contribution of one interval is delta * y1.
2.) Trapezoid approximation:  y is taken as the mean value within the interval. Its contribution is delta*(y1+y2)/2.
3.) Parabola approximation:  the function in two consecutive intervals is approximated by a second order parabola through both end points and the middle point of the double interval (a parabola needs three points to be uniquely defined). The contribution of the double integral, derived as a surprisingly simple formula, is  2*delta*1/6(y1+4y2+y3).
In principle one can increase the precision of the parabola algorithm still further by using higher order parabolas, with correspondingly more sub intervals of the definition range. As the second order is already very good, higher order approximations have no great practical importance. (For fun and exercise derive the formula for a third order parabola!)
The simulation calculates the sum of two approximating intervals of width delta using the three algorithms. Their respective values are represented by the green points.
A first slider defines the interval delta, a second one the initial abscissa x1, reset defines delta = 1 and x1 = 0.5.


Title and author:

Integral: algorithms of numerical approximation
Logo

author image Dieter Roess - WEH-Foundation; Fremont Teng; Loo Kang Wee