Linear Algebra

Matrices

Operations over matrices

simula.linalg.matrices.In(n)

Returns an identity matrix of order n.

Parameters

n – an integer

simula : identity_matrix(2)
Matrix([
[1, 0],
[0, 1]])
simula : identity_matrix(3)
Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
class simula.linalg.matrices.Matrix(*args, **kwargs)

Bases: sympy.matrices.dense.MutableDenseMatrix, simula.structure.simula_object.SimulaObject

Base class for Matrices.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.det()
-4
simula : A.rank()
3
simula : A.trace()
3
simula : A.transpose()
Matrix([
[-2, -5, -1],
[ 1,  2,  1],
[ 4,  5,  3]])
simula : A^3
Matrix([
[-19, 12, 27],
[-15,  8, 15],
[-18, 12, 26]])
simula : A.charpoly('x')
PurePoly(x^3 - 3x^2 + 4, x, domain='ZZ')
simula : A.eigenvals()
{-1: 1, 2: 2}
simula : A.cofactor_matrix()
Matrix([
[ 1,  10, -3],
[ 1,  -2,  1],
[-3, -10,  1]])
simula : B = matrix([[1, 2], [3, 4]]); B
Matrix([
[1, 2],
[3, 4]])
simula : C = matrix([[5, 6, 7], [8, 9, 10]]); C
Matrix([
[5, 6,  7],
[8, 9, 10]])
simula : matrix([B, C])
Matrix([
[1, 2, 5, 6,  7],
[3, 4, 8, 9, 10]])
simula : matrix([[B, C], [B, C]])
[1, 2, 5, 6,  7],
[3, 4, 8, 9, 10],
[1, 2, 5, 6,  7],
[3, 4, 8, 9, 10]])
algebraic_multiplicity(lamda)

Returns the algebraic multiplicity of lamda.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.eigenvalues()
{-1: 1, 2: 2}
simula : A.algebraic_multiplicity(2)
2
static circulant(v, shift=None)

Returns a circulant matrix.

See also circulant_matrix

dunford_decomposition()

Returns the Dunford decomposition of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : B, N = A.dunford_decomposition(); B, N
(Matrix([
[-1/3, 0, 7/3],
[  -5, 2,   5],
[ 2/3, 0, 4/3]]), Matrix([
[-5/3, 1, 5/3],
[   0, 0,   0],
[-5/3, 1, 5/3]]))
simula : B*N == N*B
True
simula : B.is_diagonalizable()
True
simula : N.is_nilpotent()
True
simula : B+N
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
eigenvalues(*args, **kwargs)

Returns the eigenvalues of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.eigenvalues()
{-1: 1, 2: 2}
eigenvectors_left(**kwargs)

Returns the left eigenvectors of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.eigenvectors_left()
[(-1, 1, [Matrix([[-1, 0, 1]])]), (2, 2, [Matrix([[-1, 3/5, 1]])])]
eigenvectors_right(**kwargs)

Returns the right eigenvectors of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.eigenvectors_right()
[(-1, 1, [Matrix([
[ -7/2],
[-15/2],
[    1]])]), (2, 2, [Matrix([
[1],
[0],
[1]])])]
geometric_multiplicity(lamda)

Returns the geometric multiplicity of lamda.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.eigenvalues()
{-1: 1, 2: 2}
simula : A.geometric_multiplicity(2)
1
linear_map(domain=None, codomain=None)

Returns the linear map associated to self.

Parameters

domain – (optional) a field or vector space

:param codomain : (optional) a field or vector space

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : f = A.linear_map(RR, RR)
simula : f
Linear map from RR^3 --> RR^3 defined by (x1, x2, x3) |--> (-2x1 + x2 + 4x3, -5x1 + 2x2 + 5x3, -x1 + x2 + 3x3)
simula : f(1, 0, 0)
(-2, -5, -1)
reverse_cols()

Returns a matrix when its columns are the reversed columns of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.reverse_cols()
Matrix([
[-1, 1, 3],
[-5, 2, 5],
[-2, 1, 4]])
reverse_rows()

Returns a matrix when its rows are the reversed rows of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.reverse_rows()
Matrix([
[4, 1, -2],
[5, 2, -5],
[3, 1, -1]])
rref_mod(gf)

Returns the row reduced echelon form in finite field GF(q).

Parameters

gf – a finite field GF(q)

EXAMPLES:

simula : A = matrix([[2, 1, 0, 0, 1, 1, -1], [1, 1, 0, 1, 0, -1, 0], [2, -1, 1, 1, 0, 1, -1]]); A
Matrix([
[2,  1, 0, 0, 1,  1, -1],
[1,  1, 0, 1, 0, -1,  0],
[2, -1, 1, 1, 0,  1, -1]])
simula : A.rref_mod(GF(3))
Matrix([
[1, 0, 0, 2, 1, 2, 2],
[0, 1, 0, 2, 2, 0, 1],
[0, 0, 1, 2, 0, 0, 2]])
simula : A.rref_mod(GF(5))
Matrix([
[1, 0, 0, 4, 1, 2, 4],
[0, 1, 0, 2, 4, 2, 1],
[0, 0, 1, 0, 2, 4, 2]])
spectral_radius()

Returns the spectral radius of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.spectral_radius()
2
spectrum()

Returns the spectrum of self.

EXAMPLES:

simula : A = matrix([[-2, 1, 4], [-5, 2, 5], [-1, 1, 3]]); A
Matrix([
[-2, 1, 4],
[-5, 2, 5],
[-1, 1, 3]])
simula : A.spectrum()
{2, -1}
simula.linalg.matrices.block_matrix

alias of simula.linalg.matrices.BlockMatrix

simula.linalg.matrices.circulant_matrix(v, shift=None)

Returns a circulant matrix.

Parameters
  • v – a vector

  • shift – (optional) the number of rows. If it is not None, it should be less or equal than the length of v

EXAMPLES:

simula : v = [1,2,3,4,5]
simula : circulant_matrix(v)
Matrix([
[1, 2, 3, 4, 5],
[5, 1, 2, 3, 4],
[4, 5, 1, 2, 3],
[3, 4, 5, 1, 2],
[2, 3, 4, 5, 1]])
simula : circulant_matrix(v, shift=3)
Matrix([
[1, 2, 3, 4, 5],
[5, 1, 2, 3, 4],
[4, 5, 1, 2, 3]])
simula.linalg.matrices.companion_matrix(poly, format='right')

Returns a companion matrix associated to a polynomial for a given format.

Parameters
  • poly – a polynomial

  • format – a string (“right”, “left”, “top”, “bottom”), default is “right”

EXAMPLES:

simula : p = x^5-x^4-3x^3-x^2+5x-6
simula : companion_matrix(p)
Matrix([
[0, 0, 0, 0,  6],
[1, 0, 0, 0, -5],
[0, 1, 0, 0,  1],
[0, 0, 1, 0,  3],
[0, 0, 0, 1,  1]])
simula : companion_matrix(p, format='left')
Matrix([
[ 1, 1, 0, 0, 0],
[ 3, 0, 1, 0, 0],
[ 1, 0, 0, 1, 0],
[-5, 0, 0, 0, 1],
[ 6, 0, 0, 0, 0]])
simula : companion_matrix(p, format='top')
Matrix([
[1, 3, 1, -5, 6],
[1, 0, 0,  0, 0],
[0, 1, 0,  0, 0],
[0, 0, 1,  0, 0],
[0, 0, 0,  1, 0]])
simula : companion_matrix(p, format='bottom')
Matrix([
[0,  1, 0, 0, 0],
[0,  0, 1, 0, 0],
[0,  0, 0, 1, 0],
[0,  0, 0, 0, 1],
[6, -5, 1, 3, 1]])
simula.linalg.matrices.diag(*args)

Returns a diagonal matrix.

EXAMPLES:

simula : diagonal_matrix(1, 2, 3)
Matrix([
[1, 0, 0],
[0, 2, 0],
[0, 0, 3]])
simula : diagonal_matrix(-2, 2, 1, 1)
Matrix([
[-2, 0, 0, 0],
[ 0, 2, 0, 0],
[ 0, 0, 1, 0],
[ 0, 0, 0, 1]])
simula.linalg.matrices.diagonal_matrix(*args)

Returns a diagonal matrix.

EXAMPLES:

