Question about finite differences

  • Thread starter Telemachus
  • Start date
  • Tags
    Finite
In summary: There are two finite difference schemes that can be used to solve the pde: the 6 point scheme and the 3 point scheme. The 6 point scheme is more accurate, but is more diagonally dominant. The 3 point scheme is less accurate, but is less diagonally dominant. You may be able to obtain a stable scheme by decreasing the size of the time steps.
  • #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.
 
Last edited:
  • Like
Likes Delta2
Technology news on Phys.org
  • #2
What pde and bc’s are you trying to solve?
 
  • Like
Likes Telemachus
  • #3
I am solving the 2D time dependent advection equation on a square with Dirichlet boundary conditions. I am using forward Euler in time. I am trying to avoid looking for the eigenvalues of the finite difference matrix to see the stability issue, but I have today worked with a 6 points formula (##\Delta x^5## accuracy), and it looked like I should take excessively small time steps to get stability.
 
  • Like
Likes Delta2
  • #4
Telemachus said:
I am solving the 2D time dependent advection equation on a square with Dirichlet boundary conditions. I am using forward Euler in time. I am trying to avoid looking for the eigenvalues of the finite difference matrix to see the stability issue, but I have today worked with a 6 points formula (##\Delta x^5## accuracy), and it looked like I should take excessively small time steps to get stability.
Only advection, but no diffusion?
 
  • Like
Likes Telemachus
  • #5
Chestermiller said:
Only advection, but no diffusion?

Yes, advection only.

##\frac{\partial u}{\partial t} + \frac{\partial u}{\partial x}+\frac{\partial u}{\partial y}=q(\mathbf{r},t)##,
with ##u(x=0,y,t)=u(x,y=0,t)=u(x,y,t=0)=0##
 
  • #6
Telemachus said:
Yes, advection only.

##\frac{\partial u}{\partial t} + \frac{\partial u}{\partial x}+\frac{\partial u}{\partial y}=q(\mathbf{r},t)##,
with ##u(x=0,y,t)=u(x,y=0,t)=u(x,y,t=0)=0##
Because the velocity is constant, this can be solved by the method of characteristics. Are you not allowed to use that?
 
  • #7
No, I want to solve the pde as it stands using finite differences because it is part of a bigger solver. The signs of the spatial derivatives should be negative in my previous post, I'm not allowed to edit anymore. And anyway, I would like to know what is happening with the different finite difference schemes, why two schemes, both being third order, one works better than the other? and why I haven't been able to obtain a stable scheme for finite differences of bigger order? I am working now with the six point derivative, I have tried with a lot of points in the time derivative, being the time steps four orders of magnitude smaller than the spatial step, and it still being unstable.
 
  • #8
You can still solve the equation using finite differences, based on the method of characteristics. As far as the difference scheme you are presently using is concerned, I would exercise caution, particularly since you are using a forward Euler in time, which tends to result in stability issues.
 
  • Like
Likes Telemachus
  • #9
There is something I haven't mentioned. At the points close to the boundary, I am using a different treatment for the derivatives. At those points, I have to use only one sided derivatives, so the scheme I am using in the interior of the domain, and in points close to the boundaries are different, in a way that I can use 5th order finite differences everywhere. However, I am not able to make it work.
 
  • #10
Telemachus said:
There is something I haven't mentioned. At the points close to the boundary, I am using a different treatment for the derivatives. At those points, I have to use only one sided derivatives, so the scheme I am using in the interior of the domain, and in points close to the boundaries are different, in a way that I can use 5th order finite differences everywhere. However, I am not able to make it work.
I'm not surprised. This is a very nasty problem mathematically. How accurate does this thing have to be? If not very accurate, just use upwind differencing.
 
  • Like
Likes Telemachus
  • #11
Ok, I'll see what can I do.
 

1. What is the definition of finite differences?

Finite differences refer to the mathematical technique of approximating derivatives of a function by taking the difference between two consecutive values of the function at discrete points. It is commonly used in numerical analysis and is particularly useful for solving differential equations.

2. How is the finite difference method used in scientific research?

The finite difference method is used to solve a variety of problems in different scientific fields, including physics, engineering, and computer science. It is commonly used to solve differential equations, simulate physical systems, and analyze data. The method allows for the numerical approximation of complex systems and can provide valuable insights into real-world phenomena.

3. What is the difference between forward, backward, and central finite differences?

Forward finite differences involve taking the difference between a function value at a given point and a subsequent point. Backward finite differences involve taking the difference between a function value at a given point and a previous point. Central finite differences involve taking the average of the forward and backward finite differences. Each type of finite difference has its own advantages and disadvantages, and the choice of which to use depends on the specific problem being solved.

4. Can finite differences be used in higher dimensions?

Yes, the concept of finite differences can be extended to higher dimensions. In two dimensions, for example, the finite difference method involves taking differences in two directions: one in the x-direction and one in the y-direction. This is often used in analyzing partial differential equations. The method can also be extended to three or more dimensions, although it becomes more computationally intensive.

5. Are there any limitations to using finite differences?

While finite differences can be a powerful tool in numerical analysis, there are some limitations to its use. One limitation is that it can only approximate derivatives at discrete points, which may not accurately represent the behavior of a function in between those points. Additionally, as the number of dimensions increases, the computational complexity also increases, making it more difficult to solve certain problems using finite differences.

Similar threads

  • Programming and Computer Science
Replies
4
Views
621
  • Advanced Physics Homework Help
Replies
8
Views
808
  • STEM Educators and Teaching
Replies
4
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
0
Views
298
  • Differential Equations
Replies
4
Views
642
  • Special and General Relativity
Replies
4
Views
601
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
Replies
22
Views
462
Back
Top