# Math Help - Mathematica, how to construct a tridiagonal matrix?

1. ## Mathematica, how to construct a tridiagonal matrix?

Hello I want to view the entries of a block tridiagonal matrix. The matrix is defined by

$u_{i,j-1}+u_{i-1,j}+4 u_{i,j}+u_{i+1,j}+u_{i,j+1}=h^2f_{i,j}$

$1\leq i \leq 3$ and $1\leq i \leq 4$

I want to examine the structure of this matrix. Obviously writing this out by hand is a laborious task so I was wondering if mathematica can help me.

I tried

Table[Subscript[u, i, j - 1] + Subscript[u, i - 1, j] +
4 Subscript[u, i, j] + Subscript[u, i + 1, j] + Subscript[u, i,
j + 1] - h^2 Subscript[f, i, j], {i, 3}, {j, 4}]

But this doesn't quite output what I want. Can somebody tell me how I can construct this matrix more explicitly in Mathematica?

2. That looks like a discretization of Poisson's equation. Am I right? If so, shouldn't the $4u_{i,j}$ be negative?

I can't say I know how to visualize the matrix in Mathematica, but here's a visualization of it.

3. Thanks, thats correct, it is the discretisation of the Poisson PDE, I was really hoping mathematica could help me in trying to visualise these systems of equations and matrices. Doing it by hand is such a laborious task.

4. Try this:

Code:
Table[Subscript[u, i, j - 1] + Subscript[u, i - 1, j] -
4 Subscript[u, i, j] + Subscript[u, i + 1, j] + Subscript[u, i,
j + 1] - h^2 Subscript[f, i, j], {i, 3}, {j, 4}]//MatrixForm