Advertisement
Griwin

Задача ТУ

Oct 16th, 2023
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.91 KB | Software | 0 0
  1. // Defining arrays for the values
  2. const x = [128, 125, 122, 100, 109, 126, 124, 106, 131, 120, 103, 110, 130, 111, 102];
  3. const y = [59, 40, 38, 11, 56, 36, 47, 58, 60, 13, 20, 20, 45, 29, 49, 53, 37, 54, 35, 23];
  4. const z = [130, 118, 145, 157, 132, 124, 147, 149, 123, 148, 156, 159, 137, 158, 117];
  5.  
  6. // Calculating the mean
  7. let sum_x = 0, sum_y = 0, sum_z = 0;
  8. for (let i = 0; i < x.length; ++i) {
  9.     sum_x += x[i];
  10.     sum_y += y[i];
  11.     sum_z += z[i];
  12. }
  13. const mean_x = sum_x / x.length;
  14. const mean_y = sum_y / y.length;
  15. const mean_z = sum_z / z.length;
  16.  
  17. // Calculating the variance
  18. let variance_x = 0, variance_y = 0, variance_z = 0;
  19. for (let i = 0; i < x.length; ++i) {
  20.     variance_x += Math.pow(x[i] - mean_x, 2);
  21.     variance_y += Math.pow(y[i] - mean_y, 2);
  22.     variance_z += Math.pow(z[i] - mean_z, 2);
  23. }
  24. variance_x /= x.length - 1;
  25. variance_y /= y.length - 1;
  26. variance_z /= z.length - 1;
  27.  
  28. // Calculating the standard deviation
  29. const std_dev_x = Math.sqrt(variance_x);
  30. const std_dev_y = Math.sqrt(variance_y);
  31. const std_dev_z = Math.sqrt(variance_z);
  32.  
  33. // Calculating the correlation coefficients
  34. let sum_xy = 0, sum_xz = 0, sum_yz = 0;
  35. for (let i = 0; i < x.length; ++i) {
  36.     sum_xy += (x[i] - mean_x) * (y[i] - mean_y);
  37.     sum_xz += (x[i] - mean_x) * (z[i] - mean_z);
  38.     sum_yz += (y[i] - mean_y) * (z[i] - mean_z);
  39. }
  40. const correlation_coefficient_xy = sum_xy / (std_dev_x * std_dev_y * (x.length - 1));
  41. const correlation_coefficient_xz = sum_xz / (std_dev_x * std_dev_z * (x.length - 1));
  42. const correlation_coefficient_yz = sum_yz / (std_dev_y * std_dev_z * (x.length - 1));
  43.  
  44. // Printing the results
  45. console.log("Математическо очакване за x: " + mean_x);
  46. console.log("Математическо очакване за y: " + mean_y);
  47. console.log("Математическо очакване за z: " + mean_z);
  48. console.log("Дисперсия за x: " + variance_x);
  49. console.log("Дисперсия за y: " + variance_y);
  50. console.log("Дисперсия за z: " + variance_z);
  51. console.log("Средноквадратично отклонение за x: " + std_dev_x);
  52. console.log("Средноквадратично отклонение за y: " + std_dev_y);
  53. console.log("Средноквадратично отклонение за z: " + std_dev_z);
  54. console.log("Коефициент на корелация между x и y: " + correlation_coefficient_xy);
  55. console.log("Коефициент на корелация между x и z: " + correlation_coefficient_xz);
  56. console.log("Коефициент на корелация между y и z: " + correlation_coefficient_yz);
  57.  
  58. // Confidence intervals for the mean
  59. console.log("Доверителни интервали за математическото очакване:");
  60. console.log("x: [" + (mean_x - (1.76131 * std_dev_x / 2)) + ", " + (mean_x + (1.76131 * std_dev_x / 2)) + "]");
  61. console.log("y: [" + (mean_y - (1.729133 * std_dev_y / 2)) + ", " + (mean_y + (1.729133 * std_dev_y / 2)) + "]");
  62. console.log("z: [" + (mean_z - (1.76131 * std_dev_z / 2)) + ", " + (mean_z + (1.76131 * std_dev_z / 2)) + "]");
  63.  
  64. // Confidence intervals for the variance
  65. console.log("Доверителни интервали ДИСПЕРСИЯ:");
  66. console.log("x: [" + (variance_x * 3) / 9.348 + ", " + (variance_x * 3) / 0.2158 + "]");
  67. console.log("y: [" + (variance_y * 3) / 9.348 + ", " + (variance_y * 3) / 0.2158 + "]");
  68. console.log("z: [" + (variance_z * 3) / 9.348 + ", " + (variance_z * 3) / 0.2158 + "]");
  69.  
  70. // Confidence intervals for the mean changes
  71. console.log("Доверителни интервали ИЗМЕНЕНИЕ НА ВЕЛИЧИНАТА:");
  72. console.log("x: [" + (mean_x - 3 * std_dev_x) + ", " + (mean_x + 3 * std_dev_x) + "]");
  73. console.log("y: [" + (mean_y - 3 * std_dev_y) + ", " + (mean_y + 3 * std_dev_y) + "]");
  74. console.log("z: [" + (mean_z - 3 * std_dev_z) + ", " + (mean_z + 3 * std_dev_z) + "]");
  75.  
  76. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement