Last active
May 2, 2022 15:18
-
-
Save lccalluchi/2cefe498ad627e1f3801ad0e1e258e1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const data = [ | |
| { x: 4.75, y: 4 }, | |
| { x: 4.5, y: 3 }, | |
| { x: 5, y: 5 }, | |
| { x: 4.25, y: 2 }, | |
| { x: 4, y: 1 }, | |
| ]; | |
| function main() { | |
| let xy = 0; | |
| let sumX = 0; | |
| let sumY = 0; | |
| let x2 = 0; | |
| let y2 = 0; | |
| const size = data.length; // 5 | |
| data.map(({ x, y }) => { | |
| xy += x * y; | |
| sumX += x; | |
| sumY += y; | |
| x2 += x ** 2; | |
| y2 += y ** 2; | |
| }); | |
| console.log(xy); // 70 | |
| console.log(sumX); // 22.5 | |
| console.log(sumY); // 15 | |
| const sumXY = (sumX * sumY) / size; | |
| console.log(sumXY); // 67.5 | |
| // Valores para x | |
| console.log(x2); // 101.875 | |
| const sumXn = sumX ** 2 / size; | |
| console.log(sumXn); // 101.25 | |
| const resultx = Math.sqrt(x2 - sumXn); | |
| console.log(resultx); // 0.7905694150420949 | |
| // Valores para y | |
| console.log(y2); // 55 | |
| const sumYn = sumY ** 2 / size; | |
| console.log(sumYn); // 45 | |
| const resulty = Math.sqrt(y2 - sumYn); | |
| console.log(resulty); // 3.1622776 | |
| const r_sup = xy - (sumX * sumY) / size; | |
| console.log(r_sup); // 2.5 | |
| const r = r_sup / (resulty * resultx); | |
| console.log(r); // 0.999 | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment