Guest User

Untitled

a guest
May 27th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Muestreo_Aleatorio
  8. {
  9. class Estratificado
  10. {
  11. #region Valores
  12. private double[,] _estratos;
  13. public double[,] estratos { set { _estratos = value; } get { return _estratos; } }
  14. private double _N;
  15. public double N { set { _N = value; } get { return _N; } }
  16. private double _n;
  17. public double n { set { _n = value; } get { return _n; } }
  18. private double[] _Ns;
  19. public double[] Ns { set { _Ns = value; } get { return _Ns; } }
  20. private double[] _ns;
  21. public double[] ns { set { _ns = value; } get { return _ns; } }
  22. private int _total;
  23. public int total { set { _total = value; } get { return _total; } }
  24. private double _Z;
  25. public double Z
  26. {
  27. set { _Z = value; }
  28. get
  29. {
  30. return _Z;
  31. }
  32. }
  33. private double _pres;
  34. public double pres { set { _pres = value; } get { return _pres; } }
  35. #endregion
  36. public Estratificado(double[,] estratos, double N, double n, double[] Ns, double[] ns, int total, double Z, double pres)
  37. {
  38. this.estratos = estratos;
  39. this.N = N;
  40. this.n = n;
  41. this.Ns = Ns;
  42. this.ns = ns;
  43. this.total = total;
  44. this.Z = Z;
  45. this.pres = pres;
  46. }
  47. int ele = 0;
  48. double[] ys = new double[10];
  49. double whSh = 0;
  50. double[] Sn = new double[10];
  51. double yestrN = 0;
  52. double syestrN = 0;
  53. double tgorritop = 0;
  54. double nyN = 0;
  55. double nTn = 0;
  56. public double yestr()
  57. {
  58. double resultado = 0;
  59. //Sumar los elementos del estrato y guardarlos en un vector
  60. for (int i = 0; i < total; i++)
  61. {
  62. ele = 0;
  63. while (estratos[i, ele] != 0 && (ele < 20))
  64. {
  65. ys[i] = estratos[i, ele] + ys[i];
  66. ele++;
  67. }
  68. }
  69. //Sacar los promedios por estrato y guardarlos en el mismo vector
  70. for (int i = 0; i < total; i++)
  71. {
  72. ys[i] = ys[i] / ns[i];
  73. //Realizar la parte de arriba (N1*y1+...)
  74. resultado = resultado + (ys[i] * Ns[i]);
  75. }
  76. resultado = resultado / N;
  77. yestrN = resultado;
  78. resultado = Math.Round(resultado, 4);
  79. return resultado;
  80. }
  81. public double tgorritoestr()
  82. {
  83. double res = N * yestrN;
  84. tgorritop = res;
  85. res = Math.Round(res, 4);
  86. return res;
  87. }
  88. public double Syestr()
  89. {
  90. double res = 0;
  91.  
  92. //Sacar la sumatoria de los elementos por estrato al cuadrado
  93. for (int i = 0; i < total; i++)
  94. {
  95. ele = 0;
  96. while (estratos[i, ele] != 0 && (ele < 20))
  97. {
  98. Sn[i] = Math.Pow(estratos[i, ele], 2) + Sn[i];
  99. ele++;
  100. }
  101. }
  102. for (int i = 0; i < total; i++)
  103. {
  104. double ys2 = Math.Pow(ys[i], 2);
  105. double numerador = 0;
  106. double desRest = ns[i] * ys2;
  107. //Sacar la varianza de cada estrato
  108. numerador = Sn[i] - desRest;
  109. Sn[i] = numerador / (ns[i] - 1);
  110. //Sacar la varianza total
  111. res = ((Math.Pow((Ns[i] / N), 2)) * ((Ns[i] - ns[i]) / Ns[i]) * (Sn[i] / ns[i])) + res;
  112. }
  113. res = Math.Sqrt(res);
  114. syestrN = res;
  115. res = Math.Round(res, 4);
  116. return res;
  117. }
  118. public string intervaloYestr()
  119. {
  120. string inter = "";
  121. double a = 0, b = 0;
  122. a = yestrN - (Z * syestrN);
  123. a = Math.Round(a, 4);
  124. b = yestrN + (Z * syestrN);
  125. b = Math.Round(b, 4);
  126. inter = a.ToString() + " <Mestr< " + b.ToString();
  127. return inter;
  128. }
  129. public string intervaloTgorro()
  130. {
  131. string inter = "";
  132. double a = 0, b = 0;
  133. a =tgorritop - (N * (Z * syestrN));
  134. a = Math.Round(a, 4);
  135. b = tgorritop + (N * (Z * syestrN));
  136. b = Math.Round(b, 4);
  137. inter = a.ToString() + " <T< " + b.ToString();
  138. return inter;
  139. }
  140. public double ny()
  141. {
  142. double res = 0;
  143. double d = yestrN * pres;
  144. for (int i = 0; i < total; i++)
  145. {
  146. whSh = ((Ns[i] / N) * Sn[i]) + whSh;
  147. }
  148.  
  149. res = (N * (Math.Pow(Z, 2)) * whSh) / (N * (Math.Pow(d, 2)) + whSh);
  150. res = Math.Round(res, 0);
  151. return res;
  152. }
  153. public double nT()
  154. {
  155. double res = 0;
  156. double d = tgorritop * pres;
  157. res = ((Math.Pow(N, 2)) * (Math.Pow(Z, 2)) * whSh) / (((Math.Pow(d, 2))) + (N * (Math.Pow(Z, 2)) * whSh));
  158. res = Math.Round(res, 0);
  159. return res;
  160. }
  161. public double[] asignacionM()
  162. {
  163. nyN = ny();
  164. nTn = nT();
  165. double[] n = new double[2];
  166. for (int i = 0; i < total; i++)
  167. {
  168. n[0] = (Ns[i] / N) * nyN;
  169. n[1] = (Ns[i] / N) * nTn;
  170. }
  171. n[0] = Math.Round(n[0], 4);
  172. n[1] = Math.Round(n[1], 4);
  173. return n;
  174. }
  175. }
  176. }
Add Comment
Please, Sign In to add comment