Exponential Functions: math.exp()
In this lesson, we’ll talk about general exponential functions and then focus on the exponential function defined in the
00:09 Before we jump into what an exponential function is, let’s review real quick what a power function is. In power functions, the base is what changes and the power or exponent is fixed.
00:22 When the exponent is a positive integer, these functions are usually called polynomial functions. On the other hand, exponential functions are power functions, but here, the base is fixed and it’s the exponent that changes. A lot of times these are written as, say, a to the power of x. a is the base—, that’s fixed—and it’s the power x that’s changing.
00:48 The fixed base a is a positive number in most applications. Otherwise, you’re going to have to deal with complex numbers. Qualitatively, when a, the base, is greater than 1, the values of the function increase as x increases. So, in other words, if this base a is greater than 1, as we make this exponent larger, the entire output of the function also increases. On the other hand, if a is between 0 and 1, then the values of the output of the function—they’re going to decrease as the input x increases.
01:25 There’s an important exponential function, which a lot of times it’s called the exponential function, and this is one where the base a is Euler’s number e, which we’ve encountered before.
01:37 So, e is around 2.71828, and so if that constant a is exactly Euler’s number, a lot of times, this is called the exponential function or the natural exponential function.
Because of its importance, the
math module provides an implementation of the exponential function, and the name of the function is
02:00 It takes in one input argument x, which is any float or any integer.
02:06 The exponential function is important in many applications involving exponential growth or decay. We’ll take a look at an example in the next lesson of this, but for now, let’s just get comfortable with the exponential function.
Let’s just compute a couple values of the exponential function. So, say, evaluated at
3 or evaluated at, say,
-3. And so, here, the input can be any float, any number. It doesn’t matter whether it’s negative or positive.
The exponential is defined for every real number. Now, the exponential function being e to the power of x means that if we evaluate the exponential function at
1, it should be pretty close to the value of
e in the
e to the power of 1—so in other words, the exponential function evaluated at
1—e to the 1 is e, so we should either get
True or we can test this with the
But go ahead and see what happens when you do this. We get
True. Python’s doing a good job in being consistent that e to the power of 1 is exactly e, and so the value in the
e constant in the
math module does evaluate exactly to the exponential function evaluated at
Now, the exponential function is just a power function, so if I compute the power of
e to the power of
2, that should be pretty close to the exponential function evaluated at
2. Let’s see what Python does in this case.
False. But you know that these are supposed to be pretty close—let’s see how close they are. Let’s just see if the
isclose() function will return a
Go ahead and try: Is the value of the constant
e as stored in the
math module raised to the power of
2—is that close to the value of the exponential function evaluated at
2? And we get
04:17 And if you wanted to take a look at these values a little bit more so that we can see them, let’s just print these out to the console.
They’re pretty close and definitely within
10 to the power of
-9 in terms of the relative size of those values.
04:35 In the next lesson, we’ll take a look at how the exponential function is used to model the decay of a radioactive substance.
Become a Member to join the conversation.