Added invertible matrix method
This commit is contained in:
parent
fb615bd304
commit
96dd404e7d
21
matrix.ts
21
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Reference in a new issue