Added invertible matrix method

This commit is contained in:
Filip Znachor 2022-10-20 17:35:21 +02:00
parent fb615bd304
commit 96dd404e7d

View file

@ -80,8 +80,9 @@ export class Matrix {
} }
pow(power: number) { pow(power: number) {
for(let i=0; i<(power-1); i++) if(power > 0)
this.set(...this.mul(this).matrix); for(let i=0; i<(power-1); i++)
this.set(...this.mul(this).matrix);
return this; return this;
} }
@ -159,6 +160,22 @@ export class Matrix {
m.splice(row, 1); this.set(...m); m.splice(row, 1); this.set(...m);
} }
invertible() {
let matrix = Matrix.zero(this.rows, this.cols*2);
this.matrix.forEach((row, i) => {
matrix.matrix[i][this.cols+i] = 1;
row.forEach((col, j) => {
matrix.matrix[i][j] = col;
});
});
let gje = GaussianElimination.gje(matrix).matrix.map(GaussianElimination.make_pivot_1);
let result = Matrix.zero(this.rows, this.cols);
result.set(...result.matrix.map((row, i) => {
return row.map((col, j) => gje[i][this.cols+j]);
}));
return result;
}
} }