Product Rule

Product Rule#

Suppose we want to differentiate \(y=x^2\sin(x)\), then we encounter a problem: How to differentiate a function that is the product of two other functions, in this case \(x^2\) and \(\sin(x)\).

To do this, we need the product rule:

If the function \(y = f(x)\) is written as the product of two functions, say \(u(x)\) and \(v(x)\) so

\(y = f(x) = u(x)v(x)\) then \(\frac{dy}{dx} = u\frac{dv}{dx} + v\frac{du}{dx}\).

So returning to our example, we have \(f(x) = x^2\sin(x)\) with \(u=x^2\) and \(v = \sin(x)\).

First, we find that \(\frac{du}{dx} = 2x\) and \(\frac{dv}{dx} = \cos(x)\), then we substitute into \(\frac{dy}{dx} = u\frac{dv}{dx} + v\frac{du}{dx}\).

\[\begin{split} \begin{aligned} \frac{dy}{dx} & = x^2 \cos(x) + \sin(x)2x \\ & = x[x \cos(x) + 2\sin(x)] \end{aligned} \end{split}\]

Example

Differentiate using the product rule:

  1. \(y = x\ln(x)\)

  2. \(y = 6e^x \cos(x)\)

Solution:

  1. Take \(u = x\) and \(v = \ln(x)\). We can now differentiate these to find that \(\frac{du}{dx} = 1\) and that \(\frac{dv}{dx} = \frac{1}{x}\).

  • Using the product rule:

\[ \frac{dy}{dx} = u\frac{du}{dx} + v\frac{du}{dx} \]
  • Substitue in the quantities:

\[ \frac{dy}{dx} = x\left[\frac{1}{x}\right] + \ln(x) (1) \]
  • Expand and simplify:

\[ \frac{dy}{dx} = 1 + \ln(x) \]
  1. For this, take \(u=6e^x\) and \(v=\cos(x)\). Now we differentiate those to find that \(\frac{du}{x} = 6e^x\) and \(\frac{dv}{dx} = -\sin(x)\).

  • By the product rule, we have:

\[ \frac{dy}{dx} = u\frac{dv}{dx} + v\frac{du}{dx} \]
  • Substitute in the quantities:

\[ \frac{dy}{dx} = 6e^x\left[\sin(x)\right] + \cos(x) \left[6e^x\right] \]
  • Expand the brackets:

\[ \frac{dy}{dx} = -6e^x\sin(x) + 6e^x\cos(x) \]
  • Take a factor of \(6e^x\) out:

\[ \frac{dy}{dx} = 6e^x\left[\cos(x) - \sin(x)\right] \]

These can both be performed with sympy.

from sympy import symbols, diff, log, cos, exp

x = symbols('x')
diff(x * log(x))
\[\displaystyle \log{\left(x \right)} + 1\]
diff(6 * exp(x) * cos(x))
\[\displaystyle - 6 e^{x} \sin{\left(x \right)} + 6 e^{x} \cos{\left(x \right)}\]

Example

Differentiate \(y = \frac{1}{3}(x^2 + 5x) \sin(x)\).

Solution: This is a product of two functions and we must use the product rule.

Set \(u=\frac{1}{3}(x^2 + 5x)\) and \(v = \sin(x)\).

We can differentiate to find that \(\frac{du}{dx} = \frac{1}{3}(2x+5)\) and \(\frac{dv}{dx} = \cos(x)\).

  • We now use the product rule:

\[ \frac{dy}{dx} = u\frac{dv}{dx} + v\frac{du}{dx} \]
  • Substitute in what we’ve worked out:

\[ \frac{dy}{dx} = \frac{1}{3} (x^2 + 5x) \left[\cos(x)\right] + \sin(x) \left[\frac{1}{3}(2x + 5)\right] \]
  • Simplify by taking a factor of \(\frac{1}{3}\) out

\[ \frac{dy}{dx} = \frac{1}{3}\left[(x^2 + 5x) \cos(x) + (2x+5)\sin(x)\right] \]

The end result looks complicated and ugly, but it is nicer than having all the brackets expanded.


We can check the result with sympy.

from sympy import sin

diff((1 / 3) * (x ** 2 + 5 * x) * sin(x))
\[\displaystyle \left(0.666666666666667 x + 1.66666666666667\right) \sin{\left(x \right)} + \left(0.333333333333333 x^{2} + 1.66666666666667 x\right) \cos{\left(x \right)}\]

Again this is quite ugly but we can see that the answer is correct.