Matrix and linear algebra operations for complex numbers using FastMath.
This namespace provides utilities for handling complex numbers represented as FastMath Vec2 objects, along with a suite of matrix operations tailored for complex matrices, including addition, multiplication, inversion, eigendecomposition, and more.
The functions ensure type safety and proper handling of complex arithmetic, leveraging FastMath's capabilities for performance and accuracy.
Matrix and linear algebra operations for complex numbers using FastMath. This namespace provides utilities for handling complex numbers represented as FastMath Vec2 objects, along with a suite of matrix operations tailored for complex matrices, including addition, multiplication, inversion, eigendecomposition, and more. The functions ensure type safety and proper handling of complex arithmetic, leveraging FastMath's capabilities for performance and accuracy.
(cholesky-decomposition)
(cholesky-decomposition A)
(cholesky-decomposition A eps)
Compute Cholesky decomposition A = L * L† for positive definite complex matrices.
Parameters:
Returns: Map with key
Exception is thrown if A is not square, not Hermitian, or not positive definite.
Compute Cholesky decomposition A = L * L† for positive definite complex matrices. Parameters: - A: square Hermitian positive definite complex matrix - eps: tolerance for checks (default 1e-10) Returns: Map with key - :L (lower triangular complex matrix) Exception is thrown if A is not square, not Hermitian, or not positive definite.
(complex->real z)
Extract real part of a complex number, checking it's actually real. Parameters:
Returns: Real part as double, throws if imaginary part is non-zero.
Exception is thrown if imaginary part is non-zero.
Extract real part of a complex number, checking it's actually real. Parameters: - z: complex number (Vec2 or complex map) Returns: Real part as double, throws if imaginary part is non-zero. Exception is thrown if imaginary part is non-zero.
(complex-matrix->real-matrix matrix)
Convert complex matrix to real matrix.
Parameters:
Returns: 2D array of doubles representing the real parts of the complex matrix.
Convert complex matrix to real matrix. Parameters: - matrix: matrix of complex numbers Returns: 2D array of doubles representing the real parts of the complex matrix.
(complex-matrix-shape matrix)
Get the shape of a matrix containing Complex elements.
Parameters:
Returns: [num-rows num-cols] of the matrix
Get the shape of a matrix containing Complex elements. Parameters: - matrix: matrix of complex numbers Returns: [num-rows num-cols] of the matrix
(complex-matrix? m)
Test if m represents a complex matrix.
Parameters:
Returns: true if m is a matrix (vector of vectors) of complex scalars, false otherwise.
Test if m represents a complex matrix. Parameters: - m: any value Returns: true if m is a matrix (vector of vectors) of complex scalars, false otherwise.
(complex-scalar? x)
Test if x represents a complex scalar (Vec2 or complex map).
Parameters:
Returns: true if x is a complex scalar representation, false otherwise.
Test if x represents a complex scalar (Vec2 or complex map). Parameters: - x: any value Returns: true if x is a complex scalar representation, false otherwise.
(complex-scale v scalar)
Scale a complex number by a scalar.
Parameters:
Returns: scaled complex number
Scale a complex number by a scalar. Parameters: - v: complex number (Vec2 or complex map) - scalar: real or complex scalar Returns: scaled complex number
(complex-vector? v)
Test if v represents a complex vector.
Parameters:
Returns: true if v is a vector of complex scalars, false otherwise.
Test if v represents a complex vector. Parameters: - v: any value Returns: true if v is a vector of complex scalars, false otherwise.
(complex? x)
Test if x is a FastMath Vec2 complex number.
Parameters:
Returns: true if x is a Vec2 complex number, false otherwise.
Test if x is a FastMath Vec2 complex number. Parameters: - x: any value Returns: true if x is a Vec2 complex number, false otherwise.
(condition-number A)
Compute the condition number κ₂(A) = ||A||₂ * ||A⁻¹||₂ for a complex matrix A.
Parameters:
Returns: Condition number κ₂(A)
Exception is thrown if A is not square or singular.
Compute the condition number κ₂(A) = ||A||₂ * ||A⁻¹||₂ for a complex matrix A. Parameters: - A: square complex matrix (n×n) Returns: Condition number κ₂(A) Exception is thrown if A is not square or singular.
(conjugate-transpose A)
Compute the conjugate transpose Aᴴ (Hermitian adjoint).
Parameters:
Returns: Conjugate transposed matrix Aᴴ
Compute the conjugate transpose Aᴴ (Hermitian adjoint). Parameters: - A: complex matrix Returns: Conjugate transposed matrix Aᴴ
(diagonal? A eps)
Check if a complex matrix A is diagonal (off-diagonal elements ≈ 0).
Parameters:
Returns: true if A is diagonal within tolerance eps, false otherwise.
Check if a complex matrix A is diagonal (off-diagonal elements ≈ 0). Parameters: - A: complex matrix - eps: tolerance for off-diagonal elements Returns: true if A is diagonal within tolerance eps, false otherwise.
(eigen-general A)
Compute eigenvalues and eigenvectors of a general matrix.
Parameters:
Returns: Map with keys
Exception is thrown if A is not square.
Compute eigenvalues and eigenvectors of a general matrix. Parameters: - A: square complex matrix Returns: Map with keys - :eigenvalues (vector of complex eigenvalues) and - :eigenvectors (matrix with eigenvectors as columns) Exception is thrown if A is not square.
(eigen-hermitian A)
Compute eigenvalues and eigenvectors of a Hermitian matrix A.
Parameters:
Returns: Map with keys
Exception is thrown if A is not square or not Hermitian.
Compute eigenvalues and eigenvectors of a Hermitian matrix A. Parameters: - A: square Hermitian complex matrix Returns: Map with keys - :eigenvalues (vector of all complex eigenvalues) - :eigenvectors (matrix with eigenvectors as columns) Exception is thrown if A is not square or not Hermitian.
(ensure-complex x)
Ensure input is a complex number.
Parameters:
Returns: Vec2 complex number
Exception is thrown if input cannot be converted.
Ensure input is a complex number. Parameters: - x: number, complex map, or Vec2 Returns: Vec2 complex number Exception is thrown if input cannot be converted.
(hadamard-product A B)
Compute the element-wise (Hadamard) product A ⊙ B.
Parameters:
Returns: Element-wise product of matrices A and B
Compute the element-wise (Hadamard) product A ⊙ B. Parameters: - A: complex matrix - B: complex matrix Returns: Element-wise product of matrices A and B
(hermitian? A eps)
Check if a complex matrix A is Hermitian (A ≈ Aᴴ).
Parameters:
Returns: true if A is Hermitian within tolerance eps, false otherwise.
Check if a complex matrix A is Hermitian (A ≈ Aᴴ). Parameters: - A: complex matrix - eps: tolerance for element-wise comparison Returns: true if A is Hermitian within tolerance eps, false otherwise.
(inner-product x y)
Compute the inner product ⟨x|y⟩ of two complex vectors.
Parameters:
Returns: Inner product ⟨x|y⟩
Exception is thrown if vectors have different lengths.
Compute the inner product ⟨x|y⟩ of two complex vectors. Parameters: - x: complex vector - y: complex vector Returns: Inner product ⟨x|y⟩ Exception is thrown if vectors have different lengths.
(inverse A)
Compute matrix inverse using Gaussian elimination for complex matrices.
Parameters:
Returns: Inverse of matrix A
Exception is thrown if A is singular or not square.
Compute matrix inverse using Gaussian elimination for complex matrices. Parameters: - A: square complex matrix Returns: Inverse of matrix A Exception is thrown if A is singular or not square.
(kronecker-product A B)
Compute the Kronecker (tensor) product A ⊗ B.
Parameters:
Returns: Kronecker product of matrices A and B
Compute the Kronecker (tensor) product A ⊗ B. Parameters: - A: complex matrix - B: complex matrix Returns: Kronecker product of matrices A and B
(lu-decomposition A)
Compute LU decomposition of a complex matrix A = P * L * U.
Parameters:
Returns: Map with keys
Exception is thrown if A is not square.
Compute LU decomposition of a complex matrix A = P * L * U. Parameters: - A: square complex matrix Returns: Map with keys - :L (lower triangular complex matrix) - :U (upper triangular complex matrix) - :P (permutation complex matrix) Exception is thrown if A is not square.
(matrix-add A B)
Add two complex matrices A + B.
Parameters:
Returns: Sum of matrices A and B
Add two complex matrices A + B. Parameters: - A: complex matrix - B: complex matrix Returns: Sum of matrices A and B
(matrix-exp A)
Compute the matrix exponential exp(A) using eigendecomposition.
Parameters:
Returns: Matrix exponential exp(A)
Exception is thrown if A is not square or if computation fails.
Compute the matrix exponential exp(A) using eigendecomposition. Parameters: - A: square complex matrix Returns: Matrix exponential exp(A) Exception is thrown if A is not square or if computation fails.
(matrix-log A)
Compute the principal matrix logarithm log(A) using eigendecomposition.
Parameters:
Returns: Principal matrix logarithm log(A)
Exception is thrown if A is not square or if computation fails.
Compute the principal matrix logarithm log(A) using eigendecomposition. Parameters: - A: square complex matrix Returns: Principal matrix logarithm log(A) Exception is thrown if A is not square or if computation fails.
(matrix-multiply A B)
Multiply two complex matrices A * B.
Parameters:
Returns: Product of matrices A and B
Exception is thrown if dimensions are incompatible.
Multiply two complex matrices A * B. Parameters: - A: complex matrix - B: complex matrix Returns: Product of matrices A and B Exception is thrown if dimensions are incompatible.
(matrix-negate A)
Negate a complex matrix -A.
Parameters:
Returns: Negated matrix -A
Negate a complex matrix -A. Parameters: - A: complex matrix Returns: Negated matrix -A
(matrix-scale A alpha)
Scale a complex matrix by a scalar.
Parameters:
Returns: Scaled matrix
Scale a complex matrix by a scalar. Parameters: - A: complex matrix - alpha: real or complex scalar Returns: Scaled matrix
(matrix-sqrt A)
Compute the principal matrix square root √A using eigendecomposition.
Parameters:
Returns: Principal matrix square root √A
Exception is thrown if A is not square or not positive semidefinite.
Compute the principal matrix square root √A using eigendecomposition. Parameters: - A: square complex matrix Returns: Principal matrix square root √A Exception is thrown if A is not square or not positive semidefinite.
(matrix-subtract A B)
Subtract two complex matrices A - B.
Parameters:
Returns: Difference of matrices A and B
Subtract two complex matrices A - B. Parameters: - A: complex matrix - B: complex matrix Returns: Difference of matrices A and B
(matrix-vector-product A x)
Perform matrix-vector multiplication A * x.
Parameters:
Returns: Resulting complex vector
Exception is thrown if dimensions are incompatible.
Perform matrix-vector multiplication A * x. Parameters: - A: complex matrix - x: complex vector Returns: Resulting complex vector Exception is thrown if dimensions are incompatible.
(norm2 x)
Compute the Euclidean (L2) norm ||x||₂ of a complex vector x.
Parameters:
Returns: Euclidean norm ||x||₂
Compute the Euclidean (L2) norm ||x||₂ of a complex vector x. Parameters: - x: complex vector Returns: Euclidean norm ||x||₂
(outer-product x y)
Compute the outer product x ⊗ y†.
Parameters:
Returns: Matrix representing the outer product
Compute the outer product x ⊗ y†. Parameters: - x: complex vector - y: complex vector Returns: Matrix representing the outer product
(positive-semidefinite? A eps)
Check if a complex matrix A is positive semidefinite.
Parameters:
Returns: true if A is positive semidefinite within tolerance eps, false otherwise.
Exception is thrown if A is not square or not Hermitian.
Check if a complex matrix A is positive semidefinite. Parameters: - A: square complex matrix - eps: tolerance for eigenvalue check Returns: true if A is positive semidefinite within tolerance eps, false otherwise. Exception is thrown if A is not square or not Hermitian.
(qr-decomposition A)
Compute QR decomposition of a complex matrix A = Q * R.
Parameters:
Returns: Map with keys
Exception is thrown if decomposition fails.
Compute QR decomposition of a complex matrix A = Q * R. Parameters: - A: complex matrix (m×n) Returns: Map with keys - :Q (m×m unitary complex matrix) - :R (m×n upper triangular complex matrix) Exception is thrown if decomposition fails.
(real-matrix? matrix)
Check if a matrix contains only real numbers (zero imaginary parts).
Parameters:
Returns: true if all elements have negligible imaginary part, false otherwise.
Check if a matrix contains only real numbers (zero imaginary parts). Parameters: - matrix: matrix of complex numbers Returns: true if all elements have negligible imaginary part, false otherwise.
(solve-linear A b)
Solve linear system using Gaussian elimination for complex matrices.
Parameters:
Returns: Solution vector x such that A*x = b
Exception is thrown if A is singular or dimensions are incompatible.
Solve linear system using Gaussian elimination for complex matrices. Parameters: - A: square complex matrix - b: complex vector (right-hand side) Returns: Solution vector x such that A*x = b Exception is thrown if A is singular or dimensions are incompatible.
(spectral-norm A)
Compute the spectral norm ||A||₂ (largest singular value) of a complex matrix A.
Parameters:
Returns: Spectral norm ||A||₂
Exception is thrown if computation fails.
Compute the spectral norm ||A||₂ (largest singular value) of a complex matrix A. Parameters: - A: complex matrix (m×n) Returns: Spectral norm ||A||₂ Exception is thrown if computation fails.
(svd A)
Compute Singular Value Decomposition A = U * S * V† for complex matrices.
Parameters:
Returns: Map with keys
Exception is thrown if decomposition fails.
Compute Singular Value Decomposition A = U * S * V† for complex matrices. Parameters: - A: complex matrix (m×n) Returns: Map with keys - :U (m×m complex matrix) - :S (vector of singular values, length min(m,n)) - :V† (n×n complex matrix, conjugate transpose of V) Exception is thrown if decomposition fails.
(trace A)
Compute the trace Tr(A) = Σᵢ aᵢᵢ of a complex matrix A.
Parameters:
Returns: Trace of matrix A
Exception is thrown if A is not square.
Compute the trace Tr(A) = Σᵢ aᵢᵢ of a complex matrix A. Parameters: - A: square complex matrix Returns: Trace of matrix A Exception is thrown if A is not square.
(transpose A)
Compute the transpose of a complex matrix Aᵀ.
Parameters:
Returns: Transposed matrix Aᵀ
Compute the transpose of a complex matrix Aᵀ. Parameters: - A: complex matrix Returns: Transposed matrix Aᵀ
(unitary? U eps)
Check if a complex matrix U is unitary (Uᴴ U ≈ I).
Parameters:
Returns: true if U is unitary within tolerance eps, false otherwise.
Check if a complex matrix U is unitary (Uᴴ U ≈ I). Parameters: - U: complex matrix - eps: tolerance for element-wise comparison Returns: true if U is unitary within tolerance eps, false otherwise.
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |