Main Overview

Class Matrix

class Matrix
see also: Menu: Insert -- Matrix
Matrix(v): v list of lists with uniform length.
Example:
Matrix([[11,12,13],[21,22,23]])
The class Matrix ist derived from Vector:
A Matrix object ist a Vector of Vector objects with uniform length.
The elements can be addressed using double indices (e.g.: A[i,k]). Indices are counted from 0 (as in Python lists etc.).
see also. class methods with Matrix.

Base Class: Vector

Overview:

Constructor

Matrix (v)

Class methods (static methods)

MethodMeaning
fromFunction (m, n, fn, offset=0)m*n-Matrix defined by function fn
fromString (s)Matrix given by a string
identity (n)n*n Identity Matrix
null (m, n=0)m*n-Null matrix
random (m,n=0, r=100)m*n matrix with random elements in 0..r-1

Operators

OperatorMeaning
x + yMatrix addition operator
x[i] Counts from 0 A[i] à i-th row vector A[i,k] à element in i-th row, k-th column
~x
x * yScalar or matrix multiplication
-x
str(x)
x[i] = y Counts from 0 A[i] à i-th row vector A[i,k] à element in i-th row, k-th column
x - yMatrix subtraction operator

Object Methods

MethodMeaning
adjoint ()Adjoint matrix
cofactor (i, k)Cofactor for row i, columns k
colRange ()List of all column indices
complement (i, k)Matrix without row i and column k
copy ()independent copy of the matrix ("clone") A
det ()Determinant of the matrix A
float ()returns the Matrix A with all elements converted to float
gaussElim (jordan=True)Row echelon form of the matrix A
gramSchmidt (normalize=False)Orthogonalizing using the Gram–Schmidt process
height ()Number of rows of the Matrix A
inverse ()Inverse og the matrix A
isSquare ()Truth value (A is square matrix)
joinBottom (B)Vertical concatenation of A with B
joinRight (B)Horizontal concatenation of A with B
leastSquares (b)Solution of the normal system
lup ()LUP decomposition of the matrix
minor (i, k)Minor for row i, column k
operators ()For documentation only
rank ()Rank of the matrix A
rowRange ()List of all row indices
solve (b)Solution of the linear equation system Ax = b
str (i,k)string representation of the element [i,k]
submatrix (i, k, m, n)m*n Submatrix (rows i..i+m-1, columns k..k+n-1)
transp ()returns the transposed Matrix
width ()Number of columns of the Matrix A

Constructor

Matrix

Constructor

Usage: Matrix(v)


Class methods (static methods)

fromFunction

Matrix.fromFunction(m,n, fn, offset=0)

Usage: Matrix.fromFunction(m, n, fn, offset=0)

Description:
m*n-Matrix defined by function fn
fn must be a binary function.
The Matrix element A[i,k] is defined as fn(i+offset,k+offset).
Example:
Matrix.fromFunction(2,4, pow, 1)
returns the Matrix

 / 1 1 1  1 \ 
 |          |
 \ 2 4 8 16 /


fromString

Matrix.fromString(s)

Usage: Matrix.fromString(s)

Description:
Matrix given by a string
The string s must contains the elementa row by row.
The rows are divided by semicolon, the elemente within a row by comma.
Elemente may also be rational (notated with slash).
Example:
Matrix.fromString("1, 2, 3.14; 4/5, 5, 6") returns the matrix

 / 1    2  3.14 \ 
 |              |
 \ 4/5  5   6   /


identity

Matrix.identity(n)

Usage: Matrix.identity(n)

Description:
n*n Identity Matrix


null

Matrix.null(m, n=0)

Usage: Matrix.null(m, n=0)

Description:
m*n-Null matrix
Square Matrix, if n is omitted.


random

Matrix.random(m,n=0, r=100)

Usage: Matrix.random(m,n=0, r=100)

Description:
m*n matrix with random elements in 0..r-1


Operators

x + y

A.__add__(B)

Usage: x + y

Description:
Matrix addition operator
Instead of A = A + B you may write A += B.


x[i]

Definition of the Index operator []

Usage: x[i]

Description:
Counts from 0 A[i] à i-th row vector A[i,k] à element in i-th row, k-th column


~x

Operator ~ (transposition)

Usage: ~x

Description:


x * y

A.__sub__(B)

Usage: x * y

Description:
Scalar or matrix multiplication
Instead of A = A * B you may write A *= B.


-x

unary minus operator

Usage: -x

Description:


str(x)

