Symbolic generating of system equations for 2D regular grid for solving Laplace equation using finite difference method
By Nasser M. Abbasi
updated oct 28,2010

Introduction

When solving ) using finite difference method, in order to make it easy to see the internal structure of the A matrix using the standard 5 points Laplacian scheme, the following is a small function which generates the symbolic format of these equations for  a given N, the number of grid points on one edge.  At the end of this note, the system equations are generated for N=4,5,6,7,8. One can see the form of the A matrix with the dominant diagonal and the corresponding bands. It is mostly a sparse matrix.

The indexing method used is that described in the class.

Define U at each grid point

In:= Out= Define the force vector

In:= Out= In:= In:= Draw the grid with the unknown above at each point

In:= Out= Generate the discrete equations at each of the internal grid points

In:= Out= List the unknowns

In:= Out= Generate the equations of the form AU=F

In:= Out=   = For homegenous Boundary conditions

In:= Out=   = set the boundary conditions. Assume left side is U=α,Right side U=β, bottom side U=γ, top side U=η, then the above becomes

In:= Display the equations again

In:= Out=   = Now the system can be solved for the unknowns U , given the force F values.

Below is the system equations generated for N=3,4,5,6,7,8. Put the above code into one function to use it all the time

In:= In:=          For homogenous boundary conditions

In:=          