#Answer 1b
#(make sure that what you print make sense to me) - for example to print mean you can use cat command once you done with the calculation and have value in the variable
#variable_name=10
#cat("Mean number of correctly received bits ", variable_name)
cat("21.6 bits, 1.469694")
21.6 bits, 1.469694
#Answer 1c
cat("0.000002")
0.000002
#Answer 1d
qbinom(0.5, 24, 0.9)
[1] 22
cat("My interpretation is that most correctly received bits are greater than the mean which turns out to be a good stat")
My interpretation is that most correctly received bits are greater than the mean which turns out to be a good stat
#Answer 1e
qbinom(0.6, 24, 0.9)
[1] 22
#Interpretation
cat("My interpretation is that the standard deviation of this plot is very small")
My interpretation is that the standard deviation of this plot is very small
#Answer 2a
dpois(20,20)
[1] 0.08883532
dpois(30,20)
[1] 0.008343536
#Answer 2b
dpois(24,20)
[1] 0.05573456
#Answer 2c
dpois(100,85)
[1] 0.01139877
#Answer 3a
list1
list2
list3
list4
a=5
b=10
for(i in 1:1000)
{
Zi=(9*a+1)
list1[[i]]<-Zi
Zi=Zi%%16
list2[[i]]<-Zi
a=Zi
}
for(i in 1:1000){
Zj=(7*b+3)
list3[[i]]<-Zj
Zj=Zj%%32
list4[[i]]<-Zj
b=Zj
}
list2
list4
cat("A: repeats after 16 numbers,repeat after number 5")
cat("B: repeats after 8 numbers,repeat after number 9")
#Answer 3b
cat("Answer", "a&b")
Answer a&b
#Answer 3c
plot(list1, list2,xlab="Zi-1",ylab="Zi",main="A")
plot(list3, list4,xlab="Zi-1",ylab="Zi",main="B")
#Interpretation
cat("B looks like a random plot, while A has some patterns")
B looks like a random plot, while A has some patterns
#Answer
x<- runif(100, min = 0, max = 100)
plot(x)
#Interpretation
cat("This is the expected random plot")
This is the expected random plot
#Answer
result.mean <- mean(x)
print(result.mean)
[1] 48.79799
#Answer
data_numericA <- as.numeric(list1)
data_numericA <- as.numeric(list2)
hist((data_numericA ),main="A")
data_numericB <- as.numeric(list3)
data_numericB <- as.numeric(list4)
hist((data_numericB ),main="B")
\[ F(x) = 1 - e^{-(x/\lambda)^k} \]
where \(x \geq 0\), \(\lambda \geq 0\), and \(k \geq 0\).
# Answer 4a
# This might be hard to print using R - you can write the step in your notebook and then include image here / or you can include as seperate file when upload
# Check if the IRdisplay package is already installed
if (!require(IRdisplay, quietly = TRUE)) {
# If not installed, install it
install.packages("IRdisplay")
# Load the IRdisplay library
library(IRdisplay)
} else {
# If already installed, just load the library
library(IRdisplay)
}
inv_cdf <- function(p, lambda, k) {
-lambda * (-log(1 - p))^(1/k)
}
lambda <- 2
k <- 3
n <- 1000
u <- runif(n)
x <- inv_cdf(u, lambda, k)
hist(x, freq = FALSE, main = "Samples from F(x) = 1 - e^(-(x/λ)^k)")
x1=(9*9+1)%%16
y1=1-exp(-(x1)^5)
y1
[1] 1
x2=(9*2+1)%%16
y2=1-exp(-(x2)^5)
y2
[1] 1
x3=(9*17+1)%%16
y3=1-exp(-(x3)^5)
y3
[1] 1
x<-runif(10000,1,100)
x
[1] 16.651170 44.555308 12.560189 34.282678 23.847852 1.909252
[7] 32.877368 13.258988 71.746955 88.435077 82.327946 55.934792
[13] 88.596962 54.123742 26.066292 1.405242 15.400750 98.903118
[19] 52.357834 69.876363 53.489288 87.333186 88.340780 13.999425
[25] 94.894903 57.451603 57.389503 79.784688 61.083383 1.356082
[31] 99.157514 59.121026 76.070537 75.911501 63.152452 14.132020
[37] 1.697750 66.745211 95.158604 12.271875 76.162317 91.555243
[43] 71.220269 62.335100 28.882777 6.960404 75.091184 46.896636
[49] 8.980166 20.907636 16.487077 40.583670 84.968143 52.053662
[55] 89.181305 58.718505 32.139176 47.958023 34.170926 25.884272
[61] 64.315364 56.403861 14.388689 96.311821 97.732626 16.412974
[67] 79.015220 49.907139 11.192021 37.412016 16.729764 49.065987
[73] 29.800946 20.791564 42.179699 8.536451 33.548651 17.246265
[79] 72.801710 39.548690 78.585461 8.595254 57.330954 64.037168
[85] 78.207448 16.133443 52.743688 90.222662 21.029184 12.069280
[91] 98.196670 39.050724 75.920996 28.364888 66.494927 23.953383
[97] 29.614746 16.039375 96.310716 67.806233 73.601715 56.575656
[103] 68.440687 54.715653 66.968493 42.680211 11.990402 88.762605
[109] 34.549602 25.406408 15.717800 39.884065 20.236574 37.411734
[115] 41.681167 86.321181 87.641318 75.000894 48.630011 21.718733
[121] 1.899234 70.556780 5.670777 9.780060 85.293755 63.435675
[127] 88.974951 78.795144 92.629775 62.878634 59.346039 25.366368
[133] 35.716957 45.346801 65.119348 4.382032 85.335859 26.016682
[139] 87.240927 43.385248 93.952476 59.764617 8.047372 45.711577
[145] 26.972814 48.567917 32.688147 13.772885 72.819930 77.215630
[151] 91.043098 17.296716 47.737563 44.359531 66.497930 40.765627
[157] 87.832609 2.800940 73.474666 77.213519 49.966942 14.495489
[163] 66.463558 46.413386 18.375089 72.986068 37.417283 96.485089
[169] 31.750543 73.111035 3.022212 86.142586 31.227812 83.045403
[175] 7.114900 32.800643 95.216366 5.221096 86.931948 38.529480
[181] 48.960934 86.515778 62.511328 76.543490 44.481099 34.715624
[187] 33.638536 52.579766 36.252987 97.225473 71.833129 34.230252
[193] 11.127943 94.716851 85.582033 45.234689 32.283384 23.548035
[199] 16.847874 68.117492 16.462373 61.485959 5.696016 69.440543
[205] 25.778697 88.280218 18.747066 69.276792 14.479325 56.684861
[211] 43.711985 85.906954 1.123961 76.235669 93.503155 61.635491
[217] 11.358478 44.935419 35.309509 90.314312 34.769630 46.014306
[223] 61.780244 85.070799 28.056368 8.569041 20.505370 75.212738
[229] 99.410876 96.512141 92.664228 96.091645 11.471958 81.026947
[235] 26.587173 81.855927 32.343581 78.944977 67.628165 22.361247
[241] 94.663952 28.938340 63.919594 98.271797 70.479838 84.402942
[247] 23.144222 73.610483 24.434780 77.017075 63.533750 84.562525
[253] 68.127259 66.105966 44.743823 17.850870 39.755018 79.084113
[259] 43.664381 27.297376 13.411759 80.803412 9.775581 18.998336
[265] 42.526320 57.344020 19.919347 60.139225 93.991892 1.024526
[271] 25.858181 65.499108 69.819921 8.211191 19.040186 46.200241
[277] 6.749668 31.832129 86.840107 3.409108 66.337876 32.816108
[283] 98.478224 12.372048 82.035370 79.064501 68.098815 35.957191
[289] 64.853673 96.319437 8.286372 35.798600 32.069604 78.997175
[295] 68.618814 94.318949 77.494108 18.152361 86.256498 21.297249
[301] 25.946351 2.152096 43.336462 34.976737 96.140261 38.895757
[307] 94.780263 24.078767 65.255850 19.826433 48.052907 18.190892
[313] 34.802815 46.620408 68.799672 94.032172 96.341838 72.036512
[319] 23.239663 24.963206 37.980474 73.726542 4.052958 4.485692
[325] 10.235711 37.152048 48.060508 50.252548 82.312056 13.106665
[331] 27.468957 29.518585 72.583506 47.982278 50.256472 65.375928
[337] 21.129430 76.535486 41.060157 33.810876 18.552579 75.884171
[343] 47.117327 28.156506 14.585346 17.947437 3.578132 34.706159
[349] 74.766975 40.496556 71.378450 89.210017 70.112978 10.896408
[355] 18.400471 76.484249 29.170770 11.144333 70.957917 89.501354
[361] 81.844549 8.925756 25.495224 44.520607 58.734646 34.180724
[367] 38.377685 89.515905 70.238281 44.544595 40.916386 56.447145
[373] 54.233136 59.966088 87.680460 97.551965 31.736155 21.166552
[379] 83.921012 9.461486 28.074652 6.855793 17.381637 80.391804
[385] 48.295978 90.468772 39.689135 85.215948 69.196657 24.399325
[391] 88.671936 75.507280 78.035178 1.068629 46.921069 9.638562
[397] 19.229919 19.949557 70.099551 91.593209 84.000043 3.492986
[403] 6.723234 83.075180 56.163082 89.814324 46.845515 96.468092
[409] 14.339110 47.945597 44.553315 16.711232 49.713484 98.732297
[415] 88.119422 67.702440 10.474471 21.356467 9.510431 19.164045
[421] 7.502082 92.430756 17.546698 93.514188 85.312637 28.398461
[427] 92.686581 81.626057 52.006198 70.393229 67.062559 84.163916
[433] 42.209152 45.219851 58.878587 75.459341 59.392543 69.557559
[439] 33.933035 61.738611 58.393486 74.464455 95.008707 38.676984
[445] 90.454511 8.330656 92.058694 76.418690 29.387544 48.915534
[451] 12.658056 34.711847 46.391404 18.308936 85.939978 84.855909
[457] 3.203107 90.180926 22.089989 40.357641 95.663292 89.658276
[463] 2.961080 45.675174 66.817461 25.839414 52.140023 71.523162
[469] 41.330134 89.360354 68.495011 29.611979 56.302230 66.017816
[475] 23.737266 93.764347 10.163593 20.395635 8.880855 22.723842
[481] 87.158930 67.616896 20.994148 12.060229 83.388418 14.009504
[487] 16.621997 31.094341 91.182842 17.200084 57.637551 69.310700
[493] 77.360235 18.643859 82.930833 36.534548 68.249718 38.146032
[499] 28.452168 29.708376 65.821278 90.934640 36.166998 80.499998
[505] 94.203788 74.003152 26.461130 21.505519 11.015966 63.191336
[511] 70.538425 85.126915 47.502139 74.205270 73.314367 73.198144
[517] 44.889163 62.890096 41.700348 22.915605 60.143943 23.140918
[523] 57.566368 23.723466 6.927942 13.578771 57.292957 7.069615
[529] 78.779652 76.903370 59.042888 43.165172 91.786360 14.929287
[535] 54.020269 4.888122 38.089787 81.982375 81.862019 22.944031
[541] 42.285666 80.400317 84.067035 80.348682 93.577099 94.908350
[547] 4.494479 49.447893 5.493222 81.474131 65.693294 52.971417
[553] 40.703232 24.593863 13.752978 8.013040 72.326473 20.063450
[559] 95.664750 28.469644 62.679103 70.634004 3.550946 85.821858
[565] 6.242199 9.059334 65.345433 77.498340 31.006956 80.732474
[571] 23.863676 62.585348 37.138602 98.282150 96.432330 48.117381
[577] 17.824481 16.038512 67.138310 25.250408 48.834578 57.530042
[583] 58.299304 98.350320 99.996612 21.421220 31.893711 10.895110
[589] 87.991383 23.088639 72.090237 16.094530 49.238195 15.219979
[595] 40.810698 84.053744 53.630570 78.920101 88.759275 87.213092
[601] 96.692572 68.279119 18.086243 27.093987 2.845238 95.417353
[607] 79.919442 26.282552 76.320885 72.992196 12.268418 22.349704
[613] 74.677868 10.221014 3.462612 29.562079 82.116802 82.306001
[619] 73.233232 27.510157 54.444226 77.310180 43.200960 98.901094
[625] 51.501367 91.710419 43.370147 60.651455 36.973419 14.960610
[631] 32.103146 27.464435 2.658389 17.542968 15.368306 98.270331
[637] 2.259887 74.222992 69.052170 68.849210 12.076626 81.663010
[643] 40.778966 65.841067 35.384578 74.606187 71.251397 81.026621
[649] 37.918440 48.599626 10.057348 73.881770 87.836816 35.732480
[655] 42.087890 4.282262 3.251085 38.143055 66.971911 50.413534
[661] 94.154899 68.330345 33.017428 79.999478 68.366369 78.112039
[667] 45.461608 12.791553 26.591909 96.574893 31.901247 67.372578
[673] 15.923039 25.868336 45.202074 22.123641 5.988484 31.028406
[679] 70.844742 55.739407 5.890240 60.746937 38.493009 11.429988
[685] 35.222422 38.914613 79.869805 2.538051 36.550461 53.464362
[691] 91.708567 41.231209 1.052093 65.321453 49.563170 64.335175
[697] 8.943412 31.597235 85.718404 68.392024 51.693211 46.551429
[703] 57.793458 50.080185 45.679290 3.229742 69.713647 80.868720
[709] 42.695537 77.372885 12.469461 67.482050 27.933040 44.395626
[715] 14.246962 44.631888 71.414481 10.002232 71.811249 42.874109
[721] 42.070862 22.316238 64.736727 3.570052 20.743397 23.097604
[727] 89.470090 10.489672 8.761272 59.652669 75.271334 11.027685
[733] 21.753465 65.381060 14.459407 40.730893 31.290501 3.914221
[739] 99.145186 1.496602 10.471208 77.834286 91.281607 44.302191
[745] 43.526059 17.204737 68.337419 11.496040 31.295542 41.260295
[751] 28.327225 82.963676 87.299517 57.826094 69.096061 95.692329
[757] 56.762199 58.313461 2.990982 24.739693 44.413464 70.621626
[763] 8.205932 83.755834 97.019863 77.495117 19.883914 28.145638
[769] 17.584911 28.998934 22.906088 36.333134 89.099444 93.337013
[775] 32.164833 37.549688 43.062830 27.637431 28.502909 62.906432
[781] 14.990759 39.180902 84.051453 79.997338 10.675774 36.422103
[787] 22.868576 45.352549 29.911934 94.690561 12.515601 53.197604
[793] 46.374224 73.867946 4.557897 87.548328 59.928004 32.355596
[799] 53.373280 96.395169 42.646847 76.070942 91.685243 42.874515
[805] 43.534613 47.148885 52.675039 34.476537 1.748954 81.854591
[811] 19.632928 62.432407 4.322467 9.101566 44.326882 82.621004
[817] 31.561343 36.369000 95.775604 39.494704 66.343316 64.821606
[823] 54.896488 98.054706 34.341730 42.447079 48.622356 32.756726
[829] 10.914420 9.409510 41.626765 65.902156 93.268408 10.147520
[835] 20.485179 22.720522 35.146623 89.893179 8.557519 52.918707
[841] 71.484389 58.400971 61.359014 53.469347 19.401950 87.853722
[847] 3.454685 38.817184 2.859792 14.503004 53.176536 69.952192
[853] 29.420649 8.166089 6.906143 31.199126 2.413997 4.653110
[859] 86.385938 66.913199 55.062366 68.548504 47.267395 22.622996
[865] 39.605629 38.120636 99.447009 93.699016 20.496503 28.731978
[871] 26.665242 93.956841 21.129574 67.660930 86.508185 50.787216
[877] 9.373165 49.475206 1.923531 79.346812 70.916178 6.717896
[883] 27.800870 92.193571 27.314913 74.314413 47.746388 96.695019
[889] 43.238626 33.604382 37.805297 26.308695 27.376292 86.463284
[895] 72.403460 15.178269 82.996646 51.707200 78.325017 45.955802
[901] 94.364352 10.283448 34.532712 1.767897 52.095462 22.058534
[907] 37.555136 10.211166 25.973028 74.850756 83.765260 7.506673
[913] 12.608979 92.128764 89.439133 37.850735 65.460586 2.183347
[919] 14.528207 93.242389 29.462592 15.111672 9.407938 30.343671
[925] 77.909813 6.977422 95.970028 18.210542 68.581242 94.351559
[931] 74.323012 48.445554 59.702666 15.124276 93.694963 52.454601
[937] 67.628274 73.769995 36.384607 78.919954 15.853827 90.562567
[943] 44.352475 27.148740 43.048077 64.699752 88.250214 93.995996
[949] 15.399794 81.345901 25.129650 96.571208 29.800410 18.612200
[955] 49.692577 10.228725 32.097880 52.965460 32.646649 80.186199
[961] 2.766235 58.556631 9.320723 50.439565 18.334285 51.749844
[967] 79.134543 30.412597 72.561261 68.125809 66.567921 98.331435
[973] 29.383654 67.177434 45.583888 79.940617 98.524309 35.999252
[979] 8.956733 56.812706 87.716141 44.068928 94.898152 94.751318
[985] 80.696605 36.995478 31.759743 34.221060 27.808944 74.404397
[991] 63.290867 38.825544 72.519998 48.190076 73.484597 86.971763
[997] 69.408285 37.696102 67.325015 55.658467
[ reached getOption("max.print") -- omitted 9000 entries ]
y = 1 - exp(-(x/1)^5)
plot(y, frame = FALSE, col = "blue",main = "Density plot")
"The plot generated here is sparse and center on the top"
[1] "The plot generated here is sparse and center on the top"
n <- 10000
count <- 0
s <- 0
for (i in 1:n) {
x <- runif(1)
s <- s + x
if (s > 1) {
count <- count + 1
s <- 0
}
}
mean_count <- count / n
print(mean_count)
[1] 0.3683
cat("No matter how many times I run the code, this number is around 0.36")
No matter how many times I run the code, this number is around 0.36
cat("The random value generated each time is different which makes the result different")
The random value generated each time is different which makes the result different