3.1. Logarithms and Exponential Functions#

3.1.1. Learning goals:#

After working through these notes, you will be able to:

  1. Evaluate exponential functions

  2. Plot exponential functions

  3. Manipulate exponential functions

  4. Evaluate logarithmic functions

  5. Plot logarithmic functions

  6. Manipulate logarithmic functions

3.1.2. Coding concepts:#

The following coding concepts are used in this notebook:

  1. Variables

  2. Functions

  3. Plotting with matplotlib

3.1.3. Exponential Functions#

Exponential functions show up regularly in various areas of physical chemistry. Being comfortable manipulating and evaluating these types of functions is important. We start by evaluating and plotting exponential functions followed by revisiting the rules of algebraically manipulating these functions.

First, a definition, the exponential function is

(3.1)#\[\begin{equation} f(x) = e^x. \end{equation}\]

This function takes the independent variable, \(x\), and raises \(e\) to this value to determine the dependent value, \(f(x)\).

3.1.3.1. Evaluating Exponential Functions#

Exponential functions are readily evaluated on any calculator or computer. For example, we might define

(3.2)#\[\begin{equation} f(x) = 2\cdot e^{3\cdot x} \end{equation}\]

and ask, what is \(f(1.5)\)?

This will be evaluated by a computer/calculator. Below I do it using python code.

# import numpy library
import numpy as np
# define the function
def f(x):
    return 2*np.exp(3*x)
# print the specific value
print(f(1.5))
180.03426260104362

We can create more complicated exponential functions and evaluate their values at various \(x\) values. Here are some examples followed by the code to evaluate them.

(3.3)#\[\begin{eqnarray} f(x) &=& 1.2e^{2x+1}\text{, } f(3.2) = ? \\ g(x) &=& 45.0e^{-1.5x}\text{, } g(-2.0) = ? \\ h(x) &=& 12.1e^{-23x+2}\text{, } h(0.01) = ? \end{eqnarray}\]
import numpy as np
def f(x):
    return 1.2*np.exp(2*x+1)
def g(x):
    return 45*np.exp(-1.5*x)
def h(x):
    return 12.1*np.exp(-23*x+2)
print("f(3.2)=", f(3.2))
print("g(-2.0)=", g(-2.0))
print("h(0.01)=",h(0.01))
f(3.2)= 1963.1813159951123
g(-2.0)= 903.849161543445
h(0.01)= 71.03732567272948

3.1.3.2. Plotting Exponential Functions#

Exponential functions can be evaluated over the full domain of \(x\). If the largest power of \(x\) is positive then we will see exponential growth (the function will go to infinity as \(x\) goes to infinity) and if the largest power of \(x\) is negative then we will see exponential decay (the function will go to zero as \(x\) goes to infinity). We will plot one of each.

import matplotlib.pyplot as plt
%matplotlib inline
# setup plot 
fontsize=14
fig,ax = plt.subplots(1,2,figsize=(8,4), dpi= 80, facecolor='w', edgecolor='k')
ax[0].grid(which='major', axis='both', color='#808080', linestyle='--')
ax[0].set_xlabel("$x$",size=fontsize)
ax[0].set_ylabel("$f(x)$",size=fontsize)
ax[0].set_title("$f(x)$, Exponential Growth")
x = np.arange(-2,1,0.001)
ax[0].plot(x,f(x),lw=3);
ax[1].grid(which='major', axis='both', color='#808080', linestyle='--')
ax[1].set_xlabel("$x$",size=fontsize)
ax[1].set_ylabel("$g(x)$",size=fontsize)
ax[1].set_title("$g(x)$, Exponential Decay")
x = np.arange(-2,1,0.001)
ax[1].plot(x,g(x),lw=3)
plt.tight_layout()
../_images/77620628f13a2adc90558d0eb0576c9aa02cb3190c37987d80355cdaec4b79dc.png

3.1.3.3. Manipulating Exponential Functions#

Exponential functions can be manipulated in various ways. Here are two common manipulations

(3.4)#\[\begin{align} e^{x+y} &= e^xe^y \\ e^{x\cdot y} &= \left(e^x\right)^y = \left(e^y\right)^x \end{align}\]

Here is an example problem that uses both

Example: Show that

(3.5)#\[\begin{equation} e^{x^2}e^{2x}e = \left( e^{(x+1)}\right)^{(x+1)} \end{equation}\]

We start by using the reverse of the first rule above to combine everything into a single exponential

(3.6)#\[\begin{equation} e^{x^2}e^{2x}e = e^{x^2+2x+1} \end{equation}\]

