Trapezoidal formula for approximate calculation of definite integrals. An example of calculating a definite integral using the trapezoid method

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) --- height rectangle 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 . Therefore, or

This so-called small trapezoid formula.

Example 2. River width 26 m, depth measurements in the cross section of the river every 2 m gave the following results.


Trapezoidal method is one of the numerical integration methods. It allows you to calculate definite integrals with a predetermined degree of accuracy.

First, we describe the essence of the trapezoid method and derive the trapezoid formula. Next, we write an estimate of the absolute error of the method and analyze in detail the solution of typical examples. In conclusion, let's compare the method of trapezoids with the method of rectangles.

Page navigation.

The essence of the trapezoid method.

Let us set ourselves the following task: let us need to approximately calculate the definite integral , where the integrand y=f(x) is continuous on the interval .

Let's divide the segment into n equal intervals of length h with points . In this case, the partition step is found as the nodes are determined from the equality .

Consider the integrand on elementary intervals .

Four cases are possible (the figure shows the simplest of them, to which everything reduces as n increases infinitely):


On every segment let's replace the function y=f(x) with a line segment passing through the points with coordinates and . We depict them in the figure with blue lines:


As an approximate value of the integral, we take the expression , that is, let's take .

Let's find out what the written approximate equality means in a geometric sense. This will make it possible to understand why the considered method of numerical integration is called the trapezoidal method.

We know that the area of ​​a trapezoid is found as the product of half the sum of the bases times the height. Therefore, in the first case, the area of ​​a curvilinear trapezoid is approximately equal to the area of ​​a trapezoid with bases and height h, in the latter case, the definite integral is approximately equal to the area of ​​the trapezoid with bases and height h taken with a minus sign. In the second and third cases, the approximate value of the definite integral is equal to the difference between the areas of the red and blue regions shown in the figure below.


Thus, we have come to the essence of the trapezoid method, which consists in representing a definite integral as a sum of integrals of the form on each elementary interval and in the subsequent approximate replacement .

Trapezoidal formula.

As you can see, the required accuracy is achieved.

A little about errors.

Theoretically, the approximate value of a definite integral, calculated by the trapezoid method, tends to the true value at . However, one should take into account the fact that most intermediate calculations are carried out approximately, and for large n, the computational error begins to accumulate.

Let's take a look at the estimates of the absolute errors of the trapezoid method and the method of mean rectangles .

One can expect half the error for a given n when using the method of rectangles with the same amount of computational work, that is, using this method is, as it were, preferable. This is true when the values ​​of the function at the midpoints of the elementary segments are known. But sometimes integrable functions are specified not analytically, but as a set of values ​​at the nodes. In this case, we will not be able to apply the formula of middle rectangles, but we will be able to use the trapezoid method.

The methods of right and left rectangles are inferior to the method of trapezoids in the accuracy of the result for a given number of partitions of the integration segment.

How to calculate a definite integral
using the trapezoid formula and the Simpson method?

Numerical methods is a fairly large section of higher mathematics and serious textbooks on this topic have hundreds of pages. In practice, in tests, some tasks are traditionally proposed for solving by numerical methods, and one of the common tasks is approximate calculation definite integrals. In this article, I will consider two methods for the approximate calculation of a definite integral − trapezoidal method and simpson's method.

What do you need to know to master these methods? It sounds funny, but you may not be able to take integrals at all. And even do not understand what integrals are. Of the technical means, you will need a microcalculator. Yes, yes, we are waiting for routine school calculations. Better yet, download my semi-automatic calculator for the trapezoid method and the Simpson method. The calculator is written in Excel and will allow you to reduce the time for solving and processing tasks tenfold. A video manual is included for Excel teapots! By the way, the first video with my voice.

First, let's ask ourselves the question, why do we need approximate calculations at all? It seems to be possible to find the antiderivative of the function and use the Newton-Leibniz formula, calculating the exact value of a certain integral. As an answer to the question, let's immediately consider a demo example with a picture.

Calculate a definite integral

Everything would be fine, but in this example the integral is not taken - before you is not taken, the so-called integral logarithm. Does this integral even exist? Let's depict the graph of the integrand in the drawing:

Everything is fine. The integrand is continuous on the interval and the definite integral is numerically equal to the shaded area. Yes, that's just one snag - the integral is not taken. And in such cases, numerical methods come to the rescue. In this case, the problem occurs in two formulations:

1) Calculate the definite integral approximately , rounding the result to a certain decimal place. For example, up to two decimal places, up to three decimal places, etc. Let's say you get an approximate answer of 5.347. In fact, it may not be entirely correct (actually, let's say the more accurate answer is 5.343). Our task is only in that to round the result to three decimal places.

