Numerical methods for approximating definite integrals

Hugo Miguel Pelaez Carpio, Polytechnic University of Puerto Rico, Mechanical Engineering

Author Profile
Initial Publication Date: October 7, 2025

Summary

In this activity, students are introduced to Newton-Cottes integration methods, such as the trapezoidal rule and Simpson's 1/3 and 3/8 rules. The Romberg method and Gaussian quadrature are then explained.
The codes for the algorithm functions will be created and applied to an example with all the methods for comparison.

Share your modifications and improvements to this activity through the Community Contribution Tool »

Learning Goals

Students will be able to reinforce their knowledge of integration by distinguishing between indefinite and definite integrals.
Students should be able to observe the differences between integration algorithms grouped into Newton-Cottes methods, the Romberg method, and Gauss quadrature.
Students will verify the applicability of each method.
The students will demonstrate the ability to solve problems that includes integral expressions using numerical methods.

Context for Use

This explanation is given to students in the Numerical Methods Applied to Mechanical Engineering course, but it can be included in any other engineering program. Students should be familiar with the mathematical concepts of integrals and have a basic understanding of using Matlab.
The activity takes place midterm and consists of two practical sessions.

Description and Teaching Materials

Students will come prepared with their laptops, which must have Matlab installed. After the concepts are explained, they will be informed that the activities will be carried out in two sessions.
Students will be able to collaborate with each other and follow the algorithm programming sequence with the participation of all students. The idea is for them to develop their programming skills while implementing numerical methods.
Two Livescripts will be developed. The first focuses on Newton-Cottes methods, and the second develops the Romberg and Gaussian quadrature methods. A function will be created for each method, and the f.m function will be used for the example.
Finally, the application of numerical integration methods will be compared with the analytical solution.
Class 11 Integrals Session 1 (MATLAB Live Script 23kB Sep27 25) 
Class 12 Integrals Session 2 (MATLAB Live Script 20kB Sep27 25) 
function f(x) used as an example (Matlab File 123bytes Sep27 25) 
Function of the Trapezoidal rule (Matlab File 202bytes Sep27 25) 
Function of the Simpson 1/3 rule (Matlab File 229bytes Sep27 25)

CuadGauss2.m (Matlab File 188bytes Sep27 25)

Simpson38.m (Matlab File 422bytes Sep27 25)

Function of Romberg method (Matlab File 245bytes Sep27 25)

Teaching Notes and Tips

The concepts should be explained in 30-40 minutes prior to each practical session. Simple examples should also be provided that students can solve manually.
For the practical sessions, students will participate in creating Livescripts using the figures contained in the shared presentation file, used for the explanation of concepts.
They should also participate in creating the functions that implement each of the algorithms discussed in class.
The Newton-Cottes methods activity should use a number of segments that are a multiple of 3 to compare the application of the methods.
In the Romberg activity, use k=4 so that it is easy to view on the right side of the Livescript window.
Remember that the function used as an example must be changed in f.m and in the analytical solution shown at the end of each Livescript.


Assessment

Student performance will be assessed by reviewing the files they upload to the Blackboard course page after the session concludes. Not all students may complete the exercises due to errors in the coding of functions and scripts.

References and Resources

Textbook: Amos Gilat and Vish Subramaniam, Numerical Methods for Engineers and Scientist: An Introduction with Applications Using MATLAB, 3rd Edition, John Wiley & Sons, Inc., 2014.