Skip to main content

Section 12.3 Symmetric difference formulas

Although the formula (12.1.1) looks natural, it is not the best way to find the approximate value of \(f'(x)\text{.}\) The following symmetric difference formula works better:

\begin{equation} f'(x) \approx \frac{f(x+h)-f(x-h)}{2h}\label{eq-diff-f1-symm}\tag{12.3.1} \end{equation}

The following computation explains why.

Find the order of error of the formula (12.3.1).

Solution
  • With \(f(x) = x^0\) we get \(f'(x) = 0\) and \(\frac{f(x+h)-f(x-h)}{2h}=0\text{,}\) so the error term is zero for this function.
  • With \(f(x) = x^1\) we get \(f'(x) = 1\) and \(\frac{f(x+h)-f(x-h)}{2h}=\frac{2h}{2h}=1\text{,}\) so the error term is zero for this function.
  • With \(f(x) = x^2\) we get \(f'(x) = 2x\) and \(\frac{f(x+h)-f(x-h)}{2h}=\frac{4xh}{2h}=2x\text{,}\) so the error term is zero for this function.
  • With \(f(x) = x^3\) we get \(f'(x) = 3x^2\) and \(\frac{f(x+h)-f(x-h)}{2h}=\frac{6x^2h +2h^3}{2h}=3x^2 + h^2\text{,}\) so the error term for this function is \(h^2\text{.}\)

In conclusion, the formula has order of error equal to 2.

Here is a quick computation in Matlab console which compares the performance of both formulas on the function \(f(x) = e^x\) at \(x = 0\) with \(h = 0.1\text{.}\) The error of symmetric difference formula is about 30 times smaller in this example, despite the same value of \(h\) and the same amount of computations involved.

>> x = 0; h = 0.1;
>> (exp(x+h)-exp(x))/h
ans = 1.0517
>> (exp(x+h)-exp(x-h))/(2*h)
ans = 1.0017

The second order derivative also has a convenient symmetric formula:

\begin{equation} f''(x)\approx \frac{f(x+h)-2f(x)+f(x-h)}{h^2}\label{eq-diff-f2}\tag{12.3.2} \end{equation}

One can derive many other formulas for derivative of any order \(k\text{,}\) starting with Taylor series for \(f\text{:}\)

\begin{equation} f(x + \delta) = f(x) + f'(x)\delta + \frac{f''(x)}{2} \delta^2 + \frac{f'''(x)}{6} \delta^3 + \cdots\label{eq-taylor-expansion}\tag{12.3.3} \end{equation}

One can use (12.3.3) with values like \(\delta=h\text{,}\) \(\delta=-h\text{,}\) \(\delta=0\text{,}\) or maybe \(\delta=2h\text{,}\) and so on; and then take a linear combination of these expressions so that the derivatives of orders less than \(k\) cancel out, while the derivative of order \(k\) remains. The order of error of this formula will depends on what derivative of order greater than \(k\) remain in the linear combination. To have order of error \(n\text{,}\) one needs to make sure that the derivatives of orders between \(k\) and \(k+n\) also cancel out.