2) Calculate the definite integral approximately, with a certain precision. For example, calculate the definite integral approximately with an accuracy of 0.001. What does it mean? This means that we must find such an approximate value that modulo (one way or the other) differs from the truth by no more than 0.001.

There are several basic methods for the approximate calculation of a definite integral that occurs in problems:

The segment of integration is divided into several parts and a stepped figure is constructed, which is close in area to the desired area:

Do not judge strictly by the drawings, the accuracy is not perfect - they only help to understand the essence of the methods.

The idea is similar. The integration segment is divided into several intermediate segments, and the graph of the integrand approaches broken line line:

So our area (blue shading) is approximated by the sum of the areas of the trapezoids (red). Hence the name of the method. It is easy to see that the trapezoid method gives a much better approximation than the rectangle method (with the same number of partition segments). And, of course, the more smaller intermediate segments we consider, the higher the accuracy will be. The trapezoid method is encountered from time to time in practical tasks, and in this article several examples will be analyzed.

Simpson's method (parabola method). This is a more perfect way - the graph of the integrand is approached not by a broken line, but by small parabolas. How many intermediate segments - so many small parabolas. If we take the same three segments, then the Simpson method will give an even more accurate approximation than the rectangle method or the trapezoid method.

I don’t see the point in building a drawing, since visually the approximation will be superimposed on the graph of the function (the broken line of the previous paragraph - and even then it almost coincided).

The task of calculating a definite integral using the Simpson formula is the most popular task in practice. And the method of parabolas will be given considerable attention.

How to calculate a definite integral using the trapezoid method?

First, the general formula. Perhaps it will not be clear to everyone and not immediately ... Yes, Karlsson is with you - practical examples will clarify everything! Calm. Only calmness.

Consider the definite integral , where is a function continuous on the segment . Let us divide the segment into equal segments:
. In this case, obviously: (lower limit of integration) and (upper limit of integration). points also called knots.

Then the definite integral can be calculated approximately by the trapezoid formula:
, where:
step;
are the values ​​of the integrand at points .

Example 1

Calculate an approximately definite integral using the trapezoid formula. Round the results to three decimal places.

a) Dividing the integration segment into 3 parts.
b) Dividing the segment of integration into 5 parts.

Solution:
a) Especially for dummies, I tied the first paragraph to the drawing, which clearly demonstrated the principle of the method. If it will be difficult, look at the drawing in the course of the comments, here is a piece of it:

By condition, the integration segment must be divided into 3 parts, that is, .
Calculate the length of each segment of the partition: . Parameter, I remind you, is also called step.

How many points (partition nodes) will there be? There will be one more than the number of segments:

Well, the general formula of trapezoids is reduced to a pleasant size:

For calculations, you can use a regular microcalculator:

Note that, in accordance with the condition of the problem, all calculations should be rounded to the 3rd decimal place.

Finally:

From a geometric point of view, we calculated the sum of the areas of three trapezoids (see picture above).

b) We divide the integration segment into 5 equal parts, that is, . Why is this needed? So that Phobos-Grunt does not fall into the ocean - by increasing the number of segments, we increase the accuracy of calculations.

If , then the trapezoid formula takes the following form:

Let's find the partitioning step:
, that is, the length of each intermediate segment is 0.6.

When finishing the task, it is convenient to draw up all calculations with a calculation table:

In the first line we write "counter"

I think everyone can see how the second line is formed - first we write down the lower integration limit , we get the remaining values ​​by successively adding the step .

By what principle the bottom line is filled, too, I think, almost everyone understood. For example, if , then . What is called, consider, do not be lazy.

As a result:

Well, there really is a clarification, and a serious one! If for 3 segments of the partition the approximate value was, then for 5 segments . Thus, with a high degree of certainty, it can be argued that, at least .

Example 2

Calculate an approximately defined integral using the trapezoid formula with an accuracy of two decimal places (up to 0.01).

Solution: Almost the same problem, but in a slightly different formulation. The fundamental difference from Example 1 is that we we don't know, INTO HOW MANY segments to split the integration segment in order to get two correct decimal places. In other words, we do not know the value of .

There is a special formula that allows you to determine the number of partition segments to ensure that the required accuracy is achieved, but in practice it is often difficult to apply. Therefore, it is advantageous to use a simplified approach.

First, the integration segment is divided into several large segments, as a rule, into 2-3-4-5. Let us divide the integration segment, for example, into the same 5 parts. The formula is already familiar:

And the step, of course, is also known:

But another question arises, to what digit should the results be rounded? The condition does not say anything about how many decimal places to leave. The general recommendation is: 2-3 digits must be added to the required accuracy. In this case, the required accuracy is 0.01. According to the recommendation, after the comma, for fidelity, we leave five characters (four could have been):

As a result:
, we denote the approximation by .

