cmplxalg

package module
v0.0.0-...-39ca1b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2022 License: BSD-2-Clause Imports: 4 Imported by: 0

README

Complex Linear Algebra cmplxalg

A complex linear algebra package written in golang.

Implements many common linear algebra algorithms for complex-valued matrices and vectors.

This package implements the types Matrix and Vector, both of which are arrays of complex numbers. It can utilize these types to perform many different operations such as examining if two vectors are parallell, finding the angle between them, and calculating the inverse of a matrix. All of this with fully-fledged support for complex numbers.

Documentation

Index

Constants

View Source
const ERR_AUGM_ROW = "Cannot augment matrices with differing amount of rows"
View Source
const ERR_CRSP_DIM = "Can only calculate cross product of 3-dimensional vectors"
View Source
const ERR_DETM_SQR = "Cannot calculate inverse of non-square matrix"
View Source
const ERR_DOTP_DIM = "Cannot calculate dot-product of vectors with different dimensions"

Panic Messages --------------------------------------------------------------

View Source
const ERR_INVR_SNG = "Cannot calculate inverse of singular matrix"
View Source
const ERR_INVR_SQR = "Cannot calculate inverse of non-square matrix"
View Source
const ERR_MTRX_DIM = "Incompatible matrix dimensions"
View Source
const ERR_MTRX_RNG = "The index to get/set is out of range"
View Source
const ERR_MTRX_SNG = "Cannot row-reduce singular matrix"
View Source
const ERR_NORM_ZER = "Cannot normalize the zero-vector"
View Source
const ERR_PARA_ZER = "Cannot determine if zero-vector is parallell to another vector"
View Source
const ERR_PERP_ZER = "Cannot determine if zero-vector is perpendicular to another vector"

Variables

This section is empty.

Functions

func Angle

func Angle(v, w *Vector) complex128

Returns the angle between vectors 'v' and 'w' O(n)

func DotProduct

func DotProduct(v, w *Vector) complex128

Returns dot product 'v*w'. Panics if 'v' and 'w' differs in dimension. O(n)

func Parallell

func Parallell(v, w *Vector) bool

Returns whether 'v' and 'w' are perpendicular. If 'v' and 'w' differ in dimension it pads the smaller one with zeroes. Panics if 'v' or 'w' are zero-vectors O(n)

func Perpendicular

func Perpendicular(v, w *Vector) bool

Returns whether 'v' and 'w' are perpendicular. Panics if 'v' or 'w' are zero-vectors O(n)

func TestAll

func TestAll()

Types

type Matrix

type Matrix [][]complex128

func Identity

func Identity(size int) *Matrix

Returns identity matrix of specified size. O(n^2)

func Zeroes

func Zeroes(rows, columns int) *Matrix

Returns matrix with specified size filled with zeroes. O(n*m) TODO: Panic if rows or columns == 0

func (*Matrix) Augment

func (m *Matrix) Augment(a *Matrix)

Augments matrix 'm' with matrix 'a'. Panics if sizes are incompatible. O(n*m + p*q)

func (*Matrix) Columns

func (m *Matrix) Columns() int

Returns amount of columns in matrix 'm' O(1)

func (*Matrix) Conjugate

func (m *Matrix) Conjugate()

Conjugates matrix 'm'. O(n*m)

func (*Matrix) Copy

func (m *Matrix) Copy() *Matrix

Return copy of matrix 'm' O(n*m)

func (*Matrix) Determinant

func (m *Matrix) Determinant() complex128

Returns determinant of square matrix 'm' Panics if 'm' is not square. TODO: Unsure if works for complex matrices

func (*Matrix) Equal

func (a *Matrix) Equal(b *Matrix) bool

Returns whether 'a' is equal to 'b' by comparing elementwise. O(n*m)

func (*Matrix) GetColumn

func (m *Matrix) GetColumn(index int) *Vector

Get column 'index' of matrix 'm' starting at 0. Panics if out of range. O(n)

func (*Matrix) GetRow

func (m *Matrix) GetRow(index int) *Vector

Get row 'index' of matrix 'm' starting at 0. Panics if out of range. O(n)

func (*Matrix) HermitianTranspose

func (m *Matrix) HermitianTranspose()

Transposes and conjugates matrix 'm'. O(n*m)

func (*Matrix) Inverse

func (m *Matrix) Inverse()

Inverses matrix 'm'. Panics if matrix isn't invertible.

func (*Matrix) IsHermitian

func (m *Matrix) IsHermitian() bool

Returns whether matrix 'm' is hermitian or not. O(n*m)

func (*Matrix) IsInvertible

func (m *Matrix) IsInvertible() bool

Returns whether 'm' is invertible or not.

func (*Matrix) IsSingular

func (m *Matrix) IsSingular() bool

Returns whether 'm' is singular or not. TODO: Defer to recover from singular matrix panic in Determinant()

func (*Matrix) MatrixMultiply

func (m *Matrix) MatrixMultiply(a *Matrix)

Multiplies matrix 'm' by matrix 'a' O(n^3)

func (*Matrix) RR

func (m *Matrix) RR()

Perform row reduction on matrix 'm'. Panics if singular matrix.

func (*Matrix) RREF

func (m *Matrix) RREF()

Find Row-Reduced Echelon Form of matrix 'm'. Panics if singular matrix.

func (*Matrix) RealString

func (m *Matrix) RealString() string

Return string representation of real matrix 'm' O(n*m)

func (*Matrix) Rows

func (m *Matrix) Rows() int

Returns amount of rows in matrix 'm' O(1)

func (*Matrix) ScalarAdd

func (m *Matrix) ScalarAdd(f complex128)

Adds scalar 'f' to each element in matrix 'm' O(n*m)

func (*Matrix) ScalarMultiply

func (m *Matrix) ScalarMultiply(f complex128)

Multiplies each element in matrix 'm' by scalar 'f' O(n*m)

func (*Matrix) SetColumn

func (m *Matrix) SetColumn(index int, col *Vector)

Set column 'index' of matrix 'm' to 'col'. Column index starts at 0. Panics if out of range. O(n)

func (*Matrix) SetRow

func (m *Matrix) SetRow(index int, row *Vector)

Set column 'index' of matrix 'm' to 'row'. Column index starts at 0. Panics if out of range. O(n)

func (*Matrix) String

func (m *Matrix) String() string

Return string representation of matrix 'm' O(n*m)

func (*Matrix) Transpose

func (m *Matrix) Transpose()

Transposes matrix 'm'. O(n*m)

type Vector

type Vector []complex128

func CrossProduct

func CrossProduct(v, w *Vector) *Vector

Returns cross product 'vxw'. Panics if 'v' or 'w' not 3-dimensional. O(1)

func (*Vector) Add

func (v *Vector) Add(w *Vector)

Add 'w' to vector 'v'. Pads vector with zeroes if different sizes O(n), n is highest dimension of 'v', 'w'

func (*Vector) Conjugate

func (v *Vector) Conjugate()

Conjugate vector element-wise. O(n)

func (*Vector) Copy

func (v *Vector) Copy() *Vector

Returns copy of vector. O(n)

func (*Vector) Equal

func (v *Vector) Equal(w *Vector) bool

Returns whether 'v' is equal to 'w' by comparing element-wise. O(n)

func (*Vector) Magnitude

func (v *Vector) Magnitude() complex128

Return magnitude of vector O(n)

func (*Vector) MatrixMultiply

func (v *Vector) MatrixMultiply(a *Matrix)

Multiply vector 'v' by matrix 'a'. O(n)

func (*Vector) Normalize

func (v *Vector) Normalize()

Normalize 'v'. O(n)

func (*Vector) ScalarMultiply

func (v *Vector) ScalarMultiply(factor complex128)

Multiply 'v' by complex factor. O(n)

func (*Vector) Sub

func (v *Vector) Sub(w *Vector)

Subtract 'w' from vector 'v'. Pads vector with zeroes if different sizes O(n), n is highest dimension of 'v', 'w'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL