知之者 不如好之者, 好之者 不如樂之者

기계처럼 살지 말고, 즐기는 인간이 되자

Code/C C++

[C++] Integration with the Area of Rectangle and Trapezoid

코방코 2022. 9. 16. 08:35
728x90

The area of ​the first quadrant in the equation of a circle 

can be calculated using the integral likes below.

 

We use integral for get the area of under the graph.

But, computer can compute this as the sum of area of thin bars.

(because computers have fast computational processing power)

 

It can be obtained as shown in the figure below.

There must be exist an error this way.

But if we calculate δ as very small value, its result be more accurate.

 

Below code is intergration using rectangle bars which explained above.

 

 

when I put delta = 0.0001 and r = 2 in this code,

result = 3.1416922378

real Pi = 3.1415926536

result > real Pi and Error rate = 0.0031698635368 %

 

If using trapezoid bars, it will be more accurate like below figure.

 

 

 

when I put delta = 0.0001 and r = 2 in this code,

result = 3.1415922379 

real Pi = 3.1415926536

result < real Pi and Error rate = 0.000013232141969 %

 

Using trapezoid bars is more accurate than using rectangle bars.

 

728x90
반응형

'Code > C C++' 카테고리의 다른 글

[C++] Get area using Monte Carlo method  (0) 2022.10.01