UNPKG

gauss-algorithm

Version:

The implementation of the Gauss Algorithm

82 lines (77 loc) 2.42 kB
module.exports = class { /* data must be a 2 dimensional array [ [x11,x12,x13,b1], [x21,x22,x23,b2], [x31,x32,x33,b3] ] */ // input & input validation constructor (data = []) { let ok = true if (!Array.isArray(data)) { ok = false } if (ok) { for (let i = 0; i < data.length; i++) { if (!Array.isArray(data[i])) { ok = false } else { if (data[i].length != data.length +1) { ok = false } for (let j = 0; j < data[i].length; j++) { if (typeof data[i][j] != "number") { ok = false } } } } } if (ok) { this.data = data this.valid = true } else { this.valid = false } } get getAll() { return this } get getData() { return this.data } get out() { let tmp = this.data let out = [] let outone = 0 for (let i = 0; i < tmp.length; i++) { for (let j = 0; j < tmp.length; j++) { if (j != outone) { console.log("Processed Index " + i + " at " + j + ". " + JSON.stringify(tmp[j]) + " minus " + outone + ". " + JSON.stringify(tmp[outone])) tmp[j] = this.process( tmp[j], tmp[outone], i ) console.log("to " + JSON.stringify(tmp[j]) + "\n") } } outone++; } for (let i = 0; i < tmp.length; i++) { out[i] = tmp[i][tmp[i].length-1]/tmp[i][i] } return out } // process gauß with lane1 minus lane2 at index each starting a 0 // the index is that number given, that will turn 0 process(lane1,lane2,index) { let tmp = [[],[]] let out = [] for (let i = 0; i < lane1.length; i++) { tmp[0][i] = lane1[i]*lane2[index] tmp[1][i] = lane2[i]*lane1[index] } for (let i = 0; i < tmp[0].length; i++) { out[i] = tmp[0][i] - tmp[1][i] } return out } }