03| Integrals & Areas

Author

Lee Yuan Zhe

Introduction

The definite integral of a function, \(f(x)\) with respect to \(x\) is the area bounded by the curve of the function and the x-axis, as shown in the figure below.

One way to estimate the integral of a function is by approximating the area bounded as a trapezium as shown in the figure below, where the slanted side connects the \(y\) values at the lower and upper limits. The integral can then be estimated by calculating the area of the trapezium.

As you can see, the estimation using one trapezium is rather off. In this case, there’s an overestimation. We can improve the accuracy by having more trapeziums, as shown in the figure below, where three trapeziums of equal width are used. The slanted side of each trapezium connects the \(y\) values at the \(x\)-boundaries of each trapezium.

From here, we can deduce that if we have a large number of such trapeziums, each of very thin size, we can find the numerical value of the definite integral pretty accurately. This method of approximating definite integral is known as the trapezium rule.

Tasks

  1. Write a Python function which can estimate the definite integral of a mathematical function \(f(x)\) using the trapezium rule.

  2. Use WolframAlpha to evaluate the integrals and complete the last column.

# \(f(x)\) \(a\) \(b\) \(\displaystyle\int_{x=a}^{x=b} f(x)dx\)
(Wolfram Alpha)
1 \(f(x)=x^2+3x+2\) \(0\) \(5\)
2 \(f(x)=\sin x\) \(0\) \(\pi\)
3 \(f(x)=e^{-x^2}\) \(0\) \(1\)
4 \(f(x)=\sin\left(\dfrac{1}{x}\right)\) \(0.01\) \(0.1\)
  1. Now use your function to evaluate the integrals. Add your results as a new column.
    Please highlight any strategies you used to enhance the quality of your answers.

  2. For the above functions, you had the benefit of knowing the answers beforehand due to Wolfram Alpha. Can you describe a strategy that can be used to judge the quality of your answer if you did not have access to the answer beforehand?

  3. [Optional] Considering the power of services like WolframAlpha; is there a need to write your own code.

Back to top