public abstract class LinTool
extends java.lang.Object
LinTool is what you need to extend
in order to provide implementations of methods herein. For
convenience an empty implementation is provided in
LinToolEmpty. In general, if there's an error or
incompatible vectors/matrices, return null or -1 as appropriate
(depending on the return type).
| Constructor and Description |
|---|
LinTool() |
| Modifier and Type | Method and Description |
|---|---|
abstract ComplexNumber[][] |
add(ComplexNumber[][] A,
ComplexNumber[][] B)
Add two complex matrices.
|
abstract ComplexNumber[] |
add(ComplexNumber[] u,
ComplexNumber[] v)
Add two complex vectors.
|
abstract double[][] |
add(double[][] A,
double[][] B)
Add two matrices.
|
abstract double[] |
add(double[] u,
double[] v)
Take in two vectors and return the sum.
|
abstract double |
add(double a,
double b) |
abstract boolean |
approxEquals(double[][] A,
double[][] B,
double errorTolerance)
See if the sum of squared differences of elements is within a tolerance.
|
abstract boolean |
approxEquals(double[] u,
double[] v,
double errorTolerance)
Take in two vectors, and a small number (the error, or tolerance),
and check if the squared difference is within the tolerance.
|
abstract boolean |
areColumnsLI(double[][] A)
See if the columns of A are linearly independent.
|
abstract ComplexNumber[] |
computeDFT(double[] signal)
Compute the DFT of a real-valued signal.
|
abstract LinResult |
computeEigenvalues(double[][] A)
Compute eigenvalues, returning
an instance of
LinResult with the eigenvalues
in lambda and the eigenvectors in S. |
abstract LinResult |
computeEigenvaluesAndVectors(double[][] A)
Compute eigenvalues, testing that the matrix is symmetric, returning
an instance of
LinResult with the eigenvalues
in lambda and the eigenvectors in S. |
abstract LinResult |
computeEigenvaluesAndVectorsSymmetric(double[][] A)
Compute eigenvalues, testing that the matrix is symmetric, returning
an instance of
LinResult with the eigenvalues
in lambda and the eigenvectors in S. |
abstract ComplexNumber[] |
computeFFT(double[] signal)
Compute the FFT of a real-valued signal.
|
abstract ComplexNumber[] |
computeInverseDFT(ComplexNumber[] spectrum)
Compute the inverse DFT.
|
abstract ComplexNumber[] |
computeInverseFFT(ComplexNumber[] spectrum)
Compute the inverse of a real-valued signal.
|
abstract LinResult |
computeQR(double[][] A)
Assuming the columns of A are independent, compute the QR
decomposition.
|
abstract LinResult |
computeREF(double[][] A,
double[] b)
Compute the REF and return an instance of
LinResult
with the ref variable set to the REF and the
isPivotColumn variable set correctly.
|
abstract LinResult |
computeRREF(double[][] A,
double[] b)
Compute the RREF and return an instance of
LinResult
with the rref variable set to the RREF
and the
isPivotColumn variable set correctly.
|
abstract LinResult |
computeSpectralDecompositionSymmetric(double[][] A)
Compute the spectral decomposition for symmetric matrices, returning
an instance of
LinResult with the eigenvalues
in lambda, the eigenvectors in S
and the inverse of S in Sinv. |
abstract LinResult |
computeSVD(double[][] A)
Compute the SVD of A, returning
an instance of
LinResult with the
U,V matrices set, singular values both in
Sigma (as matrix) and in sigma (as
a vector). |
abstract double |
cosine(double[] u,
double[] v)
Return the cosine of the angle between two vectors.
|
abstract ComplexNumber |
dotProduct(ComplexNumber[] u,
ComplexNumber[] v)
Compute the (Hermitian) dot product.
|
abstract double |
dotProduct(double[] u,
double[] v)
Take in two vectors and return the dot
product. Return -1 if there's an error
|
abstract double |
frobeniusNorm(double[][] A)
Compute the Frobenius norm: add the squares of the elements.
|
abstract double[] |
getColumnAsVector(double[][] A,
int col)
Extract the given column from the matrix and return as a vector.
|
abstract double[] |
getRowAsVector(double[][] A,
int row)
Extract the given row from the matrix and return as a vector.
|
abstract LinResult |
gramSchmidt(double[][] A)
Assuming the columns of A are independent (form a basis),
use Gram-Schmidt to find the orthogonal basis.
|
abstract ComplexNumber[][] |
hermitianTranspose(ComplexNumber[][] A)
Compute the Hermitian transpose.
|
abstract LinResult |
inverse(double[][] A)
Compute the inverse of A and return an instance of
LinResult
with the inverse in Ainv. |
abstract ComplexNumber[][] |
makeDFTMatrix(int n)
Compute the DFT matrix of size n.
|
static LinTool |
makeInstance() |
abstract ComplexNumber[][] |
makeInverseDFTMatrix(int n)
Compute the inverse DFT matrix of size n.
|
abstract ComplexNumber[] |
matrixVectorMult(ComplexNumber[][] A,
ComplexNumber[] v)
Product of a complex matrix and a complex vector.
|
abstract double[] |
matrixVectorMult(double[][] A,
double[] v)
Product of a matrix and a vector.
|
abstract ComplexNumber[][] |
mult(ComplexNumber[][] A,
ComplexNumber[][] B)
Product of two complex matrices.
|
abstract double[][] |
mult(double[][] A,
double[][] B)
Product of two matrices.
|
abstract double |
norm(ComplexNumber[] v)
Compute the norm.
|
abstract double |
norm(double[] v)
Compute the norm of a vector.
|
abstract LinResult |
pseudoInverse(double[][] A)
Use the LinToolLibrary's SVD to compute the pseudoinverse, returning
an instance of
LinResult with the pseudoinverse in
A_plus. |
abstract ComplexNumber[] |
scalarProduct(ComplexNumber alpha,
ComplexNumber[] v)
Compute the scalar product (where the scalar is complex).
|
abstract ComplexNumber[][] |
scalarProduct(ComplexNumber alpha,
ComplexNumber[][] A)
Product of scalar (complex) and a complex matrix.
|
abstract double[] |
scalarProduct(double alpha,
double[] v)
Take in a scalar and a vector and return the scalar product.
|
abstract double[][] |
scalarProduct(double alpha,
double[][] A)
Scalar product: scalar times a matrix.
|
abstract LinResult |
solveFromREF(double[][] A,
double[] b)
Solve for x in Ax=b using REF and return an instance of
LinResult
with ref, isPivotColumn, pivotRow, rank, x, solutionExists, isUniqueSolution. |
abstract LinResult |
solveFromRREF(double[][] A,
double[] b)
Solve for x in Ax=b using RREF and return an instance of
LinResult
with x, rref, isPivotColumn, pivotRow, rank, solutionExists, isUniqueSolution. |
abstract LinResult |
solveLeastSquares(double[][] A,
double[] b)
Use the LinToolLibrary's SVD to solve least-squares, returning
an instance of
LinResult with the solution in
x. |
abstract double[][] |
transpose(double[][] A)
Matrix transpose.
|
abstract double[][] |
vectorLeftMult(double[] u,
double[] v)
Left multiplication of two vectors: results in a
matrix such that A[i][j]=u[i]*v[j]. This is not tested by
LinTool. Write your own tests.
|
abstract double[] |
vectorMatrixMult(double[] v,
double[][] A)
Product of a vector and a matrix (left multiplication).
|
public abstract double add(double a,
double b)
public abstract double[] add(double[] u,
double[] v)
public abstract double norm(double[] v)
public abstract double dotProduct(double[] u,
double[] v)
public abstract double[] scalarProduct(double alpha,
double[] v)
public abstract boolean approxEquals(double[] u,
double[] v,
double errorTolerance)
public abstract double cosine(double[] u,
double[] v)
public abstract double[][] add(double[][] A,
double[][] B)
public abstract double[][] scalarProduct(double alpha,
double[][] A)
public abstract double[][] mult(double[][] A,
double[][] B)
public abstract double[] matrixVectorMult(double[][] A,
double[] v)
public abstract double[] vectorMatrixMult(double[] v,
double[][] A)
public abstract double[][] vectorLeftMult(double[] u,
double[] v)
public abstract double[][] transpose(double[][] A)
public abstract double frobeniusNorm(double[][] A)
public abstract boolean approxEquals(double[][] A,
double[][] B,
double errorTolerance)
public abstract double[] getColumnAsVector(double[][] A,
int col)
public abstract double[] getRowAsVector(double[][] A,
int row)
public abstract LinResult computeREF(double[][] A, double[] b)
LinResult
with the ref variable set to the REF. Also properly
set isPivotColumn, pivotRow, and
rank.public abstract LinResult computeRREF(double[][] A, double[] b)
LinResult
with the rref variable set to the REF.
Also properly
set isPivotColumn, pivotRow, rank.public abstract LinResult solveFromREF(double[][] A, double[] b)
LinResult
with x, solutionExists, isUniqueSolution.public abstract LinResult solveFromRREF(double[][] A, double[] b)
LinResult
with x, solutionExists, isUniqueSolution.public abstract LinResult inverse(double[][] A)
LinResult
with the inverse in Ainv.public abstract boolean areColumnsLI(double[][] A)
public abstract LinResult gramSchmidt(double[][] A)
LinResult with the orthogonal
vectors of the basis in V and their orthonormal
versions in Q.public abstract LinResult computeQR(double[][] A)
LinResult with the orthogonal
vectors of the basis in Q and the coefficients
in R.public abstract LinResult computeEigenvalues(double[][] A)
LinResult with the eigenvalues
in lambda and the eigenvectors in S.public abstract LinResult computeEigenvaluesAndVectorsSymmetric(double[][] A)
LinResult with the eigenvalues
in lambda and the eigenvectors in S.public abstract LinResult computeEigenvaluesAndVectors(double[][] A)
LinResult with the eigenvalues
in lambda and the eigenvectors in S.public abstract LinResult computeSpectralDecompositionSymmetric(double[][] A)
LinResult with the eigenvalues
in lambda, the eigenvectors in S
and the inverse of S in Sinv.public abstract LinResult computeSVD(double[][] A)
LinResult with the
U,V matrices set, singular values both in
Sigma (as matrix) and in sigma (as
a vector). The matrices returned should be trimmed down
to match the rank, which should be set in rank.
And U,V,Sigma,sigma need to be sorted in
decreasing order of the singular values.public abstract LinResult pseudoInverse(double[][] A)
LinResult with the pseudoinverse in
A_plus.public abstract LinResult solveLeastSquares(double[][] A, double[] b)
LinResult with the solution in
x.public abstract ComplexNumber[] add(ComplexNumber[] u, ComplexNumber[] v)
public abstract double norm(ComplexNumber[] v)
public abstract ComplexNumber dotProduct(ComplexNumber[] u, ComplexNumber[] v)
public abstract ComplexNumber[] scalarProduct(ComplexNumber alpha, ComplexNumber[] v)
public abstract ComplexNumber[][] add(ComplexNumber[][] A, ComplexNumber[][] B)
public abstract ComplexNumber[][] scalarProduct(ComplexNumber alpha, ComplexNumber[][] A)
public abstract ComplexNumber[][] mult(ComplexNumber[][] A, ComplexNumber[][] B)
public abstract ComplexNumber[] matrixVectorMult(ComplexNumber[][] A, ComplexNumber[] v)
public abstract ComplexNumber[][] hermitianTranspose(ComplexNumber[][] A)
public abstract ComplexNumber[][] makeDFTMatrix(int n)
public abstract ComplexNumber[][] makeInverseDFTMatrix(int n)
public abstract ComplexNumber[] computeDFT(double[] signal)
public abstract ComplexNumber[] computeInverseDFT(ComplexNumber[] spectrum)
public abstract ComplexNumber[] computeFFT(double[] signal)
public abstract ComplexNumber[] computeInverseFFT(ComplexNumber[] spectrum)
public static LinTool makeInstance()