Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.31 KB | None | 0 0
  1. %% Ex.01
  2. clear all; close all; clc; rng('default');
  3.  
  4. N = 9999;
  5. MEAN10 = zeros(N,1);
  6. MEAN100 = zeros(N,1);
  7.  
  8. for i=1:N
  9.     MEAN10(i) = mean(sqrt(2) * randn(10,1) + 4);
  10.     MEAN100(i) = mean(sqrt(2) * randn(100,1) + 4);
  11. end
  12.  
  13. subplot(1,2,1); hist(MEAN10, 30);
  14. title('MEAN 10');
  15. subplot(1,2,2); hist(MEAN100, 30);
  16. title('MEAN 100');
  17.  
  18. %% Ex.02
  19. clear all; close all; clc;
  20.  
  21. N = 9999;
  22. chi = zeros(N,1);
  23. tStud = zeros(N,1);
  24.  
  25. for i=1:N
  26.     sample = sqrt(2) * randn(10,1) + 4;
  27.     MEAN = mean(sample);
  28.     s = 0;
  29.     for j = 1:10
  30.         s = s + (1/9)*((sample(j)-MEAN)^2);
  31.     end
  32.     chi(i) = (9*s)/2;
  33.     tStud(i) = ((MEAN - 4)/sqrt(s))*sqrt(9);
  34. end
  35.  
  36. x_axis_chi = 0:0.1:50;
  37. x_axis_t = -4:0.1:4;
  38. subplot(2,2,1); hist(chi, 50);
  39. subplot(2,2,2); plot(x_axis_chi,chi2pdf(x_axis_chi,9));
  40. subplot(2,2,3); hist(tStud, 50);
  41. subplot(2,2,4); plot(x_axis_t,tpdf(x_axis_t,9));
  42.  
  43. %% Ex.03
  44. close all; clear all; clc; rng('default');
  45.  
  46. X = sqrt(2)*randn(10,1) + 4;
  47.  
  48. % A
  49. sigma_A = sqrt(2);
  50. alfa_A = 0.05;
  51. mean_A = mean(X);
  52. n_A = length(X);
  53. norm_inv_A = norminv([alfa_A/2 1-(alfa_A/2)]);
  54. norm_range_A = mean_A + (norm_inv_A .* (sigma_A/sqrt(n_A)));
  55.  
  56. % B
  57. sigma_B = sqrt(2);
  58. alfa_B = 0.1;
  59. mean_B = mean(X);
  60. n_B = length(X);
  61. norm_inv_B = norminv([alfa_B/2 1-(alfa_B/2)]);
  62. norm_range_B = mean_B + (norm_inv_B .* (sigma_B/sqrt(n_B)));
  63.  
  64. % C
  65. sigma_C = std(X);
  66. alfa_C = 0.05;
  67. n_C = length(X);
  68. mean_C = mean(X);
  69. norm_inv_C = tinv([1-alfa_C/2 alfa_C/2], 9);
  70. norm_range_C = mean_C + (norm_inv_C .* (sigma_C/sqrt(n_C)));
  71. norm_range_C = sort(norm_range_C,'ascend');
  72. %% Ex.04
  73. clear all; close all; clc; rng('default');
  74.  
  75. X = sqrt(2)*randn(10,1) + 4;
  76. MEAN = mean(X);
  77. sigma = std(X);
  78. alfa = 0.05;
  79. freedom = length(X) - 1;
  80. chi2_range = chi2inv([1-(alfa/2) alfa/2], freedom);
  81. chi2_range = sqrt((freedom * sigma^2)./chi2_range);
  82.  
  83. %% Ex.05
  84. close all; clear all; clc;
  85.  
  86. X = [15.43, 16.92, 14.43, 12.94, 15.92, 17.42, 18.91, 16.92, 14.93, 14.49, 15.92, 15.43];
  87. X = sort(X, 'ascend');
  88. MEAN = mean(X); SIGMA = std(X);
  89. N = length(X);
  90.  
  91. SREDNI_PRZYROST = SIGMA/MEAN;
  92. ROZSTEP = max(X) - min(X);
  93. alfa = 0.05;
  94. norm_inv = norminv([alfa/2 1-(alfa/2)]);
  95. norm_range = MEAN + norm_inv.*SIGMA/sqrt(length(X));
  96.  
  97. M = 1000;
  98. values = zeros(M,1);
  99. for i=1:M
  100.     index = randi([1 12],1,1);
  101.     disp(index);
  102.     values(i) = X(index);
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement