(data, deg)
| 287 | return this.polynomial(slope, intercept) |
| 288 | } |
| 289 | polyreg(data, deg) { |
| 290 | const x = Object.keys(data) |
| 291 | for (let i in x) { |
| 292 | x[i] = parseFloat(x[i]) |
| 293 | } |
| 294 | const y = Object.values(data) |
| 295 | for (let i in y) { |
| 296 | y[i] = parseFloat(y[i]) |
| 297 | } |
| 298 | const lhs = []; |
| 299 | const rhs = []; |
| 300 | let a = 0; |
| 301 | let b = 0; |
| 302 | let c; |
| 303 | let k; |
| 304 | |
| 305 | var i; |
| 306 | let j; |
| 307 | let l; |
| 308 | const len = x.length; |
| 309 | |
| 310 | let results; |
| 311 | let equation; |
| 312 | let string; |
| 313 | |
| 314 | if (typeof deg === 'undefined') { |
| 315 | k = 3; |
| 316 | } else { |
| 317 | k = deg + 1; |
| 318 | } |
| 319 | |
| 320 | for (i = 0; i < k; i++) { |
| 321 | for (l = 0; l < len; l++) { |
| 322 | if (y[l] !== null) { |
| 323 | a += x[l] ** i * y[l]; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | lhs.push(a); |
| 328 | a = 0; |
| 329 | |
| 330 | c = []; |
| 331 | for (j = 0; j < k; j++) { |
| 332 | for (l = 0; l < len; l++) { |
| 333 | if (y[l] !== null) { |
| 334 | b += x[l] ** (i + j); |
| 335 | } |
| 336 | } |
| 337 | c.push(b); |
| 338 | b = 0; |
| 339 | } |
| 340 | rhs.push(c); |
| 341 | } |
| 342 | rhs.push(lhs); |
| 343 | equation = this.gaussElimination(rhs, k); |
| 344 | |
| 345 | return this.polynomial(...equation.reverse()) |
| 346 | } |
no test coverage detected