simula : diagonal_matrix(1, 2, 3)
Matrix([
[1, 0, 0],
[0, 2, 0],
[0, 0, 3]])
simula : diagonal_matrix(-2, 2, 1, 1)
Matrix([
[-2, 0, 0, 0],
[ 0, 2, 0, 0],
[ 0, 0, 1, 0],
[ 0, 0, 0, 1]])
simula.linalg.matrices.hilbert_matrix(n)

Return a Hilbert matrix of the given dimension.

H_ij = 1/(i + j - 1) for i, j = 1, …, n

Parameters

n – an integer

EXAMPLES:

simula : hilbert_matrix(2)
Matrix([
[  1, 1/2],
[1/2, 1/3]])
simula : hilbert_matrix(3)
Matrix([
[  1, 1/2, 1/3],
[1/2, 1/3, 1/4],
[1/3, 1/4, 1/5]])
simula : hilbert_matrix(4)
Matrix([
[  1, 1/2, 1/3, 1/4],
[1/2, 1/3, 1/4, 1/5],
[1/3, 1/4, 1/5, 1/6],
[1/4, 1/5, 1/6, 1/7]])
simula.linalg.matrices.identity_matrix(n)

Returns an identity matrix of order n.

Parameters

n – an integer

simula : identity_matrix(2)
Matrix([
[1, 0],
[0, 1]])
simula : identity_matrix(3)
Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
simula.linalg.matrices.jordan_cell(lamda, dim)

Returns a jordan block of dimension dim associated to the eigenvalue lamda.

Param

an eigenvalue

Parameters

dim – (an integer) the number of rows and columns

EXAMPLES:

simula : jordan_cell(2, 3)
Matrix([
[2, 1, 0],
[0, 2, 1],
[0, 0, 2]])
simula : jordan_cell(-3, 4)
Matrix([
[-3,  1,  0,  0],
[ 0, -3,  1,  0],
[ 0,  0, -3,  1],
[ 0,  0,  0, -3]])
simula.linalg.matrices.linear_system_to_matrix(expr, symbols=None)

Returns the two matrices associated to a linear system.

Parameters
  • expr – an expression

  • symbols – list of symbols

Return type

(<class ‘simula.linalg.matrices.Matrix’>, <class ‘simula.linalg.matrices.Matrix’>)

EXAMPLES

simula : x, y , z = var('x,y,z')
simula : A, b = linear_system_to_matrix([x+y-z-1, 2x-3y-z-7, 2x+z-5], (x,y,z))
simula : A
Matrix([
[1,  1, -1],
[2, -3, -1],
[2,  0,  1]])
simula : b
Matrix([
[1],
[7],
[5]])
simula.linalg.matrices.matrix

alias of simula.linalg.matrices.Matrix

simula.linalg.matrices.ones(rows, cols=None)

Returns a matrix when all its coefficients are equal to one.

Parameters
  • rows – (an integer) the number or rows

  • cols – (optional) the number or columns

EXAMPLES:

