Sometimes it is easier to differentiate the logarithm of a function than the original function. This is called logarithmic differentiation and this module provides an overview of the method and provides some examples.
Suppose you have to differentiate \[\begin{align*}
y & =\frac{x^{2}-1}{x^{8}\sqrt{x^{4}+1}}.
\end{align*}\]
At first sight, you need to use the quotient rule. You also need to use the product rule to differentiate the denominator. If you try to do it, it will be a difficult problem. A problem like this can be easier to solve if you take the logarithm of both sides and then differentiate.
Assuming \(y>0.\) Remember the domain of the log function is \(\left(0,\infty\right)\)
Required background
Before you attempt logarithmic differerentiation, it is essential
that you know how to:
Use logarithm laws; and
Differentiate a log function using the chain rule (also known as implicit
differentiation).
These are reviewed briefly in the next section.
Logarithm laws
There are three laws of logarithms that you need to remember. If \(m\left(x\right)\)
and \(n\left(x\right)\) are functions of \(x\) and \(m\left(x\right)\), \(n\left(x\right)>0\) and \(a>0,\ a\neq1\) then:
First Logarithm Law \[\begin{align*}
\log_{a}(mn) & =\log_{a}m+\log_{a}n & \left(1\right)
\end{align*}\]
Second Logarithm Law \[\begin{align*}
\log_{a}\frac{m}{n} & =\log_{a}m-\log_{a}n & \left(2\right)
\end{align*}\]
Third Logarithm Law \[\begin{align*}
\log_{a}m^{p} & =p\log_{a}m\,. & \left(3\right)
\end{align*}\]
The number \(a\) is called the base. We will use \(a=e.\)
That is, we will use natural logarithms and the notation \(\log_{e}\left(x\right)=\ln\left(x\right)\).
Derivative of a log function and the chain rule
Suppose you want to differentiate \[\begin{align*}
y & =f\left(x\right)
\end{align*}\]
where \(f\left(x\right)>0\) for all \(x\). Taking logs of both sides, \[\begin{align*}
\ln\left(y\right) & =\ln\left(f\left(x\right)\right).
\end{align*}\]
Differentiating with respect to \(x,\) \[\begin{align*}
\frac{d}{dx} & \ln\left(y\right)=\frac{d}{dx}\left(\ln\left(f\left(x\right)\right)\right).
\end{align*}\]
The left-hand side may be differentiated implicitly using the chain rule, \[\begin{align*}
\frac{d}{dx}\ln\left(y\right) & =\frac{d}{dy}\left(\ln\left(y\right)\right)\frac{dy}{dx}\\
& =\frac{1}{y}\frac{dy}{dx}. & \left(4\right)
\end{align*}\]
Equation \(\left(4\right)\) is the basis of logarithmic differentiation.
The effectiveness of logarithmic differentiation depends on whether
it is easier to differentiate the original \(f\left(x\right)\) or \(\ln\left(f\left(x\right)\right)\).
Logarithmic differentiation
Suppose you have to differentiate \[\begin{align*}
y & =\frac{x^{2}-1}{x^{8}\sqrt{x^{4}+1}}.
\end{align*}\]
You could use the quotient rule and then you would need to use the product rule to differentiate the denominator. However, this approach will be messy and prone to error.
A better approach is to take the logarithm of both sides:2 Because we will take a log of both sides, we should ensure that \(y>0.\)
The sign of \(y\) is determined by the numerator and is positive for \(\left|x\right|>1\). Hence, we assume \(\left|x\right|>1.\) \[\begin{align*}
\ln y & =\ln\left(\frac{x^{2}-1}{x^{8}\sqrt{x^{4}+1}}\right)\\
& =\ln\left(x^{2}-1\right)-\ln\left(x^{8}\sqrt{x^{4}+1}\right)\text{ using second log rule equation $\left(2\right)$ above}\\
& =\ln\left(x^{2}-1\right)-\ln\left(x^{8}\right)-\ln\left(\sqrt{x^{4}+1}\right)\text{ using first log rule equation $\left(1\right)$ above.}
\end{align*}\]
Now differentiate each of the terms: \[\begin{align*}
\frac{d}{dx}\ln y & =\frac{d}{dx}\ln\left(x^{2}-1\right)-\frac{d}{dx}\ln\left(x^{8}\right)-\frac{d}{dx}\ln\left(\sqrt{x^{4}+1}\right). & \left(5\right)
\end{align*}\]
The term on the left
The first term on the right is calculated by setting \(u=x^{2}-1\)
so \(du/dx=2x\) and \[\begin{align*}
\frac{d}{dx}\ln\left(x^{2}-1\right) & =\frac{d}{du}\ln\left(u\right)\frac{du}{dx}\text{ by the chain rule}\\
& =\frac{1}{u}\frac{du}{dx}\\
& =\frac{1}{x^{2}-1}\cdot2x\\
& =\frac{2x}{x^{2}-1}.
\end{align*}\]
The second term on the right is calculated by setting \(u=x^{8}\).
Then \(du/dx=8x^{7}\) and, using equation \(\left(4\right),\) \[\begin{align*}
\frac{d}{dx}\ln\left(x^{8}\right) & =\frac{d}{du}\ln\left(u\right)\frac{du}{dx}\text{ by the chain rule}\\
& =\frac{1}{u}\frac{du}{dx}\\
& =\frac{1}{x^{8}}\cdot8x^{7}\\
& =\frac{8}{x}.
\end{align*}\]
The final term on the right is calculated by setting \(u=\sqrt{x^{4}+1}\).
Then3 Here we use the chain rule twice.
\[\begin{align*}
u & =\left(x^{4}+1\right)^{\frac{1}{2}}\\
\frac{du}{dx} & =\frac{1}{2}\left(x^{4}+1\right)^{-\frac{1}{2}}\cdot4x^{3}\textrm{ by the chain rule}\\
& =\frac{4}{2}x^{3}\left(x^{4}+1\right)^{-\frac{1}{2}}\\
& =2x^{3}\left(x^{4}+1\right)^{-\frac{1}{2}}\\
& =\frac{2x^{3}}{\sqrt{x^{4}+1}}.\\
\\
\frac{d}{dx}\ln\left(\sqrt{x^{4}+1}\right) & =\frac{d}{du}\ln\left(u\right)\frac{du}{dx}\text{ by the chain rule}\\
& =\frac{1}{u}\frac{du}{dx}\\
& =\frac{1}{\sqrt{x^{4}+1}}\frac{2x^{3}}{\sqrt{x^{4}+1}}\\
& =\frac{2x^{3}}{x^{4}+1}.
\end{align*}\]
Substituting in \(\left(5\right)\), we have:
\[\begin{align*}
\frac{x^{8}\sqrt{x^{4}+1}}{x^{2}-1}\frac{dy}{dx} & =\frac{2x}{x^{2}-1}-\frac{8}{x}-\frac{2x^{3}}{x^{4}+1}\\
\frac{dy}{dx} & =\frac{x^{2}-1}{x^{8}\sqrt{x^{4}+1}}\left(\frac{2x}{x^{2}-1}-\frac{8}{x}-\frac{2x^{3}}{x^{4}+1}\right).
\end{align*}\]
Note that it is possible to give this answer in several forms depending on how far you go in simplification.
In the following examples, you should be aware that the answers may be given in different, (but equivalent forms), depending on algebraic simplification.
Example 1
Differentiate \[\begin{align*}
y & =\frac{\left(2x+1\right)^{9}}{\left(x-2\right)^{3}\left(x+8\right)^{6}}
\end{align*}\]
with respect to \(x.\)
Solution
Taking logs of both sides, \[\begin{align*}
\ln\left(y\right) & =\ln\left(\frac{\left(2x+1\right)^{9}}{\left(x-2\right)^{3}\left(x+8\right)^{6}}\right)\\
& =\ln\left(\left(2x+1\right)^{9}\right)-\ln\left(\left(x-2\right)^{3}\left(x+8\right)^{6}\right)\text{ using the second logarithm law (equation $\left(2\right)$ )}\\
& =\ln\left(\left(2x+1\right)^{9}\right)-\ln\left(\left(x-2\right)^{3}\right)-\ln\left(\left(x+8\right)^{6}\right)\text{ using the first logarithm law (equation $\left(1\right)$ )}\\
& =9\ln\left(2x+1\right)-3\ln\left(x-2\right)-6\ln\left(x+8\right)\text{ using the third logarithm law (equation $\left(3\right)$ )}.
\end{align*}\]
Now differentiate both sides: \[\begin{align*}
\frac{d}{dx}\left(\ln\left(y\right)\right) & =\frac{d}{dx}\left(9\ln\left(2x+1\right)-3\ln\left(x-2\right)-6\ln\left(x+8\right)\right)\\
& =9\frac{d}{dx}\ln\left(2x+1\right)-3\frac{d}{dx}\ln\left(x-2\right)-6\frac{d}{dx}\ln\left(x+8\right).
\end{align*}\]
Using equation \(\left(4\right)\) the left-hand side is \[\begin{align*}
\frac{d}{dx}\left(\ln\left(y\right)\right) & =\frac{1}{y}\frac{dy}{dx}.
\end{align*}\]
The first term on the right-hand side is calculated using the chain
rule with \(u=2x+1.\) Then \[\begin{align*}
\frac{du}{dx} & =2
\end{align*}\]
and \[\begin{align*}
9\frac{d}{dx}\ln\left(2x+1\right) & =9\frac{d}{du}\ln\left(u\right)\frac{du}{dx}\\
& =\frac{9}{u}\cdot2\\
& =\frac{18}{2x+1}.
\end{align*}\]
The second term on the right-hand side is calculated using the chain
rule with \(u=x-2.\) Then \[\begin{align*}
\frac{du}{dx} & =1
\end{align*}\]
and \[\begin{align*}
-3\frac{d}{dx}\ln\left(x-2\right) & =-3\frac{d}{du}\ln\left(u\right)\frac{du}{dx}\\
& =-\frac{3}{u}\cdot1\\
& =-\frac{3}{x-2}.
\end{align*}\]
The last term on the right-hand side is calculated using the chain
rule with \(u=x+8.\) Then \[\begin{align*}
\frac{du}{dx} & =1
\end{align*}\]
and \[\begin{align*}
-6\frac{d}{dx}\ln\left(x+8\right) & =-6\frac{d}{du}\ln\left(u\right)\frac{du}{dx}\\
& =-\frac{6}{u}\cdot1\\
& =-\frac{6}{x+8}.
\end{align*}\]
Hence, \[\begin{align*}
\frac{1}{y}\frac{dy}{dx} & =\frac{18}{2x+1}-\frac{3}{x-2}-\frac{6}{x+8}
\end{align*}\]
and \[\begin{align*}
\frac{dy}{dx} & =y\left(\frac{18}{2x+1}-\frac{3}{x-2}-\frac{6}{x+8}\right)\\
& =\frac{\left(2x+1\right)^{9}}{\left(x-2\right)^{3}\left(x+8\right)^{6}}\left(\frac{18}{2x+1}-\frac{3}{x-2}-\frac{6}{x+8}\right).
\end{align*}\]
Example 2
Differentiate \(y=2^{x}\) with respect to \(x\).
Solution
Take logs of both sides, \[\begin{align*}
\ln\left(y\right) & =\ln\left(2^{x}\right)\\
& =x\ln\left(2\right)\text{ using third log law }(\text{equation }\left(3\right)\text{ above). }
\end{align*}\]
Differentiating both sides, \[\begin{align*}
\frac{d}{dx}\left(\ln\left(y\right)\right) & =\frac{d}{dx}\left(x\ln\left(2\right)\right)\\
\frac{d}{dy}\left(\ln\left(y\right)\right)\frac{dy}{dx} & =\frac{d}{dx}\left(x\ln\left(2\right)\right)\text{ using the chain rule (equation$\left(4\right))$ on the left term}\\
\frac{1}{y}\frac{dy}{dx} & =\frac{d}{dx}\left(x\ln\left(2\right)\right)\\
& =\ln\left(2\right)\\
\frac{dy}{dx} & =y\left(\ln\left(2\right)\right)\\
& =2^{x}\ln\left(2\right).
\end{align*}\]
Example 3
Differentiate \(y=x^{x}.\)
Solution
Take logs of both sides, \[\begin{align*}
\ln\left(y\right) & =\ln\left(x^{x}\right)\\
& =x\ln\left(x\right).
\end{align*}\]
Differentiating, \[\begin{align*}
\frac{d}{dx}\left(\ln\left(y\right)\right) & =\frac{d}{dx}\left(x\ln\left(x\right)\right)\\
\frac{d}{dy}\left(\ln\left(y\right)\right)\frac{dy}{dx} & =\frac{d}{dx}\left(x\ln\left(x\right)\right)\text{ using the chain rule (equation$\left(4\right))$ on the left term}\\
\frac{1}{y}\frac{dy}{dx} & =\frac{d}{dx}\left(x\ln\left(x\right)\right)\\
& =\ln\left(x\right)+x\frac{d}{dx}\left(\ln\left(x\right)\right)\text{ using the product rule on the right term}\\
& =\ln\left(x\right)+1\\
\frac{dy}{dx} & =y\left(\ln\left(x\right)+1\right)\\
& =x^{x}\left(\ln\left(x\right)+1\right).
\end{align*}\]
Example 4
Differentiate \(y=\left(1-2x\right)^{\sin\left(x\right)}\) where \(x<0.5\ .\)
Solution
Take logs of both sides, \[\begin{align*}
\ln\left(y\right) & =\ln\left(1-2x\right)^{\sin\left(x\right)}\\
& =\sin\left(x\right)\ln\left(1-2x\right)\text{ using third log law 3 }(\text{equation }\left(3\right)\text{ above). }
\end{align*}\]
Differentiate both sides with respect to \(x:\) \[\begin{align*}
\frac{d}{dx}\ln\left(y\right) & =\frac{d}{dx}\left[\sin\left(x\right)\ln\left(1-2x\right)\right]\\
\frac{1}{y}\frac{dy}{dx} & =\frac{d}{dx}\left[\sin\left(x\right)\ln\left(1-2x\right)\right]\text{ using equation $\left(4\right)$ }\\
& =\frac{d}{dx}\left[\sin\left(x\right)\right]\ln\left(1-2x\right)+\frac{d}{dx}\left[\ln\left(1-2x\right)\right]\sin\left(x\right)\text{ by the product rule}\\
& =\cos\left(x\right)\ln\left(1-2x\right)+\left(-2\right)\frac{1}{\left(1-2x\right)}\sin\left(x\right)\text{ using the chain rule on the last term}\\
& =\cos\left(x\right)\ln\left(1-2x\right)-\frac{2}{\left(1-2x\right)}\sin\left(x\right).
\end{align*}\]
Now multiply both sides by \(y=\left(1-2x\right)^{\sin\left(x\right)}\)
to get the answer \[\begin{align*}
\frac{dy}{dx} & =\left(1-2x\right)^{\sin\left(x\right)}\left(\cos\left(x\right)\ln\left(1-2x\right)-\frac{2}{\left(1-2x\right)}\sin\left(x\right)\right).
\end{align*}\]
Exercises
Differentiate \(y=3^{x}\) with respect to \(x\) using logarithmic
differentiation.
Using logarithmic differentiation, differentiate with
respect to \(x\), \[\begin{align*}
y & =\frac{\left(x-1\right)^{3}}{\left(x+1\right)^{4}\left(2x+3\right)}
\end{align*}\]
for \(x>1.\)