Differentiation formulae

Fundamentals
Author

Chris Kelly

Published

February 8, 2024

What we are solving

Deriving why \(\frac{d}{dx} \left(x^{n} \right) = nx^{n-1}\)


Formulating an approach to the problem

The gradient between two points, \(x\) and \(a\), is equal to the change in the y axis divided by the change in the x axis.

For example, if \(y=f(x)=x^n\), then we can approximate the gradient as follows:

\[ \frac{\Delta y}{\Delta x} = \frac{f(x)-f(a)}{x-a} = \frac{x^n-a^n}{x-a} \]

This isn’t the same as saying a line which passes through both of these points has the same gradient though. There is a gap between this linear approximation and the exact curve.

However, the smaller the movement across the x-axis, the closer the approximation is to the actual curve. For example, in Figure 1 below, the line drawn between \(f(1)\) and \(f(2)\) is closer to the gradient at \(f(1)\) of the true curve, compared to the line drawn between \(f(1)\) and \(f(3)\).

Code
import plotly.graph_objects as go
import numpy as np

def interpolate(n,x1,x2,num=50):
  x = np.linspace(x1,x2,num)
  m = (x2**n - x1**n)/(x2 - x1)
  c = x1**n - m*x1
  y = m*x+c
  return({'x':x,'y':y})

n=3
actual = {'x': np.arange(0,4,0.1)}
actual['y'] = actual['x']**n
lb, ub = 1, [3.5,3,2]
lin0 = interpolate(n,lb,ub[0])
lin1 = interpolate(n,lb,ub[1])
lin2 = interpolate(n,lb,ub[2])

fig = go.Figure(data = go.Scatter(mode='lines'))
fig.add_trace( go.Scatter( x=actual['x'], y=actual['y'], line=dict(dash='solid'), name=f"f(x)=x^{n}" ))
fig.add_trace( go.Scatter( x=lin0['x'], y=lin0['y'], name=f"f({lb}) -> f({ub[0]})", line=dict(dash='dot') ))
fig.add_trace( go.Scatter( x=lin1['x'], y=lin1['y'], name=f"f({lb}) -> f({ub[1]})", line=dict(dash='dot') ))
fig.add_trace( go.Scatter( x=lin2['x'], y=lin2['y'], name=f"f({lb}) -> f({ub[2]})", line=dict(dash='dot') ))
fig.show()
Figure 1: The smaller the change in x, the closer the linear approximation is to the true gradient of f(x)

Consequently, we want to determine the gradient at the limit i.e. where \(a \rightarrow x\), to get the true gradient.

Factoring out \((x-a)\)

First though, let’s factor out the \(x-a\) term for simplicity. Let’s derive a generic formula for this:

  • If \(n=2\), then \(x^2-a^2 = (x-a)(x+a)\)
  • If \(n=3\), then \(x^3-a^3 = (x-a)(x^2+xa+a^2)\)
  • If \(n=4\), then \(x^4-a^4 = (x-a)(x^3+x^2a+xa^2+a^3)\)
  • If \(n=5\), then \(x^5-a^5 = (x-a)(x^4+x^3a+x^2a^2+xa^3+a^4)\)
  • And so on. In fact for any \(n\), we can derive \(x^n-a^n = (x-a)\sum_{i=1}^n \left( x^{n-i}a^{i-1} \right)\)

And we can now sub that into our formula, and the \(x-a\) cancels out:

\[ \frac{x^n-a^n}{x-a} = \frac{x-a}{x-a} \sum_{i=1}^n \left( x^{n-i}a^{i-1} \right) = \sum_{i=1}^n \left( x^{n-i}a^{i-1} \right) \]

Getting our result

And now let’s calculate the result in the limit, where \(x\) approaches \(a\):

\[ \lim_{x \rightarrow a} \sum_{i=1}^n \left( x^{n-i}a^{i-1} \right) \sim \sum_{i=1}^n \left( a^{n-i}a^{i-1} \right) = \sum_{i=1}^n \left( a^{n-1} \right) = na^{n-1} \]

Hence \(\frac{d}{dx} \left(x^{n} \right) = nx^{n-1}\).

Fin.