org.ojalgo.matrix.decomposition

## Class HermitianEvD<N extends Number>

• All Implemented Interfaces:

```public abstract class HermitianEvD<N extends Number>
extends Object
implements MatrixDecomposition.Solver<N>```
Eigenvalues and eigenvectors of a real matrix.

If A is symmetric, then A = V*D*V' where the eigenvalue matrix D is diagonal and the eigenvector matrix V is orthogonal. I.e. A = V.times(D.times(V.transpose())) and V.times(V.transpose()) equals the identity matrix.

If A is not symmetric, then the eigenvalue matrix D is block diagonal with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, lambda + i*mu, in 2-by-2 blocks, [lambda, mu; -mu, lambda]. The columns of V represent the eigenvectors in the sense that A*V = V*D, i.e. A.times(V) equals V.times(D). The matrix V may be badly conditioned, or even singular, so the validity of the equation A = V*D*inverse(V) depends upon V.cond().

• ### Nested classes/interfaces inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition

`MatrixDecomposition.Determinant<N extends Number>, MatrixDecomposition.EconomySize<N extends Number>, MatrixDecomposition.Factory<D extends MatrixDecomposition<?>>, MatrixDecomposition.Hermitian<N extends Number>, MatrixDecomposition.Solver<N extends Number>, MatrixDecomposition.Values<N extends Number>`

`SolverTask.Factory<N extends Number>`

`InverterTask.Factory<N extends Number>`
• ### Nested classes/interfaces inherited from interface org.ojalgo.matrix.decomposition.Eigenvalue

`Eigenvalue.Eigenpair, Eigenvalue.Factory<N extends Number>`

• ### Fields inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition

`TYPICAL`

`BIG, COMPLEX, PRIMITIVE`

`BIG, COMPLEX, PRIMITIVE`
• ### Fields inherited from interface org.ojalgo.matrix.decomposition.Eigenvalue

`BIG, COMPLEX, PRIMITIVE`
• ### Constructor Summary

Constructors
Modifier Constructor and Description
`protected ` ```HermitianEvD(PhysicalStore.Factory<N,? extends DecompositionStore<N>> aFactory, org.ojalgo.matrix.decomposition.TridiagonalDecomposition<N> tridiagonal)```
• ### Method Summary

