# Constructing NxN tridiagonal block diagonal matrix with N is a variable [closed]

Hi please can someone help me writing a program of generating a tridiagonal block matrix with dimension of NxN where N is a variable can be 50, 100, 200, 300...etc , Well I don't know how I'm a beginner. THANK YOU ANYWAY!

My matrix is in the photos

• You can get a diagonal matrix with IdentityMatrix[n]. For the rest, improve your question and formatting. Commented Aug 6, 2022 at 17:51
• If you search the built-in help center for "tridiagonal", the first hit shows how and points you to SparseArray, whose documentation page also shows how to construct a tridiagonal matrix. Commented Aug 6, 2022 at 20:08

\$Version

"13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)"

Clear["Global*"]

n = 5;

(mat =
ReplacePart[
DiagonalMatrix[ConstantArray[A + W - EI, n]] +
DiagonalMatrix[ConstantArray[-W', n - 1], 1] +
DiagonalMatrix[ConstantArray[-W', n - 1], -1],
{{1, 1} -> A - EI, {n, n} -> A - EI}]) // MatrixForm
`