# Logarithmic Differentiation

The calculation of derivatives of functions involving products, powers or quotients can be simplified with the logarithmic differentiation (because of the properties of logarithms).

Let's first see how to differentiate functions that already have product and/or quotient under logarithm.

**Example 1.** Find derivative of `y=ln((cos(x))/(x^2+1))`

First we use properties of logarithms to simplify expression: `y=ln(cos(x))-ln(x^2+1)`.

`y'=(ln(cos(x))-ln(x^2+1))'=(ln(cos(x)))'-(ln(x^2+1))'=`

`=1/(cos(x))*(cos(x))'-1/(x^2+1)*(x^2+1)'=`

`=1/(cos(x))*(-sin(x))-1/(x^2+1)*2x=-tan(x)-(2x)/(x^2+1)` .

But what to do if we have products and powers, but don't have logarithm? Answer is to add logarithm, in other words take logarithm of both sides of function**.**

**Steps in Logarithmic Differentiation**:

- Take natural logarithms of both sides of an equation and use the Properties of Logarithms to simplify.
- Differentiate implicitly with respect to `x` (or other independent variable).
- Solve the resulting equation for `y`.

**Example 2.** Find derivative of `y=(x^3sin(x))/(x^2+4x+1)^5`.

Without logarithmic differentiation we need to use product and quotient rules. The calculations will be very complex.

So, we use logarithmic differentiation.

`ln(y)=ln((x^3sin(x))/(x^2+4x+1)^5)`

`ln(y)=ln(x^3sin(x))-ln((x^2+4x+1)^5)`

`ln(y)=ln(x^3)+ln(sin(x))-5ln(x^2+4x+1)`

`ln(y)=3ln(x)+ln(sin(x))-5ln(x^2+4x+1)`.

Differentiate implicitly with respect to `x`:

`1/y y'=3/x+1/(sin(x))*(sin(x))'-5/(x^2+4x+1)*(x^2+4x+1)'`

`1/y y'=3/x+1/(sin(x))*cos(x)-5/(x^2+4x+1)*(2x+4)`

`1/y y'=3/x+cot(x)-10(x+2)/(x^2+4x+1)`

`y'=y(3/x+cot(x)-10(x+2)/(x^2+4x+1))`

`y'=(x^3sin(x))/(x^2+4x+1)^5(3/x+cot(x)-10(x+2)/(x^2+4x+1))`.

Using logarithmic function we can easily prove that `(x^n)'=nx^(n-1)` for any real number `n`.

Indeed, let `y=x^n` then

`ln(y)=ln(x^n)` or `ln(y)=nln(x)` (`x!=0`).

Differentiating implicitly with respect to `x` gives: `1/y y'=n/x`.

So, `y'=n y/x=n(x^n)/x=nx^(n-1)`.

**Example 3.** Find derivative of `y=x^x` .

*Solution 1*. Use logarithmic differentiation:

`ln(y)=ln(x^x)=xln(x)`.

Differentiate implicitly with respect to `x`. Note, that in right part we need to use product rule.

`1/y y'=x'(ln(x))+x(ln(x))'`

`1/y y'=ln(x)+1`

`y'=y(ln(x)+1)`

`y'=x^x(ln(x)+1)`.

So, `(x^x)'=x^x(ln(x)+1)`.

*Solution 2*. We can represent `x^x` as `x^x=e^(ln(x^x))=e^(xln(x))`

`(x^x)'=(e^(xln(x)))'=e^(xln(x))*(xln(x))'=x^x((x')ln(x)+x(ln(x))')=x^x(ln(x)+1)`.

In general if you have function of the form `h(x)=f(x)^(g(x))` then you should one of two techniques presented in the Example 3.

**Example 4.** Differentiate `y=sin(x)^(x^2+1)`

`ln(y)=ln(sin(x)^(x^2+1))=(x^2+1)ln(sin(x))`

Differentiating implicitly with respect to `x` gives:

`1/y y'=(x^2+1)'ln(sin(x))+(x^2+1)(ln(sin(x)))'`

`1/y y'=2xln(sin(x))+(x^2+1)1/(sin(x))*(sin(x))'`

`1/y y'=2xln(sin(x))+(x^2+1)1/(sin(x))*cos(x)`

`1/y y'=2xln(sin(x))+(x^2+1)cot(x)`

`y'=y(2xln(sin(x))+(x^2+1)cot(x))`

`y'=sin(x)^(x^2+1)(2xln(sin(x))+(x^2+1)cot(x))`.