Construction of Matrices
1. Identity Matrix: Construct an identity matrix of size 4.
IdentityMatrixConstruction[n_] := IdentityMatrix[n]
IdentityMatrixConstruction[4]
Output:
{{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1}}
2. Diagonal Matrix
Construct a diagonal matrix with diagonal elements {1, 2, 3, 4}.
DiagonalMatrixConstruction[diagonalElements_List] := DiagonalMatrix[diagonalElements]
DiagonalMatrixConstruction[{1, 2, 3, 4}]
Output:
{{1, 0, 0, 0},
{0, 2, 0, 0},
{0, 0, 3, 0},
{0, 0, 0, 4}}
3. Random Matrix
Generate a 3×4 matrix of random integers between 0 and 10.
RandomMatrixConstruction[n_, m_] := RandomInteger[{0, 10}, {n, m}]
RandomMatrixConstruction[3, 4]
Example Output:
{{3, 8, 1, 7},
{9, 0, 5, 4},
{6, 2, 10, 8}}
4. Zero Matrix
Create a zero matrix of size 3×3.
ZeroMatrixConstruction[n_, m_] := ConstantArray[0, {n, m}]
ZeroMatrixConstruction[3, 3]
Output:
{{0, 0, 0},
{0, 0, 0},
{0, 0, 0}}
5. Upper Triangular Matrix
Generate an upper triangular matrix from the given matrix.
UpperTriangularMatrixConstruction[mat_List] := UpperTriangularize[mat]
UpperTriangularMatrixConstruction[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]
Output:
{{1, 2, 3},
{0, 5, 6},
{0, 0, 9}}
6. Lower Triangular Matrix
Generate a lower triangular matrix from the given matrix.
LowerTriangularMatrixConstruction[mat_List] := LowerTriangularize[mat]
LowerTriangularMatrixConstruction[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]
Output:
{{1, 0, 0},
{4, 5, 0},
{7, 8, 9}}
7. Symmetric Matrix
Generate a symmetric matrix from the given matrix by averaging it with its transpose.
SymmetricMatrixConstruction[mat_List] := (mat + Transpose[mat])/2
SymmetricMatrixConstruction[{{1, 2}, {3, 4}}]
Output:
{{1, 2.5},
{2.5, 4}}
8. Block Matrix
Create a block matrix from submatrices.
BlockMatrixConstruction[A_, B_, C_, D_] := ArrayFlatten[{{A, B}, {C, D}}]
BlockMatrixConstruction[{{1, 2}, {3, 4}}, {{5, 6}}, {{7, 8}}, {{9}}]
Output:
{{1, 2, 5, 6},
{3, 4, 5, 6},
{7, 8, 9, 9}}
9. Toeplitz Matrix
Generate a Toeplitz matrix from the first row and first column.
ToeplitzMatrixConstruction[firstRow_List, firstCol_List] := ToeplitzMatrix[firstRow, firstCol]
ToeplitzMatrixConstruction[{1, 2, 3}, {1, 4, 5}]
Output:
{{1, 2, 3},
{4, 1, 2},
{5, 4, 1}}
10. Hilbert Matrix
Generate a 3×3 Hilbert matrix.
HilbertMatrixConstruction[n_] := Table[1/(i + j – 1), {i, n}, {j, n}]
HilbertMatrixConstruction[3]
Output:
{{1, 1/2, 1/3},
{1/2, 1/3, 1/4},
{1/3, 1/4, 1/5}}
Add a Comment