In: Computer Science
Using python, write a function calcA() that determines the area under the curve ?(?) = ?? −? over the range ?1 to ?2. The area is to be determined approximately as follows: ? = ∫ ?(?) ?? ?2 ?1 ≈ ∑ 1 2 (?(?? ) + ?(??−1 ))∆? ? ?=1 (1) Where ? is the number of intervals over the range ?1 to ?2. So if ? is equal to 10, then ∆? = (?2 − ?1)/10. This function receives the two range limits and divides it into ? intervals and generates ? + 1 values and puts them in a list. The function will then iterate over this list and implement (1), above, to calculate the area under the curve. Test your calcA() function over the range 0 to 5 w. Then calculate the area of a rectangle, which is equal to 5.
The above program is implemented in python3 and code is explained in comments
Approximate formula to find the integration is
For f(x)=x * e-x Below is the code in python
We can see that when we find the integration of above function by rules of integration we get the result as
0.9595723180054871
So this can proove the effectiveness of our code.
For m=10 we have an error of 0.2 approx.
NOTE: Our code accuracy will always increase when we increase the value of m
For m=100, our code outputs :
The approx. result of integration over range 0 to 5 is: 0.9593583958723835
This value is more closer to the original value, which means our accuracy increased.
2) To find the area of rectangle
f(x)=width ; For a rectangle of width 1
f(x)=1