Solving Poissons Elliptic Equation using Finite Difference Method

by admin in , , , on May 1, 2019

This solves Poissons Elliptic Equation using Finite Difference Method and Sparse for the matrices. The code uses four steps to give the solution: discretization, approximation, putting the equation in a matrix form, and solving the matrix form.

Code Outputs:

  • Solution Chart compared with the exact solution if exist.
  • Error chart.
  • Printed maximum error value.

Max. Error Value = 0.0025

Input Requirements:

  • Poissons equation (right-hand side).
  • Exact solution if exist.
  • Mesh length and number of its points.

About The Method:

Finite-Difference Methods (FDM) are numerical methods for solving differential equations by approximating them with difference equations, in which finite differences approximate the derivatives. FDMs are thus discretization methods. FDMs convert a linear (non-linear) ODE (Ordinary Differential Equations) /PDE (Partial differential equations) into a system of linear (non-linear) equations, which can then be solved by matrix algebra techniques. The reduction of the differential equation to a system of algebraic equations makes the problem of finding the solution to a given ODE ideally suited to modern computers, hence the widespread use of FDMs in modern numerical analysis. Today, FDMs are the dominant approach to numerical solutions of partial differential equations.

Derivation From Taylor’s Polynomial:

First, assuming the function whose derivatives are to be approximated is properly-behaved, by Taylor’s theorem, we can create a Taylor series expansion

where n! denotes the factorial of n, and Rn(x) is a remainder term, denoting the difference between the Taylor polynomial of degree n and the original function. We will derive an approximation for the first derivative of the function ‘f’ by first truncating the Taylor polynomial:

Setting, x0=a we have,

Dividing across by h gives:

Solving for f'(a):

Assuming that R1(x) is sufficiently small, the approximation of the first derivative of ‘f‘ is:

Accuracy and Order:

The error in a method’s solution is defined as the difference between the approximation and the exact analytical

solution. The two sources of error in finite difference methods are round-off error, the loss of precision due to computer rounding of decimal quantities, and truncation error or discretization error, the difference between the exact solution of the original differential equation and the exact quantity assuming perfect arithmetic (that is, assuming no round-off).

The finite difference method relies on discretizing a function on a grid.

To use a finite difference method to approximate the solution to a problem, one must first discretize the problem’s domain. This is usually done by dividing the domain into a uniform grid (see image to the right). Note that this means that finite-difference methods produce sets of discrete numerical approximations to the derivative, often in a ‘time-stepping’ manner.

An expression of general interest is the local truncation error of a method. Typically expressed using Big-O notation, local truncation error refers to the error from a single application of a method. That is, it is the quantity f'(xi) – f’i if f'(xi) refers to the exact value and f’i to the numerical approximation. The remainder term of a Taylor polynomial is convenient for analyzing the local truncation error. Using the Lagrange form of the remainder from the Taylor polynomial for f(x0+h), which is

where x0 < xi < x0 +h the dominant term of the local truncation error can be discovered. For example, again using the forward-difference formula for the first derivative, knowing that

and with some algebraic manipulation, this leads to

and further noting that the quantity on the left is the approximation from the finite difference method and that the quantity on the right is the exact quantity of interest plus a remainder, clearly that remainder is the local truncation error. A final expression of this example and its order is:

This means that, in this case, the local truncation error is proportional to the step sizes. The quality and duration of simulated FDM solution depends on the discretization equation selection and the step sizes (time and space steps). The data quality and simulation duration increase significantly with smaller step size. Therefore, a reasonable balance between data quality and simulation duration is necessary for practical usage. Large time steps are useful for increasing simulation speed in practice. However, time steps which are too large may create instabilities and affect the data quality.

The von Neumann and Courant-Friedrichs-Lewy criteria are often evaluated to determine the numerical model stability.

Example: Ordinary Differential Equation:

For example, consider the ordinary differential equation

The Euler method for solving this equation uses the finite difference quotient

to approximate the differential equation by first substituting it for u'(x) then applying a little algebra (multiplying both sides by h, and then adding u(x) to both sides) to get

The last equation is a finite-difference equation, and solving this equation gives an approximate solution to the differential equation.


[1] K.W. Morton and D.F. Mayers, Numerical Solution of Partial Differential Equations, An Introduction. Cambridge University Press, 2005.

[2] Autar Kaw and E. Eric Kalu, Numerical Methods with Applications, (2008) [1]. Contains a brief, engineering-oriented introduction to FDM (for ODEs) in Chapter 08.07.

[3] John Strikwerda (2004). Finite Difference Schemes and Partial Differential Equations (2nd ed.). SIAM. ISBN 978-0-89871-639-9.

[4] Smith, G. D. (1985), Numerical Solution of Partial Differential Equations: Finite Difference Methods, 3rd ed., Oxford University Press

[5] Peter Olver (2013). Introduction to Partial Differential Equations. Springer. Chapter 5: Finite differences. ISBN 978-3-319-02099-0..

[6] Randall J. LeVeque, Finite Difference Methods for Ordinary and Partial Differential Equations, SIAM, 2007.

1 Sale

Share Now!

Release Information

  • Price


  • Released

    May 1, 2019

  • Last Updated

    May 28, 2019

Share Your Valuable Opinions