kevinthenerd
Platinum Member
In undergraduate mechanical engineering heat transfer, one learns about the finite difference method to solve conduction problems for complex geometries with known boundary conditions. These equations build a very sparse linear system. In one dimension, this matrix is tridiagonal. In two dimensions, this matrix is pentadiagonal. In three dimensions, this matrix is heptadiagonal.
I'm trying to write some code to solve a take-home quiz. It's expected that we should use the finite difference method, but I want to be a smartass and use hundreds or thousands of nodes. (If I'm unsuccessful with this method, my backup plan is pretty much completed.) To do this, I can't settle for an n^3 direct solution method, and I can't settle for an n^2 storage method (where n is the number of nodes). I want to store the matrix in a reduced form and use something like the Thomas Algorithm to solve it, but my numerical methods book only covers the Thomas Algorithm for tridiagonal matrices.
I'm running into two problems, though, regarding building the matrix and solving it. I'm trying to solve a two-dimensional problem, and my left hand side matrix takes the form of a three dimensional array. In addition to the X and Y coordinates of the node, I'm using a third dimension (size 5) to store each of the coefficients of the node and its surrounding nodes in addition to an array b to store the right hand side vector.
If I have a node in the middle of a homogenous substance, the 2-dimensional finite difference equations resemble...
1*top + 1*bottom + 1*left + 1*right - 4*middle = 0
This is equivalent to... (assuming Ax=b and assuming the origin on the bottom left of the problem)
1*x[i,j+1] + 1*x[i,j-1] + 1*x[i-1,j] + 1*x[i+1,j] - 4*x[i,j] = 0
This takes the form...
A[i,j,0]=-4 (middle)
A[i,j,1]=1 (right)
A[i,j,2]=1 (top)
A[i,j,3]=1 (left)
A[i,j,4]=1 (bottom)
b[i,j]=0 (right hand side)
How would I go about building and solving such a setup?
I would really appreciate it.
I'm trying to write some code to solve a take-home quiz. It's expected that we should use the finite difference method, but I want to be a smartass and use hundreds or thousands of nodes. (If I'm unsuccessful with this method, my backup plan is pretty much completed.) To do this, I can't settle for an n^3 direct solution method, and I can't settle for an n^2 storage method (where n is the number of nodes). I want to store the matrix in a reduced form and use something like the Thomas Algorithm to solve it, but my numerical methods book only covers the Thomas Algorithm for tridiagonal matrices.
I'm running into two problems, though, regarding building the matrix and solving it. I'm trying to solve a two-dimensional problem, and my left hand side matrix takes the form of a three dimensional array. In addition to the X and Y coordinates of the node, I'm using a third dimension (size 5) to store each of the coefficients of the node and its surrounding nodes in addition to an array b to store the right hand side vector.
If I have a node in the middle of a homogenous substance, the 2-dimensional finite difference equations resemble...
1*top + 1*bottom + 1*left + 1*right - 4*middle = 0
This is equivalent to... (assuming Ax=b and assuming the origin on the bottom left of the problem)
1*x[i,j+1] + 1*x[i,j-1] + 1*x[i-1,j] + 1*x[i+1,j] - 4*x[i,j] = 0
This takes the form...
A[i,j,0]=-4 (middle)
A[i,j,1]=1 (right)
A[i,j,2]=1 (top)
A[i,j,3]=1 (left)
A[i,j,4]=1 (bottom)
b[i,j]=0 (right hand side)
How would I go about building and solving such a setup?
I would really appreciate it.