Want to keep learning?

This content is taken from the Partnership for Advanced Computing in Europe (PRACE)'s online course, Python in High Performance Computing. Join the course to learn more.

Hands-on: Numerical integration

We continue studying vectorized operations with numerical integration.

Source code for this exercise is located in numpy/integration/

A simple method for evaluating integrals numerically is by the middle Riemann sum

\[S = \int_a^b f(x) dx = \sum_{i=1}^n f(x'_i) \Delta x\]


\[x'_i = (x_i + x_{i-1}) / 2 ; x_0 = a, x_n = b\]

Calculate the integral in the interval [0,π/2] and investigate how much the Riemann sum of sin differs from 1.0. Avoid for loops. Investigate also how the results changes with the choice of Δx.

Share this article:

This article is from the free online course:

Python in High Performance Computing

Partnership for Advanced Computing in Europe (PRACE)