Basic Integrals

Lesson Introduction

Welcome! Today, we'll explore integrals, a fundamental concept in calculus that's key to many machine learning applications. Integrals help us understand areas under curves, representing things like accumulated quantities over time. By the end of this lesson, you'll know what integrals are, why they're important, and how to compute them using Python.

Introduction to Integrals

An integral in calculus sums infinite tiny pieces to calculate the total area under a curve. This is useful in many real-life situations. Think about measuring the distance a car travels by knowing its speed over time. The integral helps us accumulate those tiny speed changes to find the total distance.

There are two main types of integrals: indefinite and definite. An indefinite integral represents a family of functions and includes a constant of integration. A definite integral calculates the exact area under the curve between two points, (a) and (b).

Area Approximation

The most straightforward way to calculate a complex area is to approximate it with rectangles. Here is how we can do it with a simple y=x2y = x^2 curve:

In this plot, the sum of areas of the white rectangles is close to the area of the function.

We can make this calculation more accurate by using more rectangles:

It is easy to see how 20 rectangles approximate the area under the curve way more accurate than 10. The formula for the area would be:

Areai=1nf(xi)Δx\text{Area} \approx \sum_{i=1}^{n} f(x_i^*) \Delta x

where:

f(xi)f(x_i^*) is the height of the rectangle at the sample point xix_i^*. Δx=ban\Delta x = \frac{b - a}{n} is the width of each rectangle.

Understanding Integrals

The key idea of the integral is to take this approximation to the limit: by using infinitely many rectangles with infinitely small size each, we can get the exact area under the curve:

And here is the final formula. We apply the limit nn \to \infty to the sum of rectangles. By doing so, we ask: what does this sum approach when the amount of rectangles approaches infinity?

abf(x)dx=limni=1nf(xi)Δx\int_a^b f(x)dx = \lim_{n \to \infty} \sum_{i=1}^n f(x_i^*) \Delta x

where:

  • abf(x)dx\int_a^b f(x)dx is the integral symbol representing the area under the curve from aa to bb.
  • Δx=ban\Delta x = \frac{b - a}{n} is the width of each rectangle.
  • xix_i^* is a sample point in the ii-th subinterval [xi1,xi][x_{i-1}, x_i].
  • x0=ax_0 = a, xi=a+iΔxx_i = a + i \Delta x, and xn=bx_n = b.

It might seem difficult to calculate, but in reality it is not! We need this formula only to understand the concept. To actually calculate an integral, we are going to apply another formula, called the fundamental theorem of calculus.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal