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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Logarithmic Functions: Half-Lives

00:00 In this lesson, we’re going to focus on the logarithm function with base e, Euler’s number, and see how we can use it to compute the half-life of a radioactive substance.

00:12 Before we jump in, let’s recall what the exponential function is. When the base is e, Euler’s number, that’s usually called the exponential function, and we’ve seen that exponential functions have inverses.

00:25 The inverse of the exponential function is called the logarithm function. Sometimes it’s called the natural logarithm. Now, as an aside, in a lot of math circles, instead of writing log base e, the notation is used ln, so ln for the natural logarithm. In Python, to access to logarithm function, you use the log() function with only one argument, so the second parameter to the log() function is optional and when you don’t pass it, then you’re computing the natural logarithm.

01:03 Let’s see how we can use the logarithm in the example that we were doing on the radioactive decay of substances. So, let’s review this real quick.

01:13 Okay, so going back to our example of studying the decay of a radioactive substance, the amount of the substance—say, N of t at any given time t—is computed using this formula, which involves the exponential function with this exponent.

01:30 N sub-zero is the initial amount of the substance at time t = 0, capital T is the half-life, and little t is the time that you want to use to determine the amount of the substance at that given time. Now, in a previous lesson, we use this formula to compute the amount at any given time.

01:49 In this case, what we want to do is: Suppose we have some unknown radioactive substance that, say, was found 5 years ago. And 5 years ago when you found it, you measured it to be 88.45 milligrams, and today it weighs 23.865 milligrams.

02:09 What you want to know is, what is the substance? You know it’s a radioactive substance, but you don’t know which one. What you do have is these two measurements of the amount of the substance at two different times, and so one way to identify the substance is to know what its half-life is so then you can look it up in some table of known radioactive substances and their half-lives. Now, in this formula, what you can do is you can invert it and isolate for the half-life. If you do that, this is the expression that you get for the half-life, and the natural logarithm function is used to do the inversion, and so you end up with this expression.

02:50 So you can use this expression to determine the half-life of an unknown substance if you know all of these pieces of information. You need to know the initial amount when you first started measuring, and then the time—the current time, and so here we’ll plug in N(t), and so N(t) is just the value at the current time—and then the t is going to be the time from when you started measuring.

03:14 So in our case, we would plug in 5 for t. For N(t), we would plug in 23.865, and then for N sub-zero, 88.45. Do this computation, and it would give us the half-life. So let’s try this out in the console.

03:32 Make sure you’ve imported math, and then let’s just work with the logarithm function, and then we’ll work on this decay problem. If you use the logarithm without a argument for the base, it defaults to the natural logarithm.

03:46 If we type the logarithm of 57, you know then what that means is that if you raise e, Euler’s number, to this value, you’re going to get 57.

03:58 So, why don’t you confirm it? Let’s take this value, save it in the variable x, and if you compute the exponential of that value x,

04:08 you get 57 modulo some rounding. Let’s compare this real quick. If we were to use the logarithm function—again, with 57but this time let’s pass in an argument, and we’ll use Euler’s number as the base, just to compare the difference with if we were to just use the log() without a value. So if we type in here e, we see that we’re pretty close.

04:31 It’s probably the exact same if we compare them. So, why don’t we try to do that? If we compare this with the value, with log(57),

04:42 you get True.

04:46 To wrap things up with the natural logarithm, let’s create a function that computes the half-life if we know the value of a radioactive substance at two different times.

04:57 We’ll assume for simplicity that the first time is t = 0. So go ahead, let’s write this function. Maybe we’ll call it, say, get_half_life().

05:08 It’s going to take two values for the two different amounts, so this will be the initial amount, N sub-zero, and so we’ll write it like this, and then we’ve got N sub-t, and then we need to specify the time that this second value corresponds to, and so we’ll denote that by t. And what we’re returning from the formula, -0.693 and then times the time t, and then we need to divide all of that by the natural logarithm of the amount at time t divided by the amount at time zero. All right, so go ahead and define that, and let’s try this out with the example that we did before.

05:58 Let’s get the half-life of a substance that had an initial amount of 88.45 milligrams, and then the amount of the substance after five years, 23.865, and then those two differences of amount from 80.45 and 23.865 occurred during a span of 5 years.

06:24 You get 2.6449. If you round that to three digits after the decimal, you get 2.645. And so the scenario here is that you would look up in some known table of radioactive substances, you would see which one has a half-life of about 2.645, and then you would know that you’re dealing with Californium-252.

06:49 All right, so you made it! That wraps up all of the functions that have to do with powers and exponentials and logarithms. In the next lesson, we’ll take a look at some other useful functions in the math module.

Become a Member to join the conversation.