When to take logs
You know how to differentiate \(x^5\) (power rule, the power is a constant) and \(5^x\) (exponential rule, the base is a constant). Now try \(x^x\). The base and the power both change with \(x\), so neither rule applies. Using either one gives a wrong answer.
The way out is to take logarithms first. A log brings the power down in front, where it becomes an ordinary product: \(\log\big(x^x\big) = x\log x\). That you can differentiate.
Take logs in two situations:
- A variable raised to a variable power, such as \(x^x\), \((\sin x)^x\), \(x^{\sin x}\) or \((\log x)^x\). This is where logs are needed.
- A long product or quotient of powers, such as \(\dfrac{(x + 1)^2(x - 2)^3}{(x + 3)^4}\). The product and quotient rules would work, but logs turn the whole thing into a short sum.
If \(y = u^v\), where \(u\) and \(v\) are functions of \(x\) and \(u > 0\), then \(\log y = v\log u\), and differentiating gives
\[\frac{dy}{dx} = u^v\left(v'\log u + \frac{v\,u'}{u}\right)\]
Don't memorise this formula. Learn the method below, which produces it every time. As a check: \(u^v = e^{v\log u}\), and the chain rule on the right-hand side gives exactly the same answer. Here \(\log\) means the natural log, base \(e\).
The method
- Write \(y = \ldots\) If the right side is a sum of awkward terms, name them \(u\), \(v\), and so on, and do steps 2 to 4 for each one separately. Then \(\dfrac{dy}{dx} = \dfrac{du}{dx} + \dfrac{dv}{dx}\).
- Take log of both sides and use the log rules to bring powers down and split products and quotients.
- Differentiate both sides with respect to \(x\). The left side becomes \(\dfrac{1}{y}\dfrac{dy}{dx}\), by the chain rule.
- Multiply by \(y\) and write \(y\) back in terms of \(x\).
| Log rule | What it does |
|---|---|
| \(\log(ab) = \log a + \log b\) | product becomes a sum |
| \(\log\dfrac{a}{b} = \log a - \log b\) | quotient becomes a difference |
| \(\log a^n = n\log a\) | power comes down |
| \(\dfrac{d}{dx}\log y = \dfrac{1}{y}\dfrac{dy}{dx}\) | differentiating the left side |
Logs need positive numbers, so questions of this type assume the base is positive: \(x > 0\) for \(x^x\), and \(0 < x < \pi\) for \((\sin x)^x\). For a product that might be negative, use \(\log|y|\) instead. Its derivative is still \(\dfrac{1}{y}\dfrac{dy}{dx}\), so the working is identical.
Solved examples
Example 1: x to the power x
EasyDifferentiate \(y = x^x\), \(x > 0\).
- Take logs: \(\log y = x\log x\).
- Differentiate (product rule on the right): \(\dfrac{1}{y}\dfrac{dy}{dx} = 1\cdot\log x + x\cdot\dfrac{1}{x} = \log x + 1\).
- Multiply by \(y = x^x\).
Answer\(\dfrac{dy}{dx} = x^x(1 + \log x)\)
Example 2: A trig function as the power
EasyDifferentiate \(y = x^{\sin x}\), \(x > 0\).
- \(\log y = \sin x\,\log x\).
- \(\dfrac{1}{y}\dfrac{dy}{dx} = \cos x\,\log x + \dfrac{\sin x}{x}\).
Answer\[\frac{dy}{dx} = x^{\sin x}\left(\cos x\log x + \frac{\sin x}{x}\right)\]
Example 3: A trig function as the base
MediumDifferentiate \(y = (\sin x)^x\), \(0 < x < \pi\).
- \(\log y = x\log(\sin x)\).
- Product rule, with the chain rule on \(\log(\sin x)\): \(\dfrac{1}{y}\dfrac{dy}{dx} = \log(\sin x) + x\cdot\dfrac{\cos x}{\sin x}\).
- \(\dfrac{\cos x}{\sin x} = \cot x\). Multiply by \(y\).
Answer\(\dfrac{dy}{dx} = (\sin x)^x\big(\log\sin x + x\cot x\big)\)
Example 4: A long quotient
MediumDifferentiate \(y = \dfrac{(x + 1)^2(x - 2)^3}{(x + 3)^4}\), for \(x > 2\).
- Take logs: \[\log y = 2\log(x + 1) + 3\log(x - 2) - 4\log(x + 3)\]
- Differentiate term by term: \(\dfrac{1}{y}\dfrac{dy}{dx} = \dfrac{2}{x + 1} + \dfrac{3}{x - 2} - \dfrac{4}{x + 3}\).
- Multiply by \(y\). You may leave \(y\) in the answer as the original expression.
Answer\[\frac{dy}{dx} = \frac{(x + 1)^2(x - 2)^3}{(x + 3)^4}\left(\frac{2}{x + 1} + \frac{3}{x - 2} - \frac{4}{x + 3}\right)\]
Example 5: A sum: split it first
MediumDifferentiate \(y = x^x + (\sin x)^x\), \(0 < x < \pi\).
- Do not take log of \(y\) here. \(\log(u + v)\) does not split into anything useful.
- Let \(u = x^x\) and \(v = (\sin x)^x\), so \(\dfrac{dy}{dx} = \dfrac{du}{dx} + \dfrac{dv}{dx}\).
- From Example 1, \(\dfrac{du}{dx} = x^x(1 + \log x)\). From Example 3, \(\dfrac{dv}{dx} = (\sin x)^x(\log\sin x + x\cot x)\).
Answer\[\frac{dy}{dx} = x^x(1 + \log x) + (\sin x)^x(\log\sin x + x\cot x)\]
Example 6: Logs inside and out
Exam levelDifferentiate \(y = (\log x)^x + x^{\log x}\), \(x > 1\).
- Split: \(u = (\log x)^x\), \(v = x^{\log x}\).
- \(\log u = x\log(\log x)\). Differentiate: \(\dfrac{1}{u}\dfrac{du}{dx} = \log(\log x) + x\cdot\dfrac{1}{\log x}\cdot\dfrac{1}{x}\), which simplifies to \(\log(\log x) + \dfrac{1}{\log x}\).
- \(\log v = \log x\cdot\log x = (\log x)^2\), so \(\dfrac{1}{v}\dfrac{dv}{dx} = \dfrac{2\log x}{x}\).
- Add \(\dfrac{du}{dx}\) and \(\dfrac{dv}{dx}\).
Answer\[\frac{dy}{dx} = (\log x)^x\left(\log\log x + \frac{1}{\log x}\right) + x^{\log x}\cdot\frac{2\log x}{x}\]
Example 7: x to the y equals y to the x
Exam levelIf \(x^y = y^x\), find \(\dfrac{dy}{dx}\).
- Take logs: \(y\log x = x\log y\).
- Differentiate both sides, with the product rule on each: \[\frac{dy}{dx}\log x + \frac{y}{x} = \log y + \frac{x}{y}\frac{dy}{dx}\]
- Collect: \(\left(\log x - \dfrac{x}{y}\right)\dfrac{dy}{dx} = \log y - \dfrac{y}{x}\).
- Multiply the top and bottom of the resulting fraction by \(xy\) to clear the small fractions.
Answer\(\dfrac{dy}{dx} = \dfrac{y(x\log y - y)}{x(y\log x - x)}\)
Example 8: A classic show-that
Exam levelIf \(x^y = e^{x - y}\), show that \(\dfrac{dy}{dx} = \dfrac{\log x}{(1 + \log x)^2}\).
- Take logs: \(y\log x = x - y\).
- Here you can solve for \(y\): \(y(1 + \log x) = x\), so \(y = \dfrac{x}{1 + \log x}\).
- Quotient rule: \(\dfrac{dy}{dx} = \dfrac{(1 + \log x)\cdot 1 - x\cdot\frac{1}{x}}{(1 + \log x)^2}\).
- The numerator is \(1 + \log x - 1 = \log x\).
Answer\(\dfrac{dy}{dx} = \dfrac{\log x}{(1 + \log x)^2}\)
Before you take logs, look at the right-hand side and ask one question: is there a plus or minus sign between whole terms? If there is, split into \(u + v\) first. That one check saves a lot of lost marks.
Common mistakes
1. Taking the log of a sum
For \(y = x^x + (\sin x)^x\), writing \(\log y = x\log x + x\log\sin x\) is wrong. \(\log(u + v)\) is not \(\log u + \log v\); that rule is for products. Differentiate each term separately, as in Example 5.
2. Using the power rule or the exponential rule on x to the x
The power rule gives \(x\cdot x^{x - 1} = x^x\). The exponential rule gives \(x^x\log x\). Both are wrong. The right answer, \(x^x(1 + \log x)\), happens to be the sum of the two wrong ones.
3. Stopping at (1/y)(dy/dx)
After differentiating \(\log y = x\log x\) you have \(\dfrac{1}{y}\dfrac{dy}{dx} = 1 + \log x\). That is not yet the answer. Multiply by \(y\) and replace it with \(x^x\).
Practice questions
Try each one on paper before you open the answer.
Q1Differentiate \(y = x^{2x}\), \(x > 0\).
\(\log y = 2x\log x\), so \(\dfrac{1}{y}\dfrac{dy}{dx} = 2\log x + 2\).
\(\dfrac{dy}{dx} = 2x^{2x}(1 + \log x)\).
Q2Differentiate \(y = x^{1/x}\), \(x > 0\).
\(\log y = \dfrac{\log x}{x}\), so \(\dfrac{1}{y}\dfrac{dy}{dx} = \dfrac{1 - \log x}{x^2}\) by the quotient rule.
\(\dfrac{dy}{dx} = x^{1/x}\cdot\dfrac{1 - \log x}{x^2}\).
Q3Differentiate \(y = (\cos x)^{\sin x}\), \(0 < x < \dfrac{\pi}{2}\).
\(\log y = \sin x\log\cos x\), so \(\dfrac{1}{y}\dfrac{dy}{dx} = \cos x\log\cos x + \sin x\cdot\dfrac{-\sin x}{\cos x}\).
\[\frac{dy}{dx} = (\cos x)^{\sin x}\big(\cos x\log\cos x - \sin x\tan x\big)\]
Q4Differentiate \(y = \sqrt{\dfrac{(x - 1)(x - 2)}{(x - 3)(x - 4)}}\), for \(x > 4\).
Take logs: \[\log y = \tfrac{1}{2}\big[\log(x - 1) + \log(x - 2) - \log(x - 3) - \log(x - 4)\big]\]
\[\frac{dy}{dx} = \frac{y}{2}\left(\frac{1}{x - 1} + \frac{1}{x - 2} - \frac{1}{x - 3} - \frac{1}{x - 4}\right)\]
Q5Differentiate \(y = x^{\sin x} + (\sin x)^{\cos x}\), \(0 < x < \pi\).
First term: Example 2. Second term: \(\log v = \cos x\log\sin x\), so \(\dfrac{1}{v}\dfrac{dv}{dx} = -\sin x\log\sin x + \cos x\cot x\).
\[\frac{dy}{dx} = x^{\sin x}\left(\cos x\log x + \frac{\sin x}{x}\right) + (\sin x)^{\cos x}\big(\cos x\cot x - \sin x\log\sin x\big)\]
Q6If \(x^y + y^x = c\), where \(c\) is a constant, find \(\dfrac{dy}{dx}\).
Split: \(u = x^y\), \(v = y^x\), and \(\dfrac{du}{dx} + \dfrac{dv}{dx} = 0\).
\(\log u = y\log x\) gives \(\dfrac{du}{dx} = x^y\left(\dfrac{dy}{dx}\log x + \dfrac{y}{x}\right)\). \(\log v = x\log y\) gives \(\dfrac{dv}{dx} = y^x\left(\log y + \dfrac{x}{y}\dfrac{dy}{dx}\right)\).
Collect the \(\dfrac{dy}{dx}\) terms: \[\frac{dy}{dx} = -\frac{yx^{y-1} + y^x\log y}{x^y\log x + xy^{x-1}}\]
Bring it to a free demo class and work through it with Vipul Sir. Book on WhatsApp.
Frequently asked questions
What is logarithmic differentiation?
A method where you take the natural log of both sides of \(y = f(x)\) before differentiating. Logs turn powers into products and products into sums, which are easier to differentiate. The left side becomes \(\dfrac{1}{y}\dfrac{dy}{dx}\), and you multiply by \(y\) at the end.
When should I use logarithmic differentiation?
When the variable appears in both the base and the power, like \(x^x\) or \((\sin x)^{\cos x}\), and when you have a long product or quotient of powers. For a simple product of two functions, the product rule is quicker.
What is the derivative of x^x?
\(x^x(1 + \log x)\), for \(x > 0\). Take logs to get \(\log y = x\log x\), differentiate to get \(\dfrac{1}{y}\dfrac{dy}{dx} = \log x + 1\), then multiply by \(y\).
Can I take logs when y is a sum of terms?
Not usefully, because the log of a sum does not split. Put \(y = u + v\), find \(\dfrac{du}{dx}\) and \(\dfrac{dv}{dx}\) separately (using logs on each if needed), and add them.