Help with coding a matrix
You can also use a combination of ToeplitzMatrix
, DiagonalMatrix
, LowerTriangularize
and SparseArray
:
ClearAll[mat]
mat[n_] := Module[{dd = Array[d, n]},
LowerTriangularize[ToeplitzMatrix[dd, SparseArray]] +
DiagonalMatrix[SparseArray@Range[n - 1], 1]]
mat[5] // MatrixForm // TeXForm
$\left( \begin{array}{ccccc} d(1) & 1 & 0 & 0 & 0 \\ d(2) & d(1) & 2 & 0 & 0 \\ d(3) & d(2) & d(1) & 3 & 0 \\ d(4) & d(3) & d(2) & d(1) & 4 \\ d(5) & d(4) & d(3) & d(2) & d(1) \\ \end{array} \right)$
You can define the matrix with
M[1] = {{d[1]}};
M[i_Integer /; i >= 2] := SparseArray[{Band[{1, 2}] -> Range[i - 1],
{a_, b_} /; a >= b -> d[a - b + 1]},
{i, i}]
With the $d$-elements
λ = RandomReal[{0, 1}, 10];
d[j_] = Total[λ^j];
(replace the $\lambda$-vector by your eigenvalues).
M[5] // MatrixForm