← Back to Categories

🧮 Matrix Programming Examples

Learn matrix creation, indexing, updates, arithmetic, transpose, determinant and inverse operations in Mewar.

1. Create Matrix

matrix A = [[1,2],[3,4]]

say "Matrix A:"
say A

2. Display Matrix

matrix A = [[1,2],[3,4]]

say "Matrix A:"
say A
show A

3. Matrix Indexing

matrix A = [[10,20,30],[40,50,60],[70,80,90]]

say "Matrix A:"
show A
newline

# ----- Basic Index Test -----
say "A[1][1] = " + A[1][1]
say "A[2][3] = " + A[2][3]
say "A[3][2] = " + A[3][2]

4. Update Matrix Value

matrix A = [[1,2,3],[4,5,6],[7,8,9]]

show A
newline

say "Editing A[3][1]"
set A[3][1] to 999

show A
newline

say "Value check:"
say A[3][1]

5. Matrix Addition

matrix A = [[1,2],[3,4]]
matrix B = [[5,6],[7,8]]

say "Matrix A:"
show A
newline

say "Matrix B:"
show B
newline


# ----- ADDITION -----
say "A + B:"
set Add to A + B
show Add
newline

6. Matrix Subtraction

# ----- CREATE MATRICES -----
matrix A = [[1,2],[3,4]]
matrix B = [[5,6],[7,8]]

say "Matrix A:"
show A
newline

say "Matrix B:"
show B
newline

# ----- SUBTRACTION -----
say "B - A:"
set Sub to B - A
show Sub

7. Matrix Multiplication

# ----- CREATE MATRICES -----
matrix A = [[1,2],[3,4]]
matrix B = [[5,6],[7,8]]

say "Matrix A:"
show A
newline

say "Matrix B:"
show B
newline

# ----- MULTIPLICATION -----
say "A * B:"
set Mul to A * B
show Mul

8. MATRIX FUNCTIONS

# ----- CREATE MATRICES -----
matrix A = [[1,2],[3,4]]
matrix B = [[5,6],[7,8]]

say "Matrix A:"
show A
newline

say "Matrix B:"
show B
newline

# ----- MATRIX FUNCTIONS -----
say "Rows of A = " + rows(A)
say "Columns of A = " + cols(A)

9. Matrix Transpose

matrix A = [[1,2,3],[4,5,6]]

say "Original Matrix:"
show A
newline

set T to transpose(A)

say "Transpose Matrix:"
show T

10. Matrix Determinant

matrix A = [[1,2],[3,4]]

say "Matrix A:"
show A

newline
say "det(A) = " + det(A)

11. Matrix Inverse

matrix A = [[4,7],[2,6]]

show A
newline

set Inv to inverse(A)

show Inv