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 enter image description here

enter image description here

New contributor
Med Ch is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • $\begingroup$ You can get a diagonal matrix with IdentityMatrix[n]. For the rest, improve your question and formatting. $\endgroup$
    – yarchik
    Aug 6 at 17:51
  • 1
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Aug 6 at 20:08

1 Answer 1


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


n = 5;

(mat =
    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

enter image description here


Not the answer you're looking for? Browse other questions tagged or ask your own question.