93 lines
1.4 KiB
TypeScript
93 lines
1.4 KiB
TypeScript
import { GaussianElimination, Matrix, TriangularForm } from "../matrix";
|
|
|
|
let A = new Matrix(
|
|
[1, 2, 3],
|
|
[4, 5, 6]
|
|
);
|
|
|
|
let B = new Matrix(
|
|
[1, 4],
|
|
[2, 5],
|
|
[3, 6]
|
|
);
|
|
|
|
let C = new Matrix(
|
|
[ 14, 32 ],
|
|
[ 32, 77 ]
|
|
);
|
|
|
|
test('Transpose (A, B)', () => {
|
|
expect(A.eq(B.transpose())).toBe(true);
|
|
});
|
|
|
|
test('Transpose (B, A)', () => {
|
|
expect(B.eq(A.transpose())).toBe(true);
|
|
});
|
|
|
|
test('Multiply (A, B, C)', () => {
|
|
expect(A.mul(B).eq(C)).toBe(true);
|
|
});
|
|
|
|
test('Multiply (B, A, C)', () => {
|
|
expect(B.mul(A).eq(C)).toBe(false);
|
|
});
|
|
|
|
let D = new GaussianElimination(
|
|
new Matrix(
|
|
[1, 2, -1, 1, 2],
|
|
[2, 5, 0, 1, 5],
|
|
[3, 7, -1, 3, 9],
|
|
[1, 3, 1, 1, 5]
|
|
)
|
|
);
|
|
|
|
let D_solved = new Matrix(
|
|
[1, 2, -1, 1, 2],
|
|
[0, 1, 2, -1, 1],
|
|
[0, 0, 0, 1, 2],
|
|
[0, 0, 0, 0, 0]
|
|
);
|
|
|
|
test('Gaussian elimination (D)', () => {
|
|
expect(D.solve().eq(D_solved)).toBe(true);
|
|
});
|
|
|
|
let E = new GaussianElimination(
|
|
new Matrix(
|
|
[1, 1, 3],
|
|
[2, -1, 4]
|
|
)
|
|
);
|
|
|
|
let E_solved = new Matrix(
|
|
[1, 1, 3],
|
|
[0, -3, -2]
|
|
);
|
|
|
|
test('Gaussian elimination (E)', () => {
|
|
expect(E.solve().eq(E_solved)).toBe(true);
|
|
});
|
|
|
|
let F = new Matrix(
|
|
[1, 1, 1],
|
|
[0, 2, 4],
|
|
[0, 0, 5],
|
|
);
|
|
|
|
let G = new Matrix(
|
|
[1, 0, 0],
|
|
[5, 2, 0],
|
|
[4, 8, 5],
|
|
);
|
|
|
|
test('Upper triangular matrix (F)', () => {
|
|
expect(F.is_triangular()).toBe(true);
|
|
});
|
|
|
|
test('Upper triangular matrix (A)', () => {
|
|
expect(A.is_triangular()).toBe(false);
|
|
});
|
|
|
|
test('Lower triangular matrix (G)', () => {
|
|
expect(G.is_triangular(TriangularForm.LOWER)).toBe(true);
|
|
}); |