Compound trapezoid formula and compound Simpson formula for Integral Calculation

Source: Internet
Author: User
 

1. Tutorial Purpose

1. master the basic idea of compound trapezoid formula and compound Simpson formula.
2. Calculate the integral using the compound trapezoid formula and the composite Simpson formula for programming.
3. Familiar with Matlab software.

2. experiment content
1. Use the compound trapezoid formula to calculate the points I = 4/(1 + x2) dx and calculate the points between 0 and 1. Precision: 10-5. (0.00001)
, Accurate
● 1 Calculation Formula
H = (B-a)/n

H = H/2 [(f (x0) + f (X1) + (f (X1) + f (X2) + (f (X2) + f (X3) +... + (f (xn-1) + f (Xn)]

L1 algorithm analysis
En = H2/12 [f' (B)-f' (a)]
Divide the interval [a, B] into N cells, and apply the low-level integral formula to construct the formula between the cells. The for loop is used to implement the formula. The finer the score, the closer it is to the actual result, the higher the accuracy.
L2 source program
Function F1 = fun4 (x) % Original Function
F1 = 4/(1 + x ^ 2 );
Function FF = fun2 (x) % function evaluate x
FF =-8 * x/(1 + x ^ 2) ^ 2 );
Function f = tixing (a, B) % A, B is the interval
A = 0; B = 1;
Disp ('******* compound trapezoid formula ******')
H = 0.008; % H indicates the spacing of each two numbers after the interval is divided into several equal parts
M = (A: H: B); % form a one-dimensional matrix. The interval between each two numbers is H.
N = length (m); % calculates the length of the upper matrix, that is, the number of elements
For I = 1: n-1
D (I) = fun4 (M (I) + fun4 (M (I + 1 ));
End
R = H/2 * sum (d); % points result
E =-(H ^ 2) * (fun2 (B)-fun2 (A)/12; % remainder, that is, Accuracy
T = pi-R;
[R; E; t]
Experiment Result Discussion and Analysis
By changing the value of H, we can find that the smaller the value of H, that is, the smaller the Equi-score interval, the more accurate the result, and the higher the accuracy. After hand calculation, the integral result is π, and the experimental result is 3.14158198692313. The result is correct. It can be seen that the accuracy of the compound trapezoid formula is high, and the operation frequency is 125.
2. Calculate the points I = 4/(1 + x2) dx using the composite Simpson formula and calculate the points 0 to 1. Precision: 10-5. (0.00001)
L5 Formula
H = (B-a)/2n = (XI + 1-xi)/2; (I = 0, 1 ,... N-1)
S = H/3 [F (xi) + 4f (XI + 1/2) + f (XI + 1)] (I = ,... N-1)
L6 algorithm analysis
The combination of the Simpson formula to calculate the integral is to divide the interval into 2n parts, and then take the median value between each two adjacent numbers, and use the for loop to implement the Simpson formula. This formula has more equal parts, and is more accurate.
L7 source program
Function F1 = fun4 (X)
F1 = 4/(1 + x ^ 2); % formula F (x)
Function f = xinpusen (a, B) % A, B are the endpoints of the range respectively
A = 0; B = 1;
Disp ('******* composite Simpson formula ******')
H1 = 0.25; % H indicates the spacing of each adjacent number after the interval is divided into several equal parts
M = (A: H1: B );
H = h1/2;
N = length (m );
For I = 1: n-1
Z (I) = (M (I) + M (I + 1)/2;
D (I) = fun4 (M (I) + fun4 (M (I + 1) + 4 * fun4 (Z (I ));
End
R = H/3 * sum (d );
T = pi-R; % precision
[R; t]
Discussion and Analysis on the experiment result of '9'
From the calculation results, you can see that the results of the composite Simpson formula are closer to the exact solution, with a higher accuracy and only 40 operation times, greatly reducing the number of operations and higher convergence than the composite trapezoid formula.

Iii. Summary of this experiment
In this experiment, I have mastered the basic algorithms and ideas of the compound trapezoid formula and the composite Simpson formula. By programming, I can use the composite trapezoid formula and the composite Simpson formula to calculate points. In addition, through the computer experiment, we can see that the results obtained by the composite Simpson formula are more accurate and the number of operations is relatively small. At the same time, we are more skilled in using Matlab, and more comfortable using common statements.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.