Object representation as string

Usage: str(x)

Description:


x[i] = y

Definition of the Index operator [] for assignments

Usage: x[i] = y

Description:
Counts from 0 A[i] à i-th row vector A[i,k] à element in i-th row, k-th column


x - y

A.__sub__(B)

Usage: x - y

Description:
Matrix subtraction operator
Instead of A = A - B you may write A -= B.


Object Methods

adjoint

A.adjoint()

Usage: A.adjoint()

Description:
Adjoint matrix


cofactor

A.cofactor(i, k)

Usage: A.cofactor(i, k)

Description:
Cofactor for row i, columns k
(signed minor)


colRange

A.rowRange()

Usage: A.colRange()

Description:
List of all column indices


complement

A.complement(i, k)

Usage: A.complement(i, k)

Description:
Matrix without row i and column k
(Algebraic complement)


copy

A.copy()

Usage: A.copy()

Description:
independent copy of the matrix ("clone") A


det

A.det()

Usage: A.det()

Description:
Determinant of the matrix A


float

A.float()

Usage: A.float()

Description:
returns the Matrix A with all elements converted to float


gaussElim

A.gaussElim(jordan=True)

Usage: self.gaussElim(jordan=True)

Description:
Row echelon form of the matrix A
If jordan is True, the reduced row echelon form is returned (Gaussian elimination), otherwise the normal row echelon form.


gramSchmidt

A.gramSchmidt(normalize=False)

Usage: self.gramSchmidt(normalize=False)

Description:
Orthogonalizing using the Gram–Schmidt process
A must be the matrix of the (linearly independent) vectors to be orthogonalized (given as rows).
If normalize is True, the vectors are normalized.
return value: Matrix consisting of the orthogonalen vectors.
Example:

 A = Matrix([[1,1],[2,0]])
 A.gramSchmidt()
returns the matrix
 / 1   1 \ 
 |       |
 \ 1  -1 /


height

A.height()

Usage: A.height()

Description:
Number of rows of the Matrix A


inverse

A.inverse()

Usage: A.inverse()

Description:
Inverse og the matrix A


isSquare

A.isSquare()

Usage: A.isSquare()

Description:
Truth value (A is square matrix)


joinBottom

A.joinBottom(B)

Usage: A.joinBottom(B)

Description:
Vertical concatenation of A with B
Requires: Both Matrices must have the same column count.


joinRight

A.joinRight(B)

Usage: A.joinRight(B)

Description:
Horizontal concatenation of A with B
Requires: Both Matrices must have the same row count.


leastSquares

A.leastSquares(b)

Usage: A.leastSquares(b)

Description:
Solution of the normal system
Returns: (~A*A).solve(~A*b)


lup

A.lup()

Usage: self.lup()

Description:
LUP decomposition of the matrix
Returns a triplet (L, U, P) with P*A = L*R, where:
P is a Permutation matrix,
L is a Lower triangular matrix where all diagonal elements are one.
R is an upper triangular matrix.
: Matrix ist invertible.


minor

A.minor(i, k)

Usage: A.minor(i, k)

Description:
Minor for row i, column k
(Determinant of the algebraic complement)


operators

Matrix.operators()

Usage: self.operators()

Description:
For documentation only
The following operators are defined in the class Matrix:

Op.FunctionExamples
+Additiona + b; a += b
-Subtractiona - b; a -= b
*Matrizenmultiplikation if both operands are Matrices, otherwise: Scalar multiplicationa * b; a *= b
-Unary minus-a
~Transposed Matrix~A
|ConcatenationA | B; A |= B
[ ]Index operatorA[i,k]
A[i] (Row Vector)
This method is for documentation only. It has no effect.


rank

A.rank()

Usage: A.rank()

Description:
Rank of the matrix A


rowRange

A.rowRange()

Usage: A.rowRange()

Description:
List of all row indices


solve

A.solve(b)

Usage: A.solve(b)

Description:
Solution of the linear equation system Ax = b
b may be Vektor or column Matrix.


str

A.str(i,k)

Usage: A.str(i,k)

Description:
string representation of the element [i,k]


submatrix

A.submatrix(i, k, m, n)

Usage: A.submatrix(i, k, m, n)

Description:
m*n Submatrix (rows i..i+m-1, columns k..k+n-1)


transp

A.transp()

Usage: A.transp()

Description:
returns the transposed Matrix
short form: ~A


width

A.height()

Usage: A.width()

Description:
Number of columns of the Matrix A