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 "2D_1.gif") 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[59]:=

"2D_2.gif"

Out[61]=

"2D_3.gif"

Define the force vector

In[62]:=

"2D_4.gif"

Out[63]=

"2D_5.gif"

In[64]:=

"2D_6.gif"

In[67]:=

"2D_7.gif"

Draw the grid with the unknown above at each point

In[68]:=

"2D_8.gif"

Out[70]=

"2D_9.gif"

Generate the discrete equations at each of the internal grid points

In[71]:=

"2D_10.gif"

Out[72]=

"2D_11.gif"

List the unknowns

In[73]:=

"2D_12.gif"

Out[73]=

"2D_13.gif"

Generate the equations of the form AU=F

In[80]:=

"2D_14.gif"

Out[82]=

"2D_15.gif" "2D_16.gif" "2D_17.gif" = "2D_18.gif"

For homegenous Boundary conditions

In[83]:=

"2D_19.gif"

Out[85]=

"2D_20.gif" "2D_21.gif" "2D_22.gif" = "2D_23.gif"

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

In[86]:=

"2D_24.gif"

Display the equations again

In[90]:=

"2D_25.gif"

Out[90]=

"2D_26.gif" "2D_27.gif" "2D_28.gif" = "2D_29.gif"

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[91]:=

"2D_30.gif"

In[92]:=

"2D_31.gif"

"2D_32.gif"

"2D_33.gif"

"2D_34.gif"

"2D_35.gif"

"2D_36.gif"

"2D_37.gif"

"2D_38.gif"

"2D_39.gif"

"2D_40.gif"

For homogenous boundary conditions

In[94]:=

"2D_41.gif"

"2D_42.gif"

"2D_43.gif"

"2D_44.gif"

"2D_45.gif"

"2D_46.gif"

"2D_47.gif"

"2D_48.gif"

"2D_49.gif"

"2D_50.gif"

Spikey Created with Wolfram Mathematica 7.0