simula : ones_matrix(2, 4)
Matrix([
[1, 1, 1, 1],
[1, 1, 1, 1]])
simula : ones_matrix(3)
Matrix([
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
simula.linalg.matrices.ones_matrix(rows, cols=None)

Returns a matrix when all its coefficients are equal to one.

Parameters
  • rows – (an integer) the number or rows

  • cols – (optional) the number or columns

EXAMPLES:

simula : ones_matrix(2, 4)
Matrix([
[1, 1, 1, 1],
[1, 1, 1, 1]])
simula : ones_matrix(3)
Matrix([
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
simula.linalg.matrices.zero_matrix(rows, cols=None)

Returns a zero matrix with rows rows and cols cols. If cols is not given it is equal to the rows.

Parameters
  • rows – (an integer) the number or rows

  • cols – (optional) the number or columns

EXAMPLES:

simula : zero_matrix(2, 3)
Matrix([
[0, 0, 0],
[0, 0, 0]])
simula : zero_matrix(3)
Matrix([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
simula.linalg.matrices.zeros(rows, cols=None)

Returns a zero matrix with rows rows and cols cols. If cols is not given it is equal to the rows.

Parameters
  • rows – (an integer) the number or rows

  • cols – (optional) the number or columns

EXAMPLES:

simula : zero_matrix(2, 3)
Matrix([
[0, 0, 0],
[0, 0, 0]])
simula : zero_matrix(3)
Matrix([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])

Vector Spaces

Vectors Spaces

Classes

  • VectorSpace K^n

  • SubSpace

  • Vect

  • MatrixSpace

  • vector

class simula.linalg.vector_space.MatrixSpace(field, rows=None, cols=None)

Bases: simula.linalg.vector_space.VectorSpace, abc.ABC

Representation of Matrix spaces

Parameters
  • field – a field

  • rows – the number of rows

  • cols – the number of columns

EXAMPLES:

simula : M = MatrixSpace(QQ, 3, 2)
Matrix Space of dimension 3 x 2 over Rational Numbers
simula : M.canonical_basis()
[Matrix([
[1, 0],
[0, 0],
[0, 0]]), Matrix([
[0, 1],
[0, 0],
[0, 0]]), Matrix([
[0, 0],
[1, 0],
[0, 0]]), Matrix([
[0, 0],
[0, 1],
[0, 0]]), Matrix([
[0, 0],
[0, 0],
[1, 0]]), Matrix([
[0, 0],
[0, 0],
[0, 1]])]
simula : A = matrix([[1, 2.0], [0.5, 2.5], [0.3, 1]]) ; A
Matrix([
[  1, 2.0],
[0.5, 2.5],
[0.3,   1]])
simula : M(A)
Matrix([
[   1,   2],
[ 1/2, 5/2],
[3/10,   1]])
are_linearly_independent(family)

Tests if the vectors in``family`` are linearly independent in self.

Parameters

family (Union[Iterable, Sized]) –

canonical_basis()

Returns a canonical basis of self.

change_field(field)

Returns a matrix space of same dimension of self for the new field.

get_a_basis()

Returns a basis of self.

get_component_in_basis(v, family=None)

Returns the components of the vector v in family.

is_basis(family)

Tests if family is a basis of self.

Parameters

family (Union[Iterable, Sized]) –

linear_combination(family, coeffs)

Returns a linear combination of the vectors in family by the coefficients in self.

random_element(a=None, b=None)

Returns a random matrix in self.

class simula.linalg.vector_space.SubSpace(family=None, domain=None, name='')

Bases: simula.linalg.vector_space.VectorSpace, abc.ABC

Representation of a subspace

INPUT:

Parameters
  • family – a set of vectors

  • domain – a vector space (optional)

  • name – the name of self (optional)

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : F = SubSpace({(1, 2, 0), (1, 1, 2)}, V)
Subspace of QQ^3 generated by the family {(1, 2, 0), (1, 1, 2)}
simula : F == V
False
simula : W = SubSpace({(1, 2, 0), (1, 1, 2), (1, 0, 0)}, V)
Subspace of QQ^3 generated by the family {(1, 0, 0), (1, 2, 0), (1, 1, 2)}
simula : W == V
get_a_basis()

Returns a basis of self.

get_component_in_basis(v, family=None)

Returns the component of v (if it exists) for the family.

class simula.linalg.vector_space.Vect(family=None, domain=None, transpose=False)

Bases: simula.linalg.vector_space.SubSpace, abc.ABC

Representation of (an abstract) subspace.

simula : V = QQ^3; V
Vector Space of dimension 3 over Rational Numbers
simula : F = Vect({(1,0,0), (1, 1, 1)}, V); F
Vect({(1, 0, 0), (1, 1, 1)})
simula : W = Vect({(1, 0, 0), (1, 1, 1)}); W
Vect({(1, 0, 0), (1, 1, 1)})
simula : W.dimension()
2
class simula.linalg.vector_space.VectorSpace(field, dim=1)

Bases: sympy.polys.domains.domain.Domain, simula.structure.simula_object.SimulaObject, abc.ABC

are_linearly_dependent(family)

Tests if the vectors in family` are linearly dependent in ``self.

Parameters

family (Iterable) – a set of vectors

Returns

a boolean

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.are_linearly_dependent({(1, 1, 1), (2, 1, 0), (3, 2, 1)})
True
are_linearly_independent(family)

Tests if the vectors in family` are linearly independent in ``self.

Parameters

family (Union[Iterable, Sized]) – a set of vectors

Returns

a boolean

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.are_linearly_independent({(1, 1, 1), (2, 1, 0), (3, 2, 1)})
False
canonical_basis()

Returns the canonical basis of self.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.canonical_basis()
{(1, 0, 0), (0, 1, 0), (0, 0, 1)}
cardinality()

Returns the cardinality of self

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.cardinality()
oo
simula : V2 = VectorSpace(GF(5), 3); V2
Vector Space of dimension 3 over GF(5)
simula : V2.cardinality()
125
change_field(field)

Change the base field of self.

Parameters

field – a field (QQ, RR, CC or GF(q))

Returns

a vector space

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.change_field(RR)
Vector Space of dimension 3 over Real Numbers with 53 bits of precision
contains(family)

Tests if family` is included in ``self.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.include({(1, 1, 0), (2, 1, 0), (1/2, 0, 1)})
True
Parameters

family (Iterable) –

dim()

The dimension of self.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.dimension()
3
dimension()

The dimension of self.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.dimension()
3
get_a_basis()

Returns a basis of self.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.get_a_basis()
{(1, 0, 0), (0, 1, 0), (0, 0, 1)}
get_component_in_basis(v, family=None)

Returns the component of v (if it exists) for the family.

Parameters
  • v – a vector

  • family – a list vectors

Returns

a tuple of scalars

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.get_component_in_basis((1,2,3), [(1, 1, -2), (2, 0, 1), (0, 0, 1)])
(2, -1/2, 15/2)
include(family)

Tests if family` is included in ``self.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.include({(1, 1, 0), (2, 1, 0), (1/2, 0, 1)})
True
Parameters

family (Iterable) –

is_basis(family)

Tests if family` is a basis of ``self.

Parameters

family (Union[Iterable, Sized]) – a set of vectors

Returns

a boolean

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.is_basis({(1, 1, 1), (2, 1, 0), (3, 2, 1)})
False
is_finite()

Tests if self is finite.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.is_finite()
False
simula : V2 = VectorSpace(GF(5), 3); V2
Vector Space of dimension 3 over GF(5)
simula : V2.is_finite()
True
is_generators(family)

Tests if family` generate ``self.

Parameters

family – a set of vectors

Returns

a boolean

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.is_generators({(0, 0, 1), (1, 1, 1), (1, 0, -1)})
True
is_infinite()

Tests if self is infinite.

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.is_infinite()
True
simula : V2 = VectorSpace(GF(5), 3); V2
Vector Space of dimension 3 over GF(5)
simula : V2.is_infinite()
False
is_subspace(domain)

Tests if domain is a subspace of self.

Parameters

domain – a vector space

Returns

a boolean True or False

linear_combination(family, coeffs)

Returns a linear combination of family by the coefficients coeffs.

Parameters
  • family – a list of vectors

  • coeffs – a list of scalars

Returns

a vector

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.linear_combination([(1, 1, -2), (2, 0, 1)], [-2, 3])
(4, -2, 7)
matrix_change_basis(basis1, basis2)

Returns subspace of self generated by family.

Parameters
  • basis1 (Iterable) – a basis of self

  • basis2 (Iterable) – a basis of self

Returns

a matrix

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.matrix_change_basis([(1, 0, 0), (1, -1, 0), (0, 2, 2)], [(1,0,0), (0,1,0), (0, 0, 1)])
Matrix([
[1,  1,  -1],
[0, -1,   1],
[0,  0, 1/2]])
subspace(family)

Returns subspace of self generated by family.

Parameters

family (Iterable) – a set of vectors

Returns

a vector space

EXAMPLES:

simula : V = VectorSpace(QQ, 3); V
Vector Space of dimension 3 over Rational Numbers
simula : V.subspace({(1, 1, -2), (2, 0, 1)})
Subspace of QQ^3 generated by the family {(1, 1, -2), (2, 0, 1)}
simula.linalg.vector_space.gramSchmidt(*args, orthonormal=False)

GramShmidt orthogonalisation

class simula.linalg.vector_space.vector(v, *, column=False)

Bases: object

Representation of a vector.

EXAMPLES:

simula : v = vector((1, -2, 3))
simula : v
(1, -2, 3)
simula : 5v
(5, -10, 15)
simula : v in QQ^3
True
simula : v.T
[ 1]
[-2]
[ 3]
simula : v * v.T
14
simula :  A = matrix([[1, 2, 0], [-1, 2, 3], [0, -1, 2]]); A
Matrix([
[ 1,  2, 0],
[-1,  2, 3],
[ 0, -1, 2]])
simula : v * A
(3, -5, 0)
simula : A * v.T
[-3]
[ 4]
[ 8]
simula : w = vector((2, 2, 5), column=True); w
[2]
[2]
[5]
simula : v - 3w.T
(-5, -8, -12)

Linear Maps

Operations over linear maps

class simula.linalg.linear_map.LinearMap(symbols=None, expr=None, *, domain=None, codomain=None, matrix=None, basis1=None, basis2=None, check=True)

Bases: simula.calculus.functions.Function

Representation of linear maps.

Parameters
  • symbols – a tuple of symbols

  • expr – an expression or a tuple of expression

  • domain – (optional) a field or a vector space

  • codomain – (optional) a field or a vector space

  • matrix – (optional) a matrix

  • basis1 – a basis of the domain

  • basis2 – a basis of the codomain

  • check – a boolean

One can define a linear map by two methods

  1. First method : you know the expression of the linear map

simula : (x, y, z) = var("x,y,z")
simula : f = linear_map((x, y, z), (2x-y-z, x-y, -x+z)); f
Linear map from QQ^3 --> QQ^3 defined by (x, y, z) |--> (2x - y - z, x - y, -x + z)
simula : f(1, 2, -3)
(3, -1, -4)
simula : f.kernel()
Subspace of QQ^3 generated by the family {(1, 1, 1)}
simula : f.image()
Subspace of QQ^3 generated by the family {(2, 1, -1), (-1, -1, 0)}
simula : f.is_diagonalizable()
True
simula : f.eigenvals()
{1 - sqrt(2): 1, 1 + sqrt(2): 1, 0: 1}
simula : f.is_one_to_one()
False
  1. Second methodyou know the matrix associated to the linear map in some bases (if no basis

    is specified they are equal to canonical bases).

simula : A = matrix([[-1, 1, 1], [1, -1, 1], [1, 1, -1]]); A
Matrix([
[-1,  1,  1],
[ 1, -1,  1],
[ 1,  1, -1]])
simula : g = linear_map(matrix=A, domain=RR^3, codomain=RR^3); g
g = linear_map(matrix=A, domain=RR^3, codomain=RR^3); g
Linear map from RR^3 --> RR^3 defined by (x1, x2, x3) |--> (-x1 + x2 + x3, x1 - x2 + x3, x1 + x2 - x3)
simula : g(0, 1, 1)
(2, 0, 0)
simula : g.spectrum()
{1, -2}
simula : g.image()
Subspace of RR^3 generated by the family {(1, 1, -1), (1, -1, 1), (-1, 1, 1)}
simula : g.is_endomorphism()
True
simula : g.is_surjective()
True
det()

Returns the determinant of the linear map.

eigenvals()

Returns the eigen values of self.

eigenvects()

Returns the eigen vectors of self.

get_matrix(basis1=None, basis2=None)

Return the matrix associated to the linear map with respect to basis1 and basis2.

im()

Returns the image of self.

image()

Returns the image of self.

is_diagonalizable()

Tests if self is diagonalizable.

is_endomorphism()

Tests if self is an endomorphism.

is_idempotent()

Tests if self is idempotent.

is_injective()

Tests if self is an one-to-one.

is_isomorphism()

Tests if self is an isomorphism.

is_nilpotent()

Tests if self is nilpotent.

is_one_to_one()

Tests if self is an one-to-one.

is_surjective()

Tests if self is an surjective.

is_zero()

Tests if self is null.

ker()

Returns the kernel of self.

kernel()

Returns the kernel of self.

nullity()

Returns the nullity of the kernel of the linear map.

rank()

Returns the rank of the linear map.

spectrum()

Returns the spectrum of self i.e the set of eigen values of self.

trace()

Returns the trace of the linear map.

simula.linalg.linear_map.image(expr)

Image of a linear map or a matrix.

simula.linalg.linear_map.ker(expr)

Kernel of a linear map or a matrix.

simula.linalg.linear_map.kernel(expr)

Kernel of a linear map or a matrix.

simula.linalg.linear_map.linear_map

alias of simula.linalg.linear_map.LinearMap

simula.linalg.linear_map.linear_transformation

alias of simula.linalg.linear_map.LinearMap