You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
923 B
26 lines
923 B
import LuDecomposition from './dc/lu';
|
|
import QrDecomposition from './dc/qr';
|
|
import SingularValueDecomposition from './dc/svd';
|
|
import Matrix from './matrix';
|
|
import WrapperMatrix2D from './wrap/WrapperMatrix2D';
|
|
|
|
export function inverse(matrix, useSVD = false) {
|
|
matrix = WrapperMatrix2D.checkMatrix(matrix);
|
|
if (useSVD) {
|
|
return new SingularValueDecomposition(matrix).inverse();
|
|
} else {
|
|
return solve(matrix, Matrix.eye(matrix.rows));
|
|
}
|
|
}
|
|
|
|
export function solve(leftHandSide, rightHandSide, useSVD = false) {
|
|
leftHandSide = WrapperMatrix2D.checkMatrix(leftHandSide);
|
|
rightHandSide = WrapperMatrix2D.checkMatrix(rightHandSide);
|
|
if (useSVD) {
|
|
return new SingularValueDecomposition(leftHandSide).solve(rightHandSide);
|
|
} else {
|
|
return leftHandSide.isSquare()
|
|
? new LuDecomposition(leftHandSide).solve(rightHandSide)
|
|
: new QrDecomposition(leftHandSide).solve(rightHandSide);
|
|
}
|
|
}
|
|
|