After the primary result, the number of segments double. In this case, it is necessary to divide into 10 segments. And when the number of segments grows, then a bright thought comes to mind that poking fingers into a microcalculator is already somehow tired. Therefore, I once again propose to download and use my semi-automatic calculator (link at the beginning of the lesson).

For the trapezoid formula takes the following form:

In the paper version, the entry can be safely transferred to the next line.

Let's calculate the partition step:

The results of the calculations are summarized in the table:


When finishing in a notebook, it is advantageous to turn a long table into a two-story table.

As a result:

Now we calculate the discrepancy between the approximations:

Here we use the modulo sign, since we are interested in absolute difference, and not which result is greater, but which is less.

As for further actions, I personally encountered 2 solutions in practice:

1) The first way is a “head-to-head comparison”. Since the resulting error estimate more than the required accuracy: , then it is necessary to double the number of segments of the partition up to and calculate already . With the help of an Excel calculator, the finished result can be obtained in a matter of seconds:. Now we estimate the error again: . Score received less than the required accuracy: , therefore, the calculations are completed. It remains to round the last (most accurate) result to two decimal places and give an answer.

2) Another, more efficient method is based on the use of the so-called Runge rules, according to which we are wrong in estimating the definite integral, in fact, by no more than . In our problem: , thus, the need for calculation disappears. However, for the speed of the solution in this case, we had to pay with accuracy: . Nevertheless, this result is acceptable, since our “error limit” is exactly one hundredth.

What to choose? Focus on your training manual or the preferences of the teacher.

