This repository has been archived on 2022-10-20. You can view files and clone it, but cannot push or open issues or pull requests.
Math/vector.ts

30 lines
592 B
TypeScript

import { GaussianElimination, Matrix, RawMatrix } from "./matrix";
export class Vector extends Matrix {
constructor(...coords: number[]) {
let rm: RawMatrix = coords.map(c => [c]);
super(...rm);
}
coords() {
return this.matrix.map(row => row[0]);
}
}
export class LinearIndependence {
vectors: Vector[];
constructor(...v: Vector[]) {
this.vectors = v;
}
check(): [boolean, (number[] | Matrix)] {
let rows = this.vectors.map(v => [...v.coords(), 0]);
let result = GaussianElimination.solve(new Matrix(...rows));
return [!(result instanceof Matrix), result];
}
}