summaryrefslogtreecommitdiff
path: root/A_First_Course_In_Probability_by_Sheldon_Ross/CH6
diff options
context:
space:
mode:
authorPrashant S2019-10-04 12:27:32 +0530
committerGitHub2019-10-04 12:27:32 +0530
commitac2986488a9731cff5cbb517d8f0ef98e2561d64 (patch)
tree7bb3f64824627ef179d5f341266a664fd0b69011 /A_First_Course_In_Probability_by_Sheldon_Ross/CH6
parentcbb2770fb2f88246175add29623103a56ba338b8 (diff)
parentb3f3a8ecd454359a2e992161844f2fb599f8238a (diff)
downloadR_TBC_Uploads-master.tar.gz
R_TBC_Uploads-master.tar.bz2
R_TBC_Uploads-master.zip
Merge pull request #1 from prashantsinalkar/masterHEADmaster
Added R TBC
Diffstat (limited to 'A_First_Course_In_Probability_by_Sheldon_Ross/CH6')
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.a/Ex6_1a.R18
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.b/Ex6_1b.R18
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.a/Ex6_1ca.R16
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.b/Ex6_1cb.R19
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX2.c/Ex6_2c.R16
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.a/Ex6_3ca.R16
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.b/Ex6_3cb.R17
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.a/Ex6_3da.R6
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.b/Ex6_3db.R9
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX4.a/Ex6_4a.R18
-rw-r--r--A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX6.b/Ex6_6b.R10
11 files changed, 163 insertions, 0 deletions
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.a/Ex6_1a.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.a/Ex6_1a.R
new file mode 100644
index 00000000..f5146f3a
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.a/Ex6_1a.R
@@ -0,0 +1,18 @@
+#install.packages("MASS")
+require("MASS")
+
+P_XY = function(x, y){
+ blue = 5
+ red = 3
+ white = 4
+ lot_size = 3
+ ans = choose(blue-x-y, lot_size-x-y) * choose(red, x) * choose(white, y) / choose(blue+white+red, lot_size)
+}
+
+lot_size = 3
+for(i in 0:lot_size){
+ for(j in 0:(lot_size - i)){
+ cat("p(", i,",",j,") =")
+ print(fractions(P_XY(i,j)))
+ }
+} \ No newline at end of file
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.b/Ex6_1b.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.b/Ex6_1b.R
new file mode 100644
index 00000000..97959fbe
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.b/Ex6_1b.R
@@ -0,0 +1,18 @@
+P = c(.15, .2, .35, .3)
+
+P_BG <- function(i, j){
+ if((i + j) >=4){
+ return(0)
+ }else{
+ ans = P[(i + j) + 1] * ((factorial(i + j)/(factorial(i) * factorial(j)))/2^(i + j))
+ return(ans)
+ }
+}
+
+max_children = 3
+for(i in 0:max_children){
+ for(j in 0:max_children){
+ cat("p(", i,",",j,") =", P_BG(i,j), "\n")
+ }
+}
+
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.a/Ex6_1ca.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.a/Ex6_1ca.R
new file mode 100644
index 00000000..d63e193b
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.a/Ex6_1ca.R
@@ -0,0 +1,16 @@
+myfun = function(x,y) (2*exp(-x)*exp(-2*y))
+llimx = 1
+ulimx = Inf
+
+llimy = 0
+ulimy = 1
+
+f = function(){
+ return(integrate(function(y) {
+ sapply(y, function(y) {
+ integrate(function(x) myfun(x,y), llimx, ulimx)$value
+ })
+ }, llimy, ulimy))
+}
+ans = f()$value
+print(ans) \ No newline at end of file
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.b/Ex6_1cb.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.b/Ex6_1cb.R
new file mode 100644
index 00000000..72aeb831
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX1.c.b/Ex6_1cb.R
@@ -0,0 +1,19 @@
+#install.packages("MASS")
+require("MASS")
+
+myfun <- function(x,y) (2*exp(-x)*exp(-2*y))
+llimx <- 0
+
+llimy <- 0
+ulimy <- Inf
+
+f <- function(){
+ return(integrate(function(y) {
+ sapply(y, function(y) {
+ integrate(function(x) myfun(x,y), llimx, y)$value
+ })
+ }, llimy, ulimy))
+}
+ans = f()$value
+
+print(fractions(ans)) \ No newline at end of file
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX2.c/Ex6_2c.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX2.c/Ex6_2c.R
new file mode 100644
index 00000000..f7b06cc6
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX2.c/Ex6_2c.R
@@ -0,0 +1,16 @@
+#install.packages('pracma')
+#install.packages('MASS')
+require('pracma')
+require(MASS)
+
+integrand = function(x, y){
+ 1/60^2
+}
+
+xm = function(y){
+ y - 10
+}
+
+ans = 2*integral2(integrand, xmin = 10, xmax = 60, ymin = 0, ymax = xm )$Q
+
+print(fractions(ans)) \ No newline at end of file
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.a/Ex6_3ca.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.a/Ex6_3ca.R
new file mode 100644
index 00000000..da3c82bc
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.a/Ex6_3ca.R
@@ -0,0 +1,16 @@
+#note E_Xab denotes E(Xa + Xb)
+na = 26
+pa = 0.4
+E_Xa = na*pa
+Var_Xa = na*pa*(1-pa)
+
+nb = 18
+pb = 0.7
+E_Xb = nb*pb
+Var_Xb = nb*pb*(1-pb)
+
+E_Xab = E_Xa + E_Xb
+Var_Xab = Var_Xa + Var_Xb
+
+ans = 1 - pnorm(25 - 1/2, E_Xab, sqrt(Var_Xab))
+print(ans) \ No newline at end of file
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.b/Ex6_3cb.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.b/Ex6_3cb.R
new file mode 100644
index 00000000..9944cb12
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.c.b/Ex6_3cb.R
@@ -0,0 +1,17 @@
+#note E_Xab denotes E(Xa - Xb)
+na = 26
+pa = 0.4
+E_Xa = na*pa
+Var_Xa = na*pa*(1-pa)
+
+nb = 18
+pb = 0.7
+E_Xb = nb*pb
+Var_Xb = nb*pb*(1-pb)
+
+E_Xab = E_Xa - E_Xb
+Var_Xab = Var_Xa + Var_Xb
+
+ans = 1 - pnorm(1 - 1/2, E_Xab, sqrt(Var_Xab))
+print(ans)
+
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.a/Ex6_3da.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.a/Ex6_3da.R
new file mode 100644
index 00000000..113ec124
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.a/Ex6_3da.R
@@ -0,0 +1,6 @@
+mu = 0.0165
+sigma = 0.0730
+
+p = 1 - pnorm(0, mu, sigma)
+ans = p^2
+print(ans) \ No newline at end of file
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.b/Ex6_3db.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.b/Ex6_3db.R
new file mode 100644
index 00000000..fb8b9b16
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX3.d.b/Ex6_3db.R
@@ -0,0 +1,9 @@
+mu = 0.0165
+sigma = 0.0730
+
+mu = mu*2
+sigma = sqrt(2 * sigma^2)
+
+ans = 1 - pnorm(0, mu, sigma)
+
+print(ans) \ No newline at end of file
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX4.a/Ex6_4a.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX4.a/Ex6_4a.R
new file mode 100644
index 00000000..6cf8fe78
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX4.a/Ex6_4a.R
@@ -0,0 +1,18 @@
+#install.packages("MASS")
+require("MASS")
+#note pxi denotes Px(i)
+
+p00 = 0.4
+p01 = 0.2
+p10 = 0.1
+p11 = 0.3
+
+py1 = p01 + p11
+
+px0 = p01/py1
+
+px1 = p11/py1
+
+print(fractions(px0))
+
+print(fractions(px1))
diff --git a/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX6.b/Ex6_6b.R b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX6.b/Ex6_6b.R
new file mode 100644
index 00000000..d9e60c97
--- /dev/null
+++ b/A_First_Course_In_Probability_by_Sheldon_Ross/CH6/EX6.b/Ex6_6b.R
@@ -0,0 +1,10 @@
+#install.packages("MASS")
+require("MASS")
+
+integrand = function(x){
+ x*(1-x)
+}
+
+ans = factorial(3)/factorial(1)^2 * integrate(integrand, lower = 1/4, upper = 3/4)$value
+
+print(fractions(ans)) \ No newline at end of file