Answer: accurate to 0.01 (when using Runge's rule).

Example 3

Calculate an approximately definite integral using the trapezoid formula with an accuracy of 0.001.

Before you is again an untaken integral (almost integral cosine). In the sample solution, at the first step, a division into 4 segments was carried out, that is, . A complete solution and an approximate sample of finishing at the end of the lesson.

How to calculate the definite integral using Simpson's formula?

If you were looking for only the Simpson method on this page, then I strongly recommend that you first read the beginning of the lesson and view at least the first example. For the reason that many ideas and techniques will be similar to the trapezoid method.

Again, let's start with the general formula
Consider the definite integral , where is a function continuous on the segment . Let us divide the segment into even amount equal segments. An even number of segments is denoted by .

In practice, segments can be:
two:
four:
eight:
ten:
twenty:
I don't remember any other options.

Attention! Number is understood as ONE NUMBER. That is, IT IS FORBIDDEN reduce, for example, by two, getting . Recording only stands for that the number of segments evenly. And there are no cuts to speak of.

So our partition looks like this:

The terms are similar to those of the trapezoidal method:
Dots are called knots.

Simpson formula for the approximate calculation of the definite integral has the following form:
, where:
- the length of each of the small segments or step;
are the values ​​of the integrand at the points .

Detailing this piling up, I will analyze the formula in more detail:
is the sum of the first and last values ​​of the integrand;
is the sum of members with even indexes multiplied by 2;
is the sum of members with odd index is multiplied by 4.

Example 4

Calculate the approximate integral using Simpson's formula to the nearest 0.001. Splitting start with two segments

The integral, by the way, is again not taken.

Solution: I immediately draw attention to the type of task - it is necessary to calculate a definite integral with a certain accuracy. What this means has already been commented on at the beginning of the article, as well as on concrete examples of the previous paragraph. As for the trapezoid method, there is a formula that will immediately allow you to determine the required number of segments (the “en” value) in order to guarantee the required accuracy. True, we will have to find the fourth derivative and solve the extremal problem. Who understood what I mean and estimated the amount of work, he smiled. However, there is no laughing matter here, finding the fourth derivative of such an integrand will no longer be a megabotan, but a clinical psychopath. Therefore, in practice, a simplified method for estimating the error is almost always used.

We start to decide. If we have two partition segments, then the nodes will be one more: . And Simpson's formula takes a very compact form:

Let's calculate the partition step:

Let's fill in the calculation table:


Once again I comment on how the table is filled:

In the top line we write the "counter" of indices

In the second line, we first write the lower limit of integration, and then successively add the step.

In the third line we enter the values ​​of the integrand. For example, if , then . How many decimal places to leave? Indeed, the condition again says nothing about this. The principle is the same as in the trapezoidal method, we look at the required accuracy: 0.001. And add an additional 2-3 digits. That is, you need to round up to 5-6 decimal places.

As a result:

The first result has been obtained. Now double number of segments up to four: . Simpson's formula for this partition takes the following form:

Let's calculate the partition step:

Let's fill in the calculation table:


In this way:

Let's find the absolute value of the difference between the approximations:

Runge's rule for Simpson's method is delicious. If when using middle rectangle method and the trapezoid method, we are given an “indulgence” of one third, now - as much as one fifteenth:
, and accuracy does not suffer here anymore:

But for the sake of completeness, I will also give a “simple” solution, where you have to take an additional step: since there is more than the required accuracy: , then it is necessary to double the number of segments again: .

Simpson's formula is growing by leaps and bounds:

Let's calculate the step:

Let's fill in the spreadsheet again:

In this way:

Note that here it is desirable to describe the calculations in more detail, since Simpson's formula is rather cumbersome, and if you immediately thump:
, then this booze will look like a hack. And with a more detailed recording, the teacher will get the favorable impression that you conscientiously erased the keys of the microcalculator for a good hour. Detailed calculations for "hard" cases are present in my calculator.

We estimate the error:

The error is less than the required accuracy: . It remains to take the most accurate approximation , round it up to three decimal places and write:

Answer: accurate to 0.001

Example 5

Calculate an approximate integral using Simpson's formula to the nearest 0.0001. Splitting start with two segments

This is a do-it-yourself example. A rough example of finishing work and an answer at the end of the lesson.

In the final part of the lesson, we will consider a couple more common examples.

Example 6

Calculate the approximate value of a definite integral using the Simpson formula, dividing the integration segment into 10 parts. Calculations are carried out with an accuracy of three decimal places.

Let the division of the segment into parts , be again taken. Approximately replace the area under the graph, lying above the partition interval, with the area of ​​the trapezoid, the parallel bases of which are the segments that specify the values ​​of the function at the ends of the interval, that is, and (see Fig.).

Then the area of ​​such a trapezoid is obviously equal to

Summing up all the areas, we get the quadrature trapezoid formula:

This is the same formula that was obtained by combining the formulas of the left and right rectangles, in which we denoted the right side by .

Note that when calculating the area of ​​each next trapezoid, it is enough to calculate the value of the function only at one new point - at the right end of the next interval, since the point was the right end of the previous segment and the value at this point has already been calculated when finding the area of ​​the previous trapezoid.

If all segments of the partition are chosen to be of the same length, then the trapezoid formula takes the form

All values ​​of the function except and occur twice in this formula. Therefore, by combining equal terms, we can write the trapezoid formula in the form

Let the function have a second derivative that preserves sign on the interval . As can be easily seen from the previous figure, the nature of the error of this quadrature formula is as follows: if , that is, if the graph is convex upwards, then and, therefore, ; if the graph also has a downward convexity, then and .

If we compare this with the values ​​of the error of the formula of central rectangles studied above, then we see that for functions whose second derivative retains its sign on the integration interval, the signs of the errors and are opposite. There is a desire to combine the formula of trapezoids and the formula of central rectangles so that these errors are compensated as far as possible. In order to understand which combination of formulas should be taken, we need to find out what value these errors have and, depending on the choice step. These error estimates are also of independent importance, since they make it possible to find out the accuracy of the approximate value of the integral obtained by applying the corresponding quadrature formula.

The Monte Carlo method for calculating one-dimensional integrals is usually not used, since quadrature formulas are more convenient to obtain high accuracy. This method turns out to be more efficient when calculating multiple integrals, when cubature formulas are too cumbersome and require a large amount of calculations to achieve a small error.

When using quadrature or cubature formulas, the number of operations increases rapidly with the growth of the dimension of the integral. For example, if in order to calculate a one-dimensional integral by the trapezoid method with a given accuracy, it is necessary to calculate the sum of the order N terms, then to calculate the double integral by the same method, it is necessary to add order N 2 terms, and for the triple integral the number of terms is of the order N 3 .


Number of trials N required to achieve the specified accuracy ε approximate value, in the Monte Carlo method there is a quantity of order and does not depend on the dimension of the integral .

The following selection criterion is applied between the cubature formula R-th order of accuracy and the Monte Carlo method for calculating with accuracy ε multiple integral of the function m variables:

1) if the number of dimensions m < 2R, it is better to use cubature or quadrature formulas;

2) if m > 2RMonte Carlo method.

For example, if R= 1, it is more advantageous to calculate triple integrals by the Monte Carlo method, and one-dimensional integrals - by quadrature formulas.

If a R= 2, it is better to calculate five-dimensional integrals by the Monte Carlo method, and one-dimensional, double and triple integrals - by quadrature or cubature formulas.

Let us consider specific formulas of the Monte Carlo method for calculating multiple integrals, which are obtained by the method that was used to derive formula (9.7).

Let it be required to calculate the double integral

Let's run a series of N random point tests ( x i, y i), where x i a, b], a y i uniformly distributed on the segment [ With, d]. Let us calculate the integral (9.9) by the formula

For the triple integral, we similarly obtain the formula

where x i uniformly distributed on the segment [ a, b], y i– on the segment [ With, d], a z i– on the segment [ R, q]; N is the number of trials.

For m-fold integral, the formula of the Monte Carlo method has the form