Definite integral by Simpson's method online. Trapezoidal method

To find a definite integral using the trapezoid method, the area of ​​a curvilinear trapezoid is also divided into n rectangular trapezoids with heights h and bases y 1, y 2, y 3,..y n, where n is the number of the rectangular trapezoid. The integral will be numerically equal to the sum of the areas of rectangular trapezoids (Figure 4).

Rice. 4

n - number of splits

The error of the trapezoid formula is estimated by the number

The error of the trapezoid formula decreases faster with growth than the error of the rectangle formula. Therefore, the trapezoid formula allows you to get more accuracy than the rectangle method.

Simpson formula

If for each pair of segments we construct a polynomial of the second degree, then integrate it on the segment and use the additivity property of the integral, then we obtain the Simpson formula.

In Simpson's method for calculating the definite integral, the entire integration interval is divided into subintervals of equal length h=(b-a)/n. The number of partition segments is an even number. Then, on each pair of adjacent subintervals, the subintegral function f(x) is replaced by a Lagrange polynomial of the second degree (Figure 5).

Rice. 5 The function y=f(x) on the segment is replaced by a 2nd order polynomial

Consider the integrand on the interval. Let us replace this integrand with a second-degree Lagrange interpolation polynomial coinciding with y= at the points:

Let's integrate on the interval:

We introduce a change of variables:

Given the replacement formulas,


After integrating, we get the Simpson formula:

The value obtained for the integral coincides with the area of ​​a curvilinear trapezoid bounded by an axis, straight lines, and a parabola passing through points. On a segment, Simpson's formula will look like:

In the parabola formula, the value of the function f (x) at odd split points x 1, x 3, ..., x 2n-1 has a coefficient of 4, at even points x 2, x 4, ..., x 2n-2 - coefficient 2 and at two boundary points x 0 =a, x n =b - coefficient 1.

The geometric meaning of Simpson's formula: the area of ​​a curvilinear trapezoid under the graph of the function f(x) on a segment is approximately replaced by the sum of the areas of the figures lying under the parabolas.

If the function f(x) has a continuous derivative of the fourth order, then the absolute value of the error of the Simpson formula is no more than

where M is the largest value on the segment. Since n 4 grows faster than n 2 , the error of Simpson's formula decreases with increasing n much faster than the error of the trapezoid formula.

We calculate the integral

This integral is easy to calculate:

Let's take n equal to 10, h=0.1, calculate the values ​​of the integrand at the partition points, as well as half-integer points.

According to the formula of the middle rectangles, we get I straight = 0.785606 (the error is 0.027%), according to the trapezoid formula I trap = 0.784981 (the error is about 0.054. When using the method of right and left rectangles, the error is more than 3%.

To compare the accuracy of the approximate formulas, we calculate once again the integral

but now by the Simpson formula for n=4. We divide the segment into four equal parts with points x 0 \u003d 0, x 1 \u003d 1/4, x 2 \u003d 1/2, x 3 \u003d 3/4, x 4 \u003d 1 and calculate approximately the values ​​of the function f (x) \u003d 1 / ( 1+x) at these points: y 0 =1.0000, y 1 =0.8000, y 2 =0.6667, y 3 =0.5714, y 4 =0.5000.

By Simpson's formula, we get

Let us estimate the error of the result obtained. For the integrand f(x)=1/(1+x) we have: f (4) (x)=24/(1+x) 5 , whence it follows that on the segment . Therefore, we can take M=24, and the result error does not exceed 24/(2880 4 4)=0.0004. Comparing the approximate value with the exact one, we conclude that the absolute error of the result obtained by the Simpson formula is less than 0.00011. This is in accordance with the error estimate given above and, in addition, indicates that the Simpson formula is much more accurate than the trapezoid formula. Therefore, the Simpson formula for the approximate calculation of definite integrals is used more often than the trapezoid formula.

The problem arises of the numerical calculation of a definite integral, which is solved with the help of formulas called quadrature.

Recall the simplest formulas for numerical integration.

Let us calculate the approximate numerical value of . We divide the integration interval [а, b] into n equal parts by dividing points
, called nodes of the quadrature formula. Let the values ​​in the nodes be known
:


Value

is called the integration interval or step. Note that in the practice of -calculations, the number i is chosen small, usually it is not more than 10-20. On a partial interval

the integrand is replaced by the interpolation polynomial


which approximately represents the function f(x) on the interval under consideration.

a) Keep only one first term in the interpolation polynomial, then


