- #1
Telemachus
- 835
- 30
Hi. I have written a code which solves a pde using finite differences. I won't post the code, because it's too long, and I want to discuss something specific on finite difference regarding theory.
It can be proven that the forward finite difference first derivative can be obtained from the following expansion:
##\left. \frac{dy}{dx}^+\right|_i=\frac{1}{\Delta x}\left[ \Delta-\frac{1}{2}\Delta^2+\frac{1}{3}\Delta^3+...\right] y_i##
Where ##y_i=y(x_i)=y(i\Delta x)##, and where ##\Delta## represents the finite difference operator: ##\Delta y_i=y_{i+1}-y_i##.
When one approximates the differential operator on the left by cutting the series expansion on the right, a finite difference approximation of order ##\mathcal{O}(\Delta x^n)## is obtained, where n is related to the first term ignored in the series.
However, other representations in finite differences of the differential operator might be obtained by evaluating the right hand side of the equation at other grid points.
It can be proven that ##\frac{d}{dx}^+=\frac{1}{\Delta x}\log(1+\Delta)##, so:
##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)y_i##, the series representation given above is the corresponding for the operator on the right hand side of the last equation. However, this can also be written as: ##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)(1+\Delta)^k y_{i-k}##
So other series representation for the differential operator in terms of finite difference operator might be obtained by expanding this alternative operator, which allows to obtain the finite difference derivative at point i, with points evaluated from (i-k) in the mesh.
Now here is my doubt. I have worked with this two finite difference derivatives, the one obtained from ##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)y_i## and the one obtained from ##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)(1+\Delta) y_{i-1}##.
The thing is that I expected to obtain the same accuracy for both derivatives. Up to the third order, those derivatives are:
##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\left [ 2y_{i+3}-9y_{i+2}+18y_{i+1}-11y_i\right ]##.
Using the alternative form of the expansion for the forward derivative, which computes the derivative using one previous step, this is obtained:
##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\left [ -y_{i+2}+6y_{i+1}-3y_i- 2y_{i-1}\right ]##.
The last form of the derivative used in my code gives better results than the first one, and I don't know why. It would look like if the last representation would suffer less dispersive error than the first one. I have checked the code several times, and I have also redone all the algebra to derive the finite difference formulas, and I think they are correct, but I don't know why one is better than the other.
Thanks in advance.
PS: I've been thinking, and what I've noted is that in one way the matrix representation of the finite difference operator for the derivative is more diagonally dominant than in the other. I wonder if this could be affecting some how.
It can be proven that the forward finite difference first derivative can be obtained from the following expansion:
##\left. \frac{dy}{dx}^+\right|_i=\frac{1}{\Delta x}\left[ \Delta-\frac{1}{2}\Delta^2+\frac{1}{3}\Delta^3+...\right] y_i##
Where ##y_i=y(x_i)=y(i\Delta x)##, and where ##\Delta## represents the finite difference operator: ##\Delta y_i=y_{i+1}-y_i##.
When one approximates the differential operator on the left by cutting the series expansion on the right, a finite difference approximation of order ##\mathcal{O}(\Delta x^n)## is obtained, where n is related to the first term ignored in the series.
However, other representations in finite differences of the differential operator might be obtained by evaluating the right hand side of the equation at other grid points.
It can be proven that ##\frac{d}{dx}^+=\frac{1}{\Delta x}\log(1+\Delta)##, so:
##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)y_i##, the series representation given above is the corresponding for the operator on the right hand side of the last equation. However, this can also be written as: ##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)(1+\Delta)^k y_{i-k}##
So other series representation for the differential operator in terms of finite difference operator might be obtained by expanding this alternative operator, which allows to obtain the finite difference derivative at point i, with points evaluated from (i-k) in the mesh.
Now here is my doubt. I have worked with this two finite difference derivatives, the one obtained from ##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)y_i## and the one obtained from ##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\log(1+\Delta)(1+\Delta) y_{i-1}##.
The thing is that I expected to obtain the same accuracy for both derivatives. Up to the third order, those derivatives are:
##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\left [ 2y_{i+3}-9y_{i+2}+18y_{i+1}-11y_i\right ]##.
Using the alternative form of the expansion for the forward derivative, which computes the derivative using one previous step, this is obtained:
##\frac{d}{dx}^+y_i=\frac{1}{\Delta x}\left [ -y_{i+2}+6y_{i+1}-3y_i- 2y_{i-1}\right ]##.
The last form of the derivative used in my code gives better results than the first one, and I don't know why. It would look like if the last representation would suffer less dispersive error than the first one. I have checked the code several times, and I have also redone all the algebra to derive the finite difference formulas, and I think they are correct, but I don't know why one is better than the other.
Thanks in advance.
PS: I've been thinking, and what I've noted is that in one way the matrix representation of the finite difference operator for the derivative is more diagonally dominant than in the other. I wonder if this could be affecting some how.
Last edited: