Welcome to our lesson on understanding limits, a fundamental concept in calculus with important applications in machine learning. Limits help us understand how functions behave as we approach certain points, which is crucial for defining derivatives and integrals. By the end, you'll grasp what limits are, learn how to compute them numerically, and see how to implement this in Python.
A limit in mathematics describes the value a function approaches as the input nears some value. Imagine driving toward a red light. As you get closer, you're approaching a specific point where you'll stop. That's similar to limits: as the input nears a particular value, the output of the function approaches a specific value.
This reads as "the limit of as approaches is ."
Consider the function . To find the limit as approaches 2, think about what happens to when gets very close to 2. The values of will get closer to .
Think of as a car. If we're getting closer to 2, what number is approaching? Like the car nearing the red light, gets closer to 4 as approaches 2.
We can calculate this practically using a small value : Here, is a very small number.
Let's see how to calculate limits numerically using Python.
Python1# Numeric limit calculation 2def limit(f, x, h=1e-5): 3 return f(x + h) 4 5# Sample function: f(x) = x^2 6f = lambda x: x**2 7 8# Compute limit of f at x=2 9print("Limit of f(x) as x approaches 2:", limit(f, 2)) # Limit of f(x) as x approaches 2: 4.00004
limit
function calculates the function value for a small increment . Here, f
is the function, x
is the point, and h
is a small number.The choice of is crucial. It needs to be small but not too small to avoid numerical errors due to computer precision. Typically, is set around or smaller for good accuracy.
Consider this: if you’re too close to the wall (like being too small), you can't see much of the wall's shape. Step a tiny bit back (a reasonable ), and the shape becomes clearer without much distortion.
Let's see what happens with different values:
Python1# Numeric limit calculation 2def limit(f, x, h=1e-5): 3 return f(x + h) 4 5# Sample function: f(x) = x^2 6f = lambda x: x**2 7 8print("Limit with h=1e-5:", limit(f, 2, 1e-5)) # Limit with h=1e-5: 4.00004 9print("Limit with h=1e-3:", limit(f, 2, 1e-3)) # Limit with h=1e-3: 4.004 10print("Limit with h=1e-1:", limit(f, 2, 1e-1)) # Limit with h=1e-1: 4.41
You'll notice that as gets larger (like ), the limit's accuracy decreases.
Let's examine the function , which is undefined at . This is because division by zero is not allowed in mathematics.
Here is the graph of :
Note that the function is not defined at .
For some tasks, we might want this function to be defined at every point, which means we will have to somehow define the . To find the most appropriate value of at one can use limits. Let's observe what happens as approaches 0.
The limit is:
This means that as gets very close to 0, the value of gets very close to 1. This can be clearly seen on the plot. Also, we can verify it with calculations.
Python1import numpy as np 2 3def limit_sin_x_over_x(h=0.00001): 4 # Using a small value of h to approximate the limit 5 return np.sin(h) / h 6 7# Compute limit of sin(x)/x as x approaches 0 8print("Limit of sin(x)/x as x approaches 0:", limit_sin_x_over_x()) # 0.999999...
In this code, we calculate the limit using a slightly adjusted expression of .
Knowing this, we can redefine our function:
Now, the plot of the function will look like this:
Note: that doesn't mean that the original is equal to at . It is still undefined. We used limits to determine the value it approaches and manually inserted it, constructing a new function, which looks similar, but is defined at .
We've covered what limits are, why they are important, and how to calculate them both conceptually and numerically. We broke down a Python code snippet demonstrating this process for the function . Remember, limits help understand how functions behave as inputs get close to a particular point, which is key for more advanced topics like derivatives.
Now it's time to put your new knowledge into practice! You'll be working on hands-on exercises where you'll code your own limit functions and evaluate limits for different functions and points in the CodeSignal IDE. Happy coding!