# Why does multiplying two first derivative finite difference matrices not give the matrix for the second derivative?

The finite difference matrix for the first derivative is

$\begin{bmatrix} -1 & 1 & 0 \\ 0 & -1 & 1 \\ 0 & 0 & -1 \end{bmatrix}$.

The finite difference matrix for the second derivative is

$\begin{bmatrix} -2 & 1 & 0 \\ 1 & -2 & 1 \\ 0 & 1 & -2 \end{bmatrix}$.

$\begin{bmatrix} -1 & 1 & 0 \\ 0 & -1 & 1 \\ 0 & 0 & -1 \end{bmatrix} \begin{bmatrix} -1 & 1 & 0 \\ 0 & -1 & 1 \\ 0 & 0 & -1 \end{bmatrix} = \begin{bmatrix} 1 & -2 & 1 \\ 0 & 1 & -2 \\ 0 & 0 & 1 \end{bmatrix}$.

Why does multiplying together two first derivative matrices not give the second derivative matrix?

• This is simply because $D_+ D_+ \neq D^2$ you need the information before and behind (to get the same stencil). Try multiplying $D_+ D_-$ (the forward diff operator and backward). Commented Jul 20, 2017 at 18:29
• Thanks, however, I am wondering something like the following: $\frac{d}{dx} \frac{df}{dx} = \frac{d^2f}{dx^2}$, so why does $D(Df) \neq D^2f$? You are taking the derivative of the derivative of $f$, so why do you not get the second derivative of $f$? Commented Jul 20, 2017 at 18:37
• You do get D^2, just not the approximation you're thinking of. Try expanding these operators in a taylor series to see. Commented Jul 20, 2017 at 18:43
• It would probably be better if you didn't think of your second matrix in the question as the FD matrix, but rather a FD matrix. Commented Jul 20, 2017 at 18:48
• That's exactly the point. Just like there is a forward and a backward first derivative matrix, there are multiple choices to compute second derivatives. $D_+D_+$ happens to be one of them, just not the one you've seen before. Commented Jul 20, 2017 at 20:29

Look at the operators $$D_+^2 u = \frac{u_{n+2} - 2 u_{n+1} + u_n}{\Delta x^2}.$$ If you taylor expand this for small $\Delta x$ you arrive at $$D_+^2 u = u_{xx} - \Delta x u_{xxx} + O(\Delta x^2)$$. Thus $D_+^2 = D^2$ in the limit as $\Delta x \to 0$ (as it should), but note the error is first order in $\Delta x$ and so it is not a great approximation.

Consider instead, the one you are thinking of $$D_- D_+ u = \frac{u_{n+1} - 2 u_n + u_{n-1}}{\Delta x^2}.$$ Again taking a taylor expansion we have $$D_- D_+ u = u_{xx} + \frac{\Delta x^2}{12} u_{xxxx} + O(\Delta x^4).$$ Thus this approximation is actually better since the error goes down quadratically rather than linearly.

However in the limit they are equivalent.

• What is the higher-order analog of this? Commented Jun 4 at 21:17

Your matrices are not well defined. The second derivative operator for example, takes three consecutive data values and outputs one second derivative value. That is not expressed by writing a square matrix.

There is a well-recognised Calculus of Finite Differences. You can find books with that phrase in the title, and you will find everything to be consistent and useful

• Would the downvoter care to explain?? Commented Jul 21, 2017 at 13:48