Now recognize that the quadratic function in the exponent is a perfect square so can be further simplified

(3.7)#\[\begin{equation} e^{x^2+2x+1} = e^{(x+1)(x+1)} = \left( e^{(x+1)}\right)^{(x+1)} \end{equation}\]

We also have that natural log and exponential functions are inverse functions which means that

(3.8)#\[\begin{equation} e^{\ln(x)} = x \end{equation}\]

3.1.4. Logarithmic Functions#

Log functions are the inverse of exponential and/or power functions. These also come up frequently in physical chemistry and thus we must be able to evaluate, plot, and manipulate them.

An example logarthmic function is

(3.9)#\[\begin{equation} f(x) = \ln(x), \end{equation}\]

where \(\ln\) stands for natural log or log base \(e\). We most commonly encounter natural logarithms so will not discuss other bases or change of bases in these notes but it is important to remember that these things exist.

It is also very important to consider the domain of logarithmic functions. The function \(f(x)=\ln(x)\) is only defined when \(x\) is greater than 0. That is, the function \(f(x)=\ln(x)\) is defined for \(x>0\).

3.1.4.1. Evaluating Logarithmic Functions#

Generally, we will use computers/calculators to evaluate logarithmic functions. For the function

(3.10)#\[\begin{equation} f(x) = \ln(x) \end{equation}\]

there are some important things to remember, however:

(3.11)#\[\begin{eqnarray} f(1) &=& \ln(1) = 0 \\ f(0<x<1) &<& 0 \\ f(x\ge1) &>& 0 \end{eqnarray}\]

Otherwise, evaluating logarthmic function is just a matter of entering it into your calculator. Here are some examples and the code to evaluate them.

(3.12)#\[\begin{eqnarray} f(x) &=& 1.2\ln\left(2x+1\right)\text{, } f(3.2) = ? \\ g(x) &=& 45.0\ln\left(-1.5x\right)\text{, } g(-2.0) = ? \\ h(x) &=& 12.1\ln\left(-23x+2\right)\text{, } h(-0.01) = ? \end{eqnarray}\]
import numpy as np
# Note: np.log is the natural log
def f(x):
    return 1.2*np.log(2*x+1)
def g(x):
    return 45*np.log(-1.5*x)
def h(x):
    return 12.1*np.log(-23*x+2)
print("f(3.2)=", f(3.2))
print("g(-2.0)=", g(-2.0))
print("h(0.01)=",h(-0.01))
f(3.2)= 2.401776000252149
g(-2.0)= 49.43755299006494
h(0.01)= 9.704219184211532

3.1.4.2. Plotting Logarithmic Functions#

It is important to be able to plot these functions over their finite domains. Recall that the domain of a log function is determined by making the argument of the log greater than zero. You cannot take the log of zero or a negative number.

import matplotlib.pyplot as plt
%matplotlib inline
# setup plot 
fontsize=14
fig,ax = plt.subplots(1,2,figsize=(8,4), dpi= 80, facecolor='w', edgecolor='k')
ax[0].grid(which='major', axis='both', color='#808080', linestyle='--')
ax[0].set_xlabel("$x$",size=fontsize)
ax[0].set_ylabel("$f(x)$",size=fontsize)
ax[0].set_title("$f(x)=1.2\ln(2x+1)$")
x = np.arange(-0.499,1,0.001)
ax[0].plot(x,f(x),lw=3);
ax[1].grid(which='major', axis='both', color='#808080', linestyle='--')
ax[1].set_xlabel("$x$",size=fontsize)
ax[1].set_ylabel("$g(x)$",size=fontsize)
ax[1].set_title("$g(x)=45.0\ln(-1.5x)$")
x = np.arange(-10,0,0.001)
ax[1].plot(x,g(x),lw=3)
plt.tight_layout();
../_images/92122ff43d1d3d58a6ea4eea73f9a5cec0e11b784c0f1e884458fda7dc5c62ed.png

3.1.4.3. Manipulating Logarithmic Functions (Rules of Logarithms)#

There are some important rules of logarithms that we should keep in mind:

(3.13)#\[\begin{equation} \ln(x\cdot y) = \ln(x) + \ln(y) \end{equation}\]
(3.14)#\[\begin{equation} \ln\left( \frac{x}{y} \right) = \ln(x) - \ln(y) \end{equation}\]
(3.15)#\[\begin{equation} \ln\left( x^y \right) = y\ln(x) \end{equation}\]

And finally the fact that exponential and logarithmic functions are inverses yields

(3.16)#\[\begin{equation} \ln{e^x} = x \end{equation}\]