Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.domain.math.fastmath.complex-linear-algebra

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.
raw docstring

cholesky-decompositionclj

(cholesky-decomposition)
(cholesky-decomposition A)
(cholesky-decomposition A eps)

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.

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.
sourceraw docstring

complex->realclj

(complex->real z)

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.

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.
sourceraw docstring

complex-matrix->real-matrixclj

(complex-matrix->real-matrix 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.

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.
sourceraw docstring

complex-matrix-shapeclj

(complex-matrix-shape matrix)

Get the shape of a matrix containing Complex elements.

Parameters:

  • matrix: matrix of complex numbers

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
sourceraw docstring

complex-matrix?clj

(complex-matrix? m)

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.

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.
sourceraw docstring

complex-scalar?clj

(complex-scalar? x)

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.

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.
sourceraw docstring

complex-scaleclj

(complex-scale v scalar)

Scale a complex number by a scalar.

Parameters:

  • v: complex number (Vec2 or complex map)
  • scalar: real or complex scalar

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
sourceraw docstring

complex-vector?clj

(complex-vector? v)

Test if v represents a complex vector.

Parameters:

  • v: any value

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.
sourceraw docstring

complex?clj

(complex? x)

Test if x is a FastMath Vec2 complex number.

Parameters:

  • x: any value

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.
sourceraw docstring

condition-numberclj

(condition-number A)

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.

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.
sourceraw docstring

conjugate-transposeclj

(conjugate-transpose A)

Compute the conjugate transpose Aᴴ (Hermitian adjoint).

Parameters:

  • A: complex matrix

Returns: Conjugate transposed matrix Aᴴ

Compute the conjugate transpose Aᴴ (Hermitian adjoint).

Parameters:
- A: complex matrix

Returns:
Conjugate transposed matrix Aᴴ
sourceraw docstring

default-toleranceclj

source

diagonal?clj

(diagonal? A eps)

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.

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.
sourceraw docstring

eigen-generalclj

(eigen-general A)

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.

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.
sourceraw docstring

eigen-hermitianclj

(eigen-hermitian A)

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.

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.
sourceraw docstring

ensure-complexclj

(ensure-complex x)

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.

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.
sourceraw docstring

hadamard-productclj

(hadamard-product A 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

Compute the element-wise (Hadamard) product A ⊙ B.

Parameters:
- A: complex matrix
- B: complex matrix

Returns:
Element-wise product of matrices A and B
sourceraw docstring

hermitian?clj

(hermitian? A eps)

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.

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.
sourceraw docstring

inner-productclj

(inner-product x y)

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.

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.
sourceraw docstring

inverseclj

(inverse A)

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.

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.
sourceraw docstring

kronecker-productclj

(kronecker-product A B)

Compute the Kronecker (tensor) product A ⊗ B.

Parameters:

  • A: complex matrix
  • B: complex matrix

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
sourceraw docstring

lu-decompositionclj

(lu-decomposition A)

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.

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.
sourceraw docstring

matrix-addclj

(matrix-add A B)

Add two complex matrices A + B.

Parameters:

  • A: complex matrix
  • B: complex matrix

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
sourceraw docstring

matrix-expclj

(matrix-exp A)

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.

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.
sourceraw docstring

matrix-logclj

(matrix-log A)

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.

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.
sourceraw docstring

matrix-multiplyclj

(matrix-multiply A B)

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.

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.
sourceraw docstring

matrix-negateclj

(matrix-negate A)

Negate a complex matrix -A.

Parameters:

  • A: complex matrix

Returns: Negated matrix -A

Negate a complex matrix -A.

Parameters:
- A: complex matrix

Returns:
Negated matrix -A
sourceraw docstring

matrix-scaleclj

(matrix-scale A alpha)

Scale a complex matrix by a scalar.

Parameters:

  • A: complex matrix
  • alpha: real or complex scalar

Returns: Scaled matrix

Scale a complex matrix by a scalar.

Parameters:
- A: complex matrix
- alpha: real or complex scalar

Returns:
Scaled matrix
sourceraw docstring

matrix-sqrtclj

(matrix-sqrt A)

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.

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.
sourceraw docstring

matrix-subtractclj

(matrix-subtract A B)

Subtract two complex matrices A - B.

Parameters:

  • A: complex matrix
  • B: complex matrix

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
sourceraw docstring

matrix-vector-productclj

(matrix-vector-product A x)

Perform matrix-vector multiplication A * x.

Parameters:

  • A: complex matrix
  • x: complex vector

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.
sourceraw docstring

norm2clj

(norm2 x)

Compute the Euclidean (L2) norm ||x||₂ of a complex vector x.

Parameters:

  • x: complex vector

Returns: Euclidean norm ||x||₂

Compute the Euclidean (L2) norm ||x||₂ of a complex vector x.

Parameters:
- x: complex vector

Returns:
Euclidean norm ||x||₂
sourceraw docstring

outer-productclj

(outer-product x y)

Compute the outer product x ⊗ y†.

Parameters:

  • x: complex vector
  • y: complex vector

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
sourceraw docstring

positive-semidefinite?clj

(positive-semidefinite? A eps)

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.

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.
sourceraw docstring

qr-decompositionclj

(qr-decomposition A)

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.

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.
sourceraw docstring

real-matrix?clj

(real-matrix? matrix)

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.

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.
sourceraw docstring

solve-linearclj

(solve-linear A b)

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.

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.
sourceraw docstring

spectral-normclj

(spectral-norm A)

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.

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.
sourceraw docstring

svdclj

(svd A)

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.

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.
sourceraw docstring

traceclj

(trace A)

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.

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.
sourceraw docstring

transposeclj

(transpose A)

Compute the transpose of a complex matrix Aᵀ.

Parameters:

  • A: complex matrix

Returns: Transposed matrix Aᵀ

Compute the transpose of a complex matrix Aᵀ.

Parameters:
 - A: complex matrix

Returns:
Transposed matrix Aᵀ
sourceraw docstring

unitary?clj

(unitary? U eps)

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.

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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close