The resulting quadratic formula

called the formula of rectangles.

b) Keep the first two terms in the interpolation polynomial, then

(2)

Formula (2) is called the trapezoid formula.

c) Integration interval
we divide into an even number of 2n equal parts, while the integration step h will be equal to . On the interval
of length 2h, we replace the integrand with an interpolation polynomial of the second degree, i.e., we keep the first three terms in the polynomial:

The resulting quadrature formula is called Simpson's formula

(3)

Formulas (1), (2) and (3) have a simple geometric meaning. In the formula of rectangles, the integrand f(x) on the interval
is replaced by a straight line segment y \u003d uk, parallel to the x-axis, and in the trapezoid formula - by a straight line segment
and the area of ​​a rectangle and a rectilinear trapezoid is calculated, respectively, which are then summed up. In Simpson's formula, the function f(x) on the interval
length 2h is replaced by a square trinomial - a parabola
the area of ​​a curvilinear parabolic trapezoid is calculated, then the areas are summed up.

CONCLUSION

In conclusion, I would like to note a number of features of the application of the methods discussed above. Each method for the approximate solution of a definite integral has its advantages and disadvantages, depending on the task at hand, specific methods should be used.

Variable substitution method is one of the main methods for calculating indefinite integrals. Even when we integrate by some other method, we often have to resort to a change of variables in intermediate calculations. The success of the integration depends to a large extent on whether we can find such a good change of variables that would simplify the given integral.

In essence, the study of integration methods comes down to finding out what kind of change of variable should be made for one form or another of the integrand.

Thus, integration of every rational fraction reduces to integrating a polynomial and a few simple fractions.

The integral of any rational function can be expressed in terms of elementary functions in the final form, namely:

    through logarithms - in cases of the simplest fractions of type 1;

    through rational functions - in the case of simple fractions of type 2

    through logarithms and arctangents - in the case of simple fractions of type 3

    through rational functions and arctangents - in the case of the simplest fractions of type 4. The universal trigonometric substitution always rationalizes the integrand, but often it leads to very cumbersome rational fractions, for which, in particular, it is practically impossible to find the roots of the denominator. Therefore, if possible, partial substitutions are used, which also rationalize the integrand and lead to less complex fractions.

Newton–Leibniz formula is a general approach to finding definite integrals.

As for the methods for calculating definite integrals, they practically do not differ from all those methods and methods.

The same applies substitution methods(change of variable), the method of integration by parts, the same methods of finding antiderivatives for trigonometric, irrational and transcendental functions. The only peculiarity is that when applying these techniques, it is necessary to extend the transformation not only to the sub-integral function, but also to the limits of integration. When changing the integration variable, remember to change the integration limits accordingly.

Well from the theorem, the continuity condition of the function is a sufficient condition for the integrability of the function. But this does not mean that the definite integral exists only for continuous functions. The class of integrable functions is much wider. So, for example, there is a definite integral of functions that have a finite number of discontinuity points.

The calculation of a definite integral of a continuous function using the Newton-Leibniz formula is reduced to finding an antiderivative, which always exists, but is not always an elementary function or a function for which tables are compiled that make it possible to obtain the value of the integral. In numerous applications, the integrable function is given in a table, and the Newton-Leibniz formula is not directly applicable.

If you want the most accurate result, ideal simpson's method.

From the above studied, the following conclusion can be drawn that the integral is used in such sciences as physics, geometry, mathematics and other sciences. With the help of the integral, the work of the force is calculated, the coordinates of the center of mass, the path traveled by the material point are found. In geometry, it is used to calculate the volume of a body, find the length of an arc of a curve, etc.

In this method, it is proposed to approximate the integrand on a partial interval by a parabola passing through the points
(x j , f(xj)), where j = i-1; i-0.5; i, that is, we approximate the integrand by the Lagrange interpolation polynomial of the second degree:

