diff --git a/matrix.ts b/matrix.ts index cac67bb..ce1219b 100644 --- a/matrix.ts +++ b/matrix.ts @@ -80,8 +80,9 @@ export class Matrix { } pow(power: number) { - for(let i=0; i<(power-1); i++) - this.set(...this.mul(this).matrix); + if(power > 0) + for(let i=0; i<(power-1); i++) + this.set(...this.mul(this).matrix); return this; } @@ -159,6 +160,22 @@ export class Matrix { 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; + } + }