All Methods
Modifier and Type Method and Description
`protected AggregatorSet<N>` `aggregator()`
`protected DecompositionStore<N>` ```allocate(long numberOfRows, long numberOfColumns)```
`protected boolean` `aspectRatioNormal(boolean aspectRatioNormal)`
`N` `calculateDeterminant(Access2D<?> matrix)`
`boolean` `checkAndCompute(MatrixStore<N> matrix)`
Absolutely must check if the matrix is hermitian or not.
`protected MatrixStore<N>` `collect(Access2D.Collectable<N,? super DecompositionStore<N>> source)`
`protected boolean` `computed(boolean computed)`
`boolean` `computeValuesOnly(Access2D.Collectable<N,? super PhysicalStore<N>> matrix)`
`protected DecompositionStore<N>` `copy(Access2D<?> source)`
`boolean` `decompose(Access2D.Collectable<N,? super PhysicalStore<N>> matrix)`
`protected boolean` ```doGeneral(Access2D.Collectable<N,? super PhysicalStore<N>> matrix, boolean eigenvaluesOnly)```
`protected boolean` ```doHermitian(Access2D.Collectable<N,? super PhysicalStore<N>> matrix, boolean valuesOnly)```
`protected FunctionSet<N>` `function()`
`MatrixStore<N>` `getD()`
The only requirements on [D] are that it should contain the eigenvalues and that [A][V] = [V][D].
`N` `getDeterminant()`
A matrix' determinant is the product of its eigenvalues.
`Array1D<ComplexNumber>` `getEigenvalues()`
Even for real matrices the eigenvalues (and eigenvectors) are potentially complex numbers.
`void` ```getEigenvalues(double[] realParts, Optional<double[]> imaginaryParts)```
`MatrixStore<N>` `getInverse()`
The output must be a "right inverse" and a "generalised inverse".
`MatrixStore<N>` `getInverse(PhysicalStore<N> preallocated)`
Implementiong this method is optional.
`MatrixStore<N>` `getSolution(Access2D.Collectable<N,? super PhysicalStore<N>> rhs)`
[A][X]=[B] or [this][return]=[rhs]
`MatrixStore<N>` ```getSolution(Access2D.Collectable<N,? super PhysicalStore<N>> rhs, PhysicalStore<N> preallocated)```
Implementiong this method is optional.
`ComplexNumber` `getTrace()`
A matrix' trace is the sum of the diagonal elements.
`MatrixStore<N>` `getV()`
The columns of [V] represent the eigenvectors of [A] in the sense that [A][V] = [V][D].
`MatrixStore<N>` `invert(Access2D<?> original)`
The output must be a "right inverse" and a "generalised inverse".
`MatrixStore<N>` ```invert(Access2D<?> original, PhysicalStore<N> preallocated)```
Exactly how (if at all) a specific implementation makes use of `preallocated` is not specified by this interface.
`protected boolean` `isAspectRatioNormal()`
`boolean` `isComputed()`
`boolean` `isHermitian()`
If [A] is hermitian then [V][D][V]-1 becomes [Q][D][Q]H...
`boolean` `isOrdered()`
The eigenvalues in D (and the eigenvectors in V) are not necessarily ordered.
`boolean` `isSolvable()`
`protected BasicArray<N>` `makeArray(int length)`
`protected MatrixStore<N>` `makeD()`
`protected Array1D<ComplexNumber>` `makeEigenvalues()`
`protected DecompositionStore<N>` ```makeEye(int numberOfRows, int numberOfColumns)```
`protected Householder<N>` `makeHouseholder(int dimension)`
`protected MatrixStore.LogicalBuilder<N>` `makeIdentity(int dimension)`
`protected Rotation<N>` ```makeRotation(int low, int high, double cos, double sin)```
`protected Rotation<N>` ```makeRotation(int low, int high, N cos, N sin)```
`protected MatrixStore<N>` `makeV()`
`protected DecompositionStore<N>` ```makeZero(int numberOfRows, int numberOfColumns)```
`PhysicalStore<N>` `preallocate(Structure2D template)`
Will create a PhysicalStore instance suitable for use with `InverterTask.invert(Access2D, PhysicalStore)`.
`PhysicalStore<N>` ```preallocate(Structure2D templateBody, Structure2D templateRHS)```
`void` `reset()`
Delete computed results, and resets attributes to default values
`protected Scalar.Factory<N>` `scalar()`
`MatrixStore<N>` ```solve(Access2D<?> body, Access2D<?> rhs)```
[A][X]=[B] or [body][return]=[rhs]
`MatrixStore<N>` ```solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<N> preallocated)```
Exactly how (if at all) a specific implementation makes use of `preallocated` is not specified by this interface.
`protected MatrixStore.LogicalBuilder<N>` `wrap(Access2D<?> source)`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Methods inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver

`compute`
• ### Methods inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition

`decompose, isComputed, reconstruct`
• ### Methods inherited from interface org.ojalgo.matrix.decomposition.Eigenvalue

`copyEigenvector, equals, getEigenpair, getEigenvector, getEigenvectors, make, make, reconstruct, reconstruct`
• ### Constructor Detail

• #### HermitianEvD

```protected HermitianEvD(PhysicalStore.Factory<N,? extends DecompositionStore<N>> aFactory,
org.ojalgo.matrix.decomposition.TridiagonalDecomposition<N> tridiagonal)```
• ### Method Detail

• #### getDeterminant

`public final N getDeterminant()`
Description copied from interface: `MatrixDecomposition.Determinant`

A matrix' determinant is the product of its eigenvalues.

Specified by:
`getDeterminant` in interface `MatrixDecomposition.Determinant<N extends Number>`
Returns:
The matrix' determinant
• #### getEigenvalues

```public void getEigenvalues(double[] realParts,
Optional<double[]> imaginaryParts)```
Specified by:
`getEigenvalues` in interface `Eigenvalue<N extends Number>`
Parameters:
`realParts` - An array that will receive the real parts of the eigenvalues
`imaginaryParts` - An optional array that, if present, will receive the imaginary parts of the eigenvalues
• #### getInverse

`public final MatrixStore<N> getInverse()`
Description copied from interface: `MatrixDecomposition.Solver`
The output must be a "right inverse" and a "generalised inverse".
Specified by:
`getInverse` in interface `MatrixDecomposition.Solver<N extends Number>`
`BasicMatrix.invert()`
• #### getInverse

`public final MatrixStore<N> getInverse(PhysicalStore<N> preallocated)`
Description copied from interface: `MatrixDecomposition.Solver`

Implementiong this method is optional.

Exactly how a specific implementation makes use of `preallocated` is not specified by this interface. It must be documented for each implementation.

Should produce the same results as calling `MatrixDecomposition.Solver.getInverse()`.

Specified by:
`getInverse` in interface `MatrixDecomposition.Solver<N extends Number>`
Parameters:
`preallocated` - Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/final/correct solution.
Returns:
The inverse, this is where you get the solution
• #### getSolution

`public final MatrixStore<N> getSolution(Access2D.Collectable<N,? super PhysicalStore<N>> rhs)`
Description copied from interface: `MatrixDecomposition.Solver`
[A][X]=[B] or [this][return]=[rhs]
Specified by:
`getSolution` in interface `MatrixDecomposition.Solver<N extends Number>`
• #### getSolution

```public final MatrixStore<N> getSolution(Access2D.Collectable<N,? super PhysicalStore<N>> rhs,
PhysicalStore<N> preallocated)```
Description copied from interface: `MatrixDecomposition.Solver`

Implementiong this method is optional.

Exactly how a specific implementation makes use of `preallocated` is not specified by this interface. It must be documented for each implementation.

Should produce the same results as calling `#getSolution(Collectable)`.

Specified by:
`getSolution` in interface `MatrixDecomposition.Solver<N extends Number>`
Parameters:
`rhs` - The Right Hand Side, wont be modfied
`preallocated` - Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/final/correct solution.
Returns:
The solution
• #### getTrace

`public final ComplexNumber getTrace()`
Description copied from interface: `Eigenvalue`
A matrix' trace is the sum of the diagonal elements. It is also the sum of the eigenvalues. This method should return the sum of the eigenvalues.
Specified by:
`getTrace` in interface `Eigenvalue<N extends Number>`
Returns:
The matrix' trace
• #### invert

```public final MatrixStore<N> invert(Access2D<?> original)
Description copied from interface: `InverterTask`
The output must be a "right inverse" and a "generalised inverse".
Specified by:
`invert` in interface `InverterTask<N extends Number>`
Throws:
`TaskException`
`BasicMatrix.invert()`
• #### invert

```public final MatrixStore<N> invert(Access2D<?> original,
PhysicalStore<N> preallocated)
Description copied from interface: `InverterTask`

Exactly how (if at all) a specific implementation makes use of `preallocated` is not specified by this interface. It must be documented for each implementation.

Should produce the same results as calling `InverterTask.invert(Access2D)`.

Use `InverterTask.preallocate(Structure2D)` to obtain a suitbale `preallocated`.

Specified by:
`invert` in interface `InverterTask<N extends Number>`
`preallocated` - Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/final/correct solution.
Returns:
The inverse
Throws:
`TaskException`
• #### isHermitian

`public final boolean isHermitian()`
Description copied from interface: `Eigenvalue`
If [A] is hermitian then [V][D][V]-1 becomes [Q][D][Q]H...
Specified by:
`isHermitian` in interface `Eigenvalue<N extends Number>`
• #### isOrdered

`public boolean isOrdered()`
Description copied from interface: `Eigenvalue`
The eigenvalues in D (and the eigenvectors in V) are not necessarily ordered. This is a property of the algorithm/implementation, not the data.
Specified by:
`isOrdered` in interface `Eigenvalue<N extends Number>`
Specified by:
`isOrdered` in interface `MatrixDecomposition.Values<N extends Number>`
Returns:
true if they are ordered
• #### isSolvable

`public final boolean isSolvable()`
Specified by:
`isSolvable` in interface `MatrixDecomposition.Solver<N extends Number>`
Returns:
true if it is ok to call #getSolution(Collectable) (computation was successful); false if not
`#getSolution(Collectable)`, `MatrixDecomposition.isComputed()`
• #### preallocate

`public PhysicalStore<N> preallocate(Structure2D template)`
Description copied from interface: `InverterTask`

Will create a PhysicalStore instance suitable for use with `InverterTask.invert(Access2D, PhysicalStore)`.

When inverting a matrix (mxn) the preallocated memory/matrix will typically be nxm (and of course most of the time A is square).

Specified by:
`preallocate` in interface `InverterTask<N extends Number>`
• #### preallocate

```public PhysicalStore<N> preallocate(Structure2D templateBody,
Structure2D templateRHS)```
Description copied from interface: `SolverTask`

Will create a PhysicalStore instance suitable for use with `SolverTask.solve(Access2D, Access2D, PhysicalStore)`. The dimensions of the returned instance is not specified by this interface - it is specified by the behaviour/requirements of each implementation.

When solving an equation system [A][X]=[B] ([mxn][nxb]=[mxb]) the preallocated memory/matrix will typically be either mxb or nxb.

Specified by:
`preallocate` in interface `SolverTask<N extends Number>`
• #### reset

`public void reset()`
Description copied from interface: `MatrixDecomposition`
Delete computed results, and resets attributes to default values
Specified by:
`reset` in interface `MatrixDecomposition<N extends Number>`
• #### solve

```public MatrixStore<N> solve(Access2D<?> body,
Access2D<?> rhs)
Description copied from interface: `SolverTask`
[A][X]=[B] or [body][return]=[rhs]
Specified by:
`solve` in interface `SolverTask<N extends Number>`
Throws:
`TaskException`
• #### solve

```public MatrixStore<N> solve(Access2D<?> body,
Access2D<?> rhs,
PhysicalStore<N> preallocated)
Description copied from interface: `SolverTask`

Exactly how (if at all) a specific implementation makes use of `preallocated` is not specified by this interface. It must be documented for each implementation.

Should produce the same results as calling `SolverTask.solve(Access2D, Access2D)`.

Use `SolverTask.preallocate(Structure2D, Structure2D)` to obtain a suitbale `preallocated`.

Specified by:
`solve` in interface `SolverTask<N extends Number>`
`rhs` - The Right Hand Side, wont be modfied
`preallocated` - Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/final/correct solution.
Returns:
The solution
Throws:
`TaskException`
• #### doGeneral

```protected final boolean doGeneral(Access2D.Collectable<N,? super PhysicalStore<N>> matrix,
boolean eigenvaluesOnly)```
• #### doHermitian

```protected final boolean doHermitian(Access2D.Collectable<N,? super PhysicalStore<N>> matrix,
boolean valuesOnly)```
• #### makeD

`protected MatrixStore<N> makeD()`
• #### makeEigenvalues

`protected Array1D<ComplexNumber> makeEigenvalues()`
• #### makeV

`protected MatrixStore<N> makeV()`
• #### calculateDeterminant

`public N calculateDeterminant(Access2D<?> matrix)`
Specified by:
`calculateDeterminant` in interface `DeterminantTask<N extends Number>`
• #### checkAndCompute

`public final boolean checkAndCompute(MatrixStore<N> matrix)`
Description copied from interface: `MatrixDecomposition.Hermitian`
Absolutely must check if the matrix is hermitian or not. Then, depending on the result differents paths can be chosen - compute or not / choose different algorithms...
Specified by:
`checkAndCompute` in interface `MatrixDecomposition.Hermitian<N extends Number>`
Parameters:
`matrix` - A matrix to check and then (maybe) decompose
Returns:
true if the hermitian check passed and computation suceeded; false if not
• #### computeValuesOnly

`public boolean computeValuesOnly(Access2D.Collectable<N,? super PhysicalStore<N>> matrix)`
Specified by:
`computeValuesOnly` in interface `MatrixDecomposition.Values<N extends Number>`
Parameters:
`matrix` - The matrix to decompose
Returns:
The same as `Solver#compute(Collectable)` or `#decompose(Collectable)` if the instance does not implement `MatrixDecomposition.Solver`.
• #### decompose

`public final boolean decompose(Access2D.Collectable<N,? super PhysicalStore<N>> matrix)`
Specified by:
`decompose` in interface `MatrixDecomposition<N extends Number>`
Parameters:
`matrix` - A matrix to decompose
Returns:
true if the computation suceeded; false if not
• #### getD

`public final MatrixStore<N> getD()`
Description copied from interface: `Eigenvalue`
The only requirements on [D] are that it should contain the eigenvalues and that [A][V] = [V][D]. The ordering of the eigenvalues is not specified.
• If [A] is real and symmetric then [D] is (purely) diagonal with real eigenvalues.
• If [A] is real but not symmetric then [D] is block-diagonal with real eigenvalues in 1-by-1 blocks and complex eigenvalues in 2-by-2 blocks.
• If [A] is complex then [D] is (purely) diagonal with complex eigenvalues.
Specified by:
`getD` in interface `Eigenvalue<N extends Number>`
Returns:
The (block) diagonal eigenvalue matrix.
• #### getEigenvalues

`public final Array1D<ComplexNumber> getEigenvalues()`
Description copied from interface: `Eigenvalue`

Even for real matrices the eigenvalues (and eigenvectors) are potentially complex numbers. Typically they need to be expressed as complex numbers when [A] is not symmetric.

Prior to v41 this array should always be ordered in descending order - largest (modulus) first. As of v41 the values should be in the same order as the matrices "V" and "D", and if that is ordered or not is indicated by the `Eigenvalue.isOrdered()` method.

Specified by:
`getEigenvalues` in interface `Eigenvalue<N extends Number>`
Returns:
The eigenvalues.
• #### getV

`public final MatrixStore<N> getV()`
Description copied from interface: `Eigenvalue`
The columns of [V] represent the eigenvectors of [A] in the sense that [A][V] = [V][D].
Specified by:
`getV` in interface `Eigenvalue<N extends Number>`
Returns:
The eigenvector matrix.
• #### aggregator

`protected final AggregatorSet<N> aggregator()`
• #### allocate

```protected final DecompositionStore<N> allocate(long numberOfRows,
long numberOfColumns)```
• #### collect

`protected final MatrixStore<N> collect(Access2D.Collectable<N,? super DecompositionStore<N>> source)`
• #### copy

`protected final DecompositionStore<N> copy(Access2D<?> source)`
• #### function

`protected final FunctionSet<N> function()`
• #### makeArray

`protected final BasicArray<N> makeArray(int length)`
• #### makeEye

```protected final DecompositionStore<N> makeEye(int numberOfRows,
int numberOfColumns)```
• #### makeHouseholder

`protected final Householder<N> makeHouseholder(int dimension)`
• #### makeIdentity

`protected final MatrixStore.LogicalBuilder<N> makeIdentity(int dimension)`
• #### makeRotation

```protected final Rotation<N> makeRotation(int low,
int high,
double cos,
double sin)```
• #### makeRotation

```protected final Rotation<N> makeRotation(int low,
int high,
N cos,
N sin)```
• #### makeZero

```protected final DecompositionStore<N> makeZero(int numberOfRows,
int numberOfColumns)```
• #### scalar

`protected final Scalar.Factory<N> scalar()`
• #### wrap

`protected final MatrixStore.LogicalBuilder<N> wrap(Access2D<?> source)`
• #### isComputed

`public final boolean isComputed()`
Specified by:
`isComputed` in interface `MatrixDecomposition<N extends Number>`
Returns:
true if computation has been attemped; false if not.
`#decompose(Access2D.Collectable>)`
`protected final boolean aspectRatioNormal(boolean aspectRatioNormal)`
`protected final boolean computed(boolean computed)`
`protected final boolean isAspectRatioNormal()`