(10.14)

After integrating, we get:

(10.15)

That's what it is simpson's formula or the formula of parabolas. On the segment
[a, b] Simpson's formula takes the form

(10.16)

A graphical representation of Simpson's method is shown in fig. 2.4.

Rice. 10.4. Simpson method

Let's get rid of fractional indices in expression (2.16) by renaming the variables:

(10.17)

Then Simpson's formula takes the form

(10.18)

The error of formula (2.18) is estimated by the following expression:

, (10.19)

where h n = b-a, . Thus, the error of Simpson's formula is proportional to O(h 4).

Comment. It should be noted that in the Simpson formula, the integration segment is necessarily divided into even number of intervals.

10.5. Calculation of definite integrals by methods
Monte Carlo

The previously discussed methods are called deterministic , that is, devoid of the element of chance.

Monte Carlo Methods(MMK) are numerical methods for solving mathematical problems by modeling random variables. MCM allow to successfully solve mathematical problems caused by probabilistic processes. Moreover, when solving problems that are not associated with any probabilities, one can artificially come up with a probabilistic model (and even more than one) that allows solving these problems. Consider the calculation of the definite integral

(10.20)

When calculating this integral using the formula of rectangles, the interval [ a, b] split into N identical intervals, in the middle of which the values ​​of the integrand were calculated. By calculating the function values ​​at random nodes, you can get a more accurate result:

(10.21)

(10.22)

Here γ i is a random number uniformly distributed over the interval
. The error in calculating the MMK integral ~ , which is much larger than that of the previously studied deterministic methods.

On fig. 2.5 shows a graphical implementation of the Monte Carlo method for calculating a single integral with random nodes (2.21) and (2.22).


(2.23)

Rice. 10.6. Monte Carlo integration (2nd case)

As seen in fig. 2.6, the integral curve lies in the unit square, and if we can get pairs of random numbers uniformly distributed over the interval, then the obtained values ​​(γ 1, γ 2) can be interpreted as the coordinates of a point in the unit square. Then, if there are enough of these pairs of numbers, we can approximately assume that
. Here S is the number of pairs of points that fall under the curve, and N is the total number of pairs of numbers.

Example 2.1. Calculate the following integral:

The problem was solved by various methods. The results obtained are summarized in table. 2.1.

Table 2.1

Comment. The choice of the table integral allowed us to compare the error of each method and find out the influence of the number of partitions on the accuracy of calculations.

11 APPROXIMATE SOLUTION OF NONLINEAR
AND TRANSCENDENT EQUATIONS

Calculation of integrals using the formulas of rectangles, trapezoids and Simpson's formula. Estimation of errors.

Guidelines on topic 4.1:

Calculation of integrals by formulas of rectangles. Error estimate:

The solution of many technical problems is reduced to the calculation of certain integrals, the exact expression of which is difficult, requires lengthy calculations and is not always justified in practice. Here, their approximate value is quite sufficient. For example, you need to calculate the area bounded by a line whose equation is unknown, the axis X and two ordinates. In this case, you can replace this line with a simpler one, for which the equation is known. The area of ​​the curvilinear trapezoid thus obtained is taken as the approximate value of the desired integral. Geometrically, the idea behind the method of calculating the definite integral using the formula of rectangles is that the area of ​​a curvilinear trapezoid A 1 ABB 1 is replaced by the area of ​​an equal area rectangle A 1 A 2 B 1 B 2, which, according to the mean value theorem, is equal to

Where f(c)--- rectangle height A 1 A 2 B 1 B 2, which is the value of the integrand at some intermediate point c(a< c

It is practically difficult to find such a value with, at which (b-a)f(c) would be exactly equal to . To obtain a more accurate value, the area of ​​\u200b\u200ba curvilinear trapezoid is divided into n rectangles whose heights are equal y 0 , y 1 , y 2 , …,y n -1 and foundations.

If we summarize the areas of rectangles that cover the area of ​​a curvilinear trapezoid with a disadvantage, the function is non-decreasing, then instead of the formula, the formula is used

If in excess, then

Values ​​are found from equalities. These formulas are called rectangle formulas and give an approximate result. With the increase n the result becomes more accurate.

Example 1 . Calculate from the formula of rectangles

We divide the interval of integration into 5 parts. Then . Using a calculator or a table, we find the values ​​​​of the integrand (with an accuracy of 4 decimal places):

According to the formula of rectangles (with a disadvantage)

On the other hand, according to the Newton-Leibniz formula

Let's find the relative calculation error using the formula of rectangles:

Calculation of integrals by trapezoid formulas. Error estimate:

The geometric meaning of the following method for the approximate calculation of integrals is that finding the area of ​​an approximately equal-sized "rectilinear" trapezoid.

Let it be necessary to calculate the area A 1 AmBB 1 curvilinear trapezoid, expressed by the formula .

Let's replace the arc AmB chord AB and instead of the area of ​​a curvilinear trapezoid A 1 AmBB 1 calculate the area of ​​the trapezoid A 1 ABB 1: , where AA 1 and BB 1 - the base of the trapezoid, and A 1 V 1 is its height.


Denote f(a)=A 1 A,f(b)=B 1 B. trapezoid height A 1 B 1 \u003d b-a, square . Hence, or

This so-called small trapezoid formula.

To construct the Simpson formula, we first consider the following problem: calculate the area S of a curvilinear trapezoid bounded from above by the graph of the parabola y \u003d Ax 2 + Bx + C, from the left by the straight line x \u003d - h, from the right by the straight line x \u003d h and from below by the segment [-h; h]. Let the parabola pass through three points (Fig. 8): D (-h; y 0) E (0; y 1) and F (h; y 2), and x 2 - x 1 = x 1 - x 0 = h . Hence,

x 1 \u003d x 0 + h \u003d 0; x 2 = x 0 + 2h.

Then the area S is equal to the integral:

We express this area in terms of h, y 0 , y 1 and y 2 . To do this, we calculate the coefficients of the parabola A, B, C. From the condition that the parabola passes through the points D, E and F, we have:

Solving this system, we get: C = y 1 ; A=

Substituting these values ​​A and C into (3), we obtain the desired area

Let us now turn to the derivation of Simpson's formula for calculating the integral

To do this, we divide the integration segment into 2n equal parts of length

At the division points (Fig. 4). a \u003d x 0, x 1, x 2, ..., x 2n-2, x 2n-1, x 2n \u003d b,

We calculate the values ​​of the integrand f: y 0 , y 1 , y 2 , ...,y 2n-2 , y 2n-1 , y 2n , de y i = f(x i), x i = a + ih (i = 0, 1, 2,...,2n).

On the segment, we replace the integrand with a parabola passing through the points (x 0; y 0), (x 1; y 1) and (x 2; y 2), and to calculate the approximate value of the integral from x 0 to x 2, we use the formula (4 ). Then (the shaded area in Fig. 4):

Similarly, we find:

................................................

Adding the resulting equalities, we have:

Formula (5) is called generalized Simpson formula or parabola formula, since when deriving it, the graph of the integrand on a partial segment of length 2h is replaced by a parabola arc.

Job assignment:

1. As directed by the teacher or in accordance with an option from tables 4 tasks (see Appendix) to take the conditions - the integrand, the limits of integration.

2. Draw up a flowchart of the program and a program that should:

Request the accuracy of calculating a definite integral, the lower and upper limits of integration;

Calculate the given integral by methods: for options 1,4,7, 10… - right, for options 2,5,8,… - average; for options 2,5,8,… - left rectangles. Output the number of partitions of the integration range at which the specified calculation accuracy is achieved;

Calculate the given integral using the trapezoid method (for even options) and Simpson's method (for odd options).

Output the number of partitions of the integration range at which the specified calculation accuracy is achieved;

Output the values ​​of the control function for the given value of the argument and compare with the calculated values ​​of the integral. Draw conclusions.


test questions

1. What is a definite integral?

2. Why, along with analytical methods, numerical methods for calculating definite integrals are used.

3. What is the essence of the main numerical methods for calculating definite integrals.

4. Influence of the number of partitions on the accuracy of calculating a definite integral by numerical methods.

5. How to calculate the integral by any method with a given accuracy?