Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Exponential Functions: math.exp()

00:00 In this lesson, we’ll talk about general exponential functions and then focus on the exponential function defined in the math module.

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.

01:52 Because of its importance, the math module provides an implementation of the exponential function, and the name of the function is exp().

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.

02:20 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.

02:36 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 math module.

02:55 e to the power of 1—so in other words, the exponential function evaluated at 1e to the 1 is e, so we should either get True or we can test this with the isclose() function.

03:07 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 1.

03:27 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.

03:47 We get 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 True value.

03:58 Go ahead and try: Is the value of the constant e as stored in the math module raised to the power of 2is that close to the value of the exponential function evaluated at 2? And we get True.

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.

04:27 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.