Pydzik45

RStudio - Kostki

Nov 15th, 2020
681
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##################################################
  2. # Typ kodowania UTF8
  3. # Realizator: Kretek Kacper
  4. # Tytu: Symulacyjne badanie wielokrotnych sum wielko±ci losowych
  5. ##################################################
  6.  
  7. N=10000 # Ilosc rzutow
  8. N2=100000 # Ilsc rzutow
  9. K=1:6 # Definiujemy zwykla szescio scienna kostke
  10.  
  11. # Ad I.1
  12. rzut1=sample(K,N,replace=T)
  13. hist(rzut1,main = "rzut jedna kostka N", xlab="os X", ylab="os Y" )
  14.  
  15. # Ad I.2
  16. s2k=function(){sample(K,1)+sample(K,1)}
  17. rzut2=sapply(1:N, function(j){s2k()})
  18. hist(rzut2,main = "rzut dwoma kostkami N", xlab="os X", ylab="os Y")
  19.  
  20. # Ad I.3
  21. s3k=function(){sample(K,1)+sample(K,1)+sample(K,1)}
  22. rzut3=sapply(1:N, function(j){s3k()})
  23. hist(rzut3,main = "rzut trzema kostkami N", xlab="os X", ylab="os Y")
  24.  
  25. # Ad I.4
  26. s4k=function(){sample(K,1)+sample(K,1)+sample(K,1)+sample(K,1)}
  27. rzut4=sapply(1:N, function(j){s4k()})
  28. hist(rzut4,main = "rzut czterema kostkami N", xlab="os X", ylab="os Y")
  29.  
  30. # Ad I.5
  31. s5k=function(){sample(K,1)+sample(K,1)+sample(K,1)+sample(K,1)+sample(K,1)}
  32. rzut5=sapply(1:N, function(j){s5k()})
  33. hist(rzut5,main = "rzut piecioma kostkami N", xlab="os X", ylab="os Y")
  34.  
  35.  
  36. # Ad II
  37.  
  38. # 1Kostka
  39. rzut1=sample(K,N2,replace=T)
  40. hist(rzut1,main = "rzut jedna kostka N2", xlab="os X", ylab="os Y" )
  41.  
  42. # 2Kostka
  43. s2k=function(){sample(K,1)+sample(K,1)}
  44. rzut2=sapply(1:N2, function(j){s2k()})
  45. hist(rzut2,main = "rzut dwoma kostkami N2", xlab="os X", ylab="os Y")
  46.  
  47. # 3Kostka
  48. s3k=function(){sample(K,1)+sample(K,1)+sample(K,1)}
  49. rzut3=sapply(1:N2, function(j){s3k()})
  50. hist(rzut3,main = "rzut trzema kostkami N2", xlab="os X", ylab="os Y")
  51.  
  52. # 4Kostka
  53. s4k=function(){sample(K,1)+sample(K,1)+sample(K,1)+sample(K,1)}
  54. rzut4=sapply(1:N2, function(j){s4k()})
  55. hist(rzut4,main = "rzut czterema kostkami N2", xlab="os X", ylab="os Y")
  56.  
  57. # 5Kostka
  58. s5k=function(){sample(K,1)+sample(K,1)+sample(K,1)+sample(K,1)+sample(K,1)}
  59. rzut5=sapply(1:N2, function(j){s5k()})
  60. hist(rzut5,main = "rzut piecioma kostkami N2", xlab="os X", ylab="os Y")
  61.  
  62. # Ad III
  63. ZK=c(0,2,2,4,4,6) # Definiujemy zepsuta kostke
  64.  
  65. # 1Kostka
  66. rzut1=sample(ZK,N,replace=T)
  67. hist(rzut1,main = "rzut jedna kostka ZK", xlab="os X", ylab="os Y" )
  68.  
  69. # 2Kostka
  70. s2k=function(){sample(ZK,1)+sample(ZK,1)}
  71. rzut2=sapply(1:N, function(j){s2k()})
  72. hist(rzut2,main = "rzut dwoma kostkami ZK", xlab="os X", ylab="os Y")
  73.  
  74. # 3Kostka
  75. s3k=function(){sample(ZK,1)+sample(ZK,1)+sample(ZK,1)}
  76. rzut3=sapply(1:N, function(j){s3k()})
  77. hist(rzut3,main = "rzut trzema kostkami ZK", xlab="os X", ylab="os Y")
  78.  
  79. # 4Kostka
  80. s4k=function(){sample(ZK,1)+sample(ZK,1)+sample(ZK,1)+sample(ZK,1)}
  81. rzut4=sapply(1:N, function(j){s4k()})
  82. hist(rzut4,main = "rzut czterema kostkami ZK", xlab="os X", ylab="os Y")
  83.  
  84. # 5Kostka
  85. s5k=function(){sample(ZK,1)+sample(ZK,1)+sample(ZK,1)+sample(ZK,1)+sample(ZK,1)}
  86. rzut5=sapply(1:N, function(j){s5k()})
  87. hist(rzut5,main = "rzut piecioma kostkami ZK", xlab="os X", ylab="os Y")
  88.  
  89.  
  90. # 1Kostka
  91. rzut1=sample(ZK,N2,replace=T)
  92. hist(rzut1,main = "rzut jedna kostka ZK N2", xlab="os X", ylab="os Y" )
  93.  
  94. # 2Kostka
  95. s2k=function(){sample(ZK,1)+sample(ZK,1)}
  96. rzut2=sapply(1:N2, function(j){s2k()})
  97. hist(rzut2,main = "rzut dwoma kostkami ZK N2", xlab="os X", ylab="os Y")
  98.  
  99. # 3Kostka
  100. s3k=function(){sample(ZK,1)+sample(ZK,1)+sample(ZK,1)}
  101. rzut3=sapply(1:N2, function(j){s3k()})
  102. hist(rzut3,main = "rzut trzema kostkami ZK N2", xlab="os X", ylab="os Y")
  103.  
  104. # 4Kostka
  105. s4k=function(){sample(ZK,1)+sample(ZK,1)+sample(ZK,1)+sample(ZK,1)}
  106. rzut4=sapply(1:N2, function(j){s4k()})
  107. hist(rzut4,main = "rzut czterema kostkami ZK N2", xlab="os X", ylab="os Y")
  108.  
  109. # 5Kostka
  110. s5k=function(){sample(ZK,1)+sample(ZK,1)+sample(ZK,1)+sample(ZK,1)+sample(ZK,1)}
  111. rzut5=sapply(1:N2, function(j){s5k()})
  112. hist(rzut5,main = "rzut piecioma kostkami ZK N2", xlab="os X", ylab="os Y")
  113.  
  114.  
  115.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×