-4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ You can get a diagonal matrix with IdentityMatrix[n]. For the rest, improve your question and formatting. $\endgroup$
    – yarchik
    Commented Aug 6, 2022 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
    Commented Aug 6, 2022 at 20:08

1 Answer 1

3
$\begingroup$
$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

enter image description here

$\endgroup$

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