I have an algorithm that works for a Tri-Diagonal matrix in Mathematica, but I need a good way to build my starter matrix A. It's a 20 variable system (and will be a 200 variable system once I get it), so I need a loop to build my pieces. My outline looks like this right for the first 3 lines of my matrix;
h is a constant x1, x2, ... x3 are knowns, (x_n+1 = x_n + 1/h, I think I can write a loop for this...) I have a system Au = f, and need a way to build matrix A (a matrix of the coefficients below) in Mathematica.
-(2/h^2 +1)u1 + (1/h^2 + x1/(2h))u2 = f1
(1/h^2 + x1/(2h))u1 - (2/h^2 +1)u2 + (1/h^2 + x1/(2h))u3 = f2
(1/h^2 + x1/(2h))u2 - (2/h^2 +1)u3 + (1/h^2 + x1/(2h))u4 = f3
(1/h^2 + x1/(2h))u3 - (2/h^2 +1)u4 + (1/h^2 + x1/(2h))u5 = f4
.
.
.
(1/h^2 + x1/(2h))u17 - (2/h^2 +1)u18 + (1/h^2 + x1/(2h))u19 = f18
(1/h^2 + x1/(2h))u18 - (2/h^2 +1)u19 = f19
where u = {u1, u2, ..., u19} is the vector I am solving for.
Some advice for some sort of loop to build this main matrix would be very helpful. I have had difficulty thus far using this forum and it may not be what I think it is.
SparseArray
andBand
. $\endgroup$