summaryrefslogtreecommitdiff
path: root/3808/CH7
diff options
context:
space:
mode:
authorprashantsinalkar2017-10-10 12:27:19 +0530
committerprashantsinalkar2017-10-10 12:27:19 +0530
commit7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch)
treedbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /3808/CH7
parentb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff)
downloadScilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip
initial commit / add all books
Diffstat (limited to '3808/CH7')
-rw-r--r--3808/CH7/EX7.1/Ex7_1.sce12
-rw-r--r--3808/CH7/EX7.10/Ex7_10.sce18
-rw-r--r--3808/CH7/EX7.11/Ex7_11.sce23
-rw-r--r--3808/CH7/EX7.12/Ex7_12.sce14
-rw-r--r--3808/CH7/EX7.13/Ex7_13.sce18
-rw-r--r--3808/CH7/EX7.14/Ex7_14.sce22
-rw-r--r--3808/CH7/EX7.2/Ex7_2.sce15
-rw-r--r--3808/CH7/EX7.3/Ex7_3.sce21
-rw-r--r--3808/CH7/EX7.4/Ex7_4.sce28
-rw-r--r--3808/CH7/EX7.5/Ex7_5.sce22
-rw-r--r--3808/CH7/EX7.6/Ex7_6.sce10
-rw-r--r--3808/CH7/EX7.7/Ex7_7.sce16
-rw-r--r--3808/CH7/EX7.8/Ex7_8.sce34
-rw-r--r--3808/CH7/EX7.9/Ex7_9.sce30
14 files changed, 283 insertions, 0 deletions
diff --git a/3808/CH7/EX7.1/Ex7_1.sce b/3808/CH7/EX7.1/Ex7_1.sce
new file mode 100644
index 000000000..20dae4c82
--- /dev/null
+++ b/3808/CH7/EX7.1/Ex7_1.sce
@@ -0,0 +1,12 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+no_blue=4 //no of blue balls
+no_red=5 //no of red balls
+
+prob_blue=no_blue/(no_red+no_blue)
+
+disp('The probability that a ball chosen at random will be blue is:')
+disp(prob_blue)
diff --git a/3808/CH7/EX7.10/Ex7_10.sce b/3808/CH7/EX7.10/Ex7_10.sce
new file mode 100644
index 000000000..696b872c8
--- /dev/null
+++ b/3808/CH7/EX7.10/Ex7_10.sce
@@ -0,0 +1,18 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+s_total_msg=2000 //spam messages total
+spam_msg=250 //occurrence of 'Rolex' in spam
+nspam_msg=5 //occurrence of 'Rolex' in not know to be spam
+ns_total_msg=1000//not spam messages total
+threshold=0.9
+p=spam_msg/s_total_msg
+q=nspam_msg/ns_total_msg
+r=p/(p+q)
+
+if r>threshold then
+ disp(r,'R=')
+ disp('Reject')
+end
diff --git a/3808/CH7/EX7.11/Ex7_11.sce b/3808/CH7/EX7.11/Ex7_11.sce
new file mode 100644
index 000000000..025b4134f
--- /dev/null
+++ b/3808/CH7/EX7.11/Ex7_11.sce
@@ -0,0 +1,23 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+spam_msg=2000 //no of spam messages
+nspam_msg=1000 //no of messages that are not spam
+o_msg_spam=400 //occurrence of stock in spam
+o_msg_nspam=60 //occurrence of stock in non spam
+o_msg1_spam=200 //occurrence of undervalued in spam
+o_msg1_nspam=25 //occurrence of undervalued in non spam
+threshold=0.9
+p1=o_msg_spam/spam_msg
+q1=o_msg_nspam/nspam_msg
+p2=o_msg1_spam/spam_msg
+q2=o_msg1_nspam/nspam_msg
+
+r=(p1*p2)/(p1*p2+q1*q2)
+
+if r>threshold then
+ disp(r,'R=')
+ disp('Reject')
+end
diff --git a/3808/CH7/EX7.12/Ex7_12.sce b/3808/CH7/EX7.12/Ex7_12.sce
new file mode 100644
index 000000000..6668d90df
--- /dev/null
+++ b/3808/CH7/EX7.12/Ex7_12.sce
@@ -0,0 +1,14 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+X=[1,2,3,4,5,6] //possible values on a fair die
+p=1/6 //probability for any value to appear when die is rolled
+Ex=0
+l=length(X)
+for i=1:l
+ Ex=Ex+p*X(i)
+end
+
+disp(Ex,'Expected value of X')
diff --git a/3808/CH7/EX7.13/Ex7_13.sce b/3808/CH7/EX7.13/Ex7_13.sce
new file mode 100644
index 000000000..53c63bf99
--- /dev/null
+++ b/3808/CH7/EX7.13/Ex7_13.sce
@@ -0,0 +1,18 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+times=8 //time flipped
+o1=3 //occurrence of 3 heads
+o2=2 //occurrence of 2 heads
+o3=2 //occurrence of 2 heads
+o4=2 //occurrence of 2 heads
+o5=1 //occurrence of 1 head
+o6=1 //occurrence of 1 head
+o7=1 //occurrence of 1 head
+o8=0 //occurrence of 0 heads
+peo=1/times //probability of each outcome
+Ex=peo*(o1+o2+o3+o4+o5+o6+o7+o8)
+
+disp(Ex,'Expected heads when fair coin is flipped 3 times')
diff --git a/3808/CH7/EX7.14/Ex7_14.sce b/3808/CH7/EX7.14/Ex7_14.sce
new file mode 100644
index 000000000..bdd04fa52
--- /dev/null
+++ b/3808/CH7/EX7.14/Ex7_14.sce
@@ -0,0 +1,22 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+tot_out=36 //total no of outcomes when 2 dice are rolled
+X=[2,3,4,5,6,7,8,9,10,11,12] //possible sum of 2 dice
+pX2=1/tot_out //no of possible chances
+pX12=pX2 //no of possible chances
+pX3=2/tot_out //no of possible chances
+pX11=pX3 //no of possible chances
+pX4=3/tot_out //no of possible chances
+pX10=pX4 //no of possible chances
+pX5=4/tot_out //no of possible chances
+pX9=pX5 //no of possible chances
+pX6=5/tot_out //no of possible chances
+pX8=pX6 //no of possible chances
+pX7=6/tot_out //no of possible chances
+
+Ex=X(1)*pX2+X(2)*pX3+X(3)*pX4+X(4)*pX5+X(5)*pX6+X(6)*pX7+X(7)*pX8+X(8)*pX9+X(9)*pX10+X(10)*pX11+X(11)*pX12
+
+disp(Ex,'Ex=')
diff --git a/3808/CH7/EX7.2/Ex7_2.sce b/3808/CH7/EX7.2/Ex7_2.sce
new file mode 100644
index 000000000..75436d2f3
--- /dev/null
+++ b/3808/CH7/EX7.2/Ex7_2.sce
@@ -0,0 +1,15 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+//For sum to be 7 out of the total 36 equally likely possible outcomes there are 6 outcomes
+//(1,6) (2,5) (3,4) (4,3) (5,2) (6,1)
+
+total_outcomes=36 //total no of outcomes
+seven_sum_outcome=6 //no of outcomes where sum of numbers appearing on dice is 7
+
+prob_seven=seven_sum_outcome/total_outcomes
+
+disp('Probability that 7 comes when 2 dice are rolled is')
+disp(prob_seven)
diff --git a/3808/CH7/EX7.3/Ex7_3.sce b/3808/CH7/EX7.3/Ex7_3.sce
new file mode 100644
index 000000000..c8b0603b0
--- /dev/null
+++ b/3808/CH7/EX7.3/Ex7_3.sce
@@ -0,0 +1,21 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+//Part a
+no_four_digits=10**4 //no of ways to choose 4 digits by the product rule
+
+//since only 1 entry is correct and wins the prize ,it is inferred that there is only 1 possible way to choose all the digits correctly
+no_correctentry=1 //no of ways to choose all 4 digits correctly
+prob_winning=no_correctentry/no_four_digits //probability of player winning the large prize
+
+disp(,prob_winning,'Probability that a player wins the large prize is')
+
+//Part b
+//to win small prize player must correctly choose exactly 3 of 4 digits
+
+no_correctentry=36 //no of ways to choose 4 digits with exactly three of the four being correct
+prob_winning=no_correctentry/no_four_digits //probability of player winning small prize
+
+disp(,prob_winning,'Probability that a player wins the small prize is')
diff --git a/3808/CH7/EX7.4/Ex7_4.sce b/3808/CH7/EX7.4/Ex7_4.sce
new file mode 100644
index 000000000..455dfafc5
--- /dev/null
+++ b/3808/CH7/EX7.4/Ex7_4.sce
@@ -0,0 +1,28 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+function result=combination(n,r) //function definition
+i=n
+num=1
+denominator=1
+l=(n-r)+1
+u=n
+for i=l:u //to compute the value of the numerator
+num=num*i
+end
+for j=1:r //to compute the value of the denominator
+denominator=denominator*j
+end
+result=num/denominator
+return result
+endfunction
+
+n1=input('Enter the total numbers: ')
+n2=input('Enter the amount of numbers to pick correctly to win the prize:')
+win=combination(n1,n2)
+p_win=1/win
+mprintf('The total no of ways to choose %d numbers out of %d number is: %d',n1,n2,win)
+mprintf('\nThe probability of a winning combination is')
+disp(p_win)
diff --git a/3808/CH7/EX7.5/Ex7_5.sce b/3808/CH7/EX7.5/Ex7_5.sce
new file mode 100644
index 000000000..0e73ebb24
--- /dev/null
+++ b/3808/CH7/EX7.5/Ex7_5.sce
@@ -0,0 +1,22 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+total_balls=50 //total no of balls in bin
+pr=1
+//Part-(A) Sampling without replacement
+given_no=5 //11 4 17 39 23
+select_ways=1 //ways in which that particular order can be drawn
+n=total_balls-given_no
+for i=total_balls:-1:n+1
+pr=pr*i
+end
+prob=select_ways/pr
+disp(prob,'The probability that 11,4,17,39,23 are drawn in that order is')
+
+//Part-(B) Sampling with replacement
+total_ways=total_balls**given_no //5 is the no.of balls ,i.e, 11 4 17 39 23
+select_ways=1 //numbers are drawn in that order
+prob=select_ways/total_ways
+disp(prob,'The probability that 11,4,17,39,23 are drawn in that order is')
diff --git a/3808/CH7/EX7.6/Ex7_6.sce b/3808/CH7/EX7.6/Ex7_6.sce
new file mode 100644
index 000000000..d2294942e
--- /dev/null
+++ b/3808/CH7/EX7.6/Ex7_6.sce
@@ -0,0 +1,10 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+s=2**10 //no of bits-0,1 power sequence ie 10
+eb=1 //for bits are 1
+pEb=eb/s //probability of event E bar that all the bits are 1
+pE=1-pEb //probability of event E
+disp(pE,'The probability that the bit string will contain at least one 0 bit is')
diff --git a/3808/CH7/EX7.7/Ex7_7.sce b/3808/CH7/EX7.7/Ex7_7.sce
new file mode 100644
index 000000000..6d26984d1
--- /dev/null
+++ b/3808/CH7/EX7.7/Ex7_7.sce
@@ -0,0 +1,16 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+max_integers=100
+E1=100/2 //event that random integer is divisible by 2
+E2=100/5 //event that random integer is divisible by 5
+E1IE2=100/(5*2) //event that random integer is divisible by 5 and 2
+pE1=E1/max_integers //probability of event E1
+pE2=E2/max_integers //probability of event E2
+pE1IE2=E1IE2/max_integers //probability of event E1IE2
+
+pE1UE2=pE1+pE2-pE1IE2
+
+disp(pE1UE2,'Probability that random integer is divisible by either 2 or 5 is')
diff --git a/3808/CH7/EX7.8/Ex7_8.sce b/3808/CH7/EX7.8/Ex7_8.sce
new file mode 100644
index 000000000..583f32afd
--- /dev/null
+++ b/3808/CH7/EX7.8/Ex7_8.sce
@@ -0,0 +1,34 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+times=7 //no of times flipped
+total_outcomes=2**times //outcomes power times flipped
+
+function result=combination(n,r) //function definition
+i=n
+num=1
+denominator=1
+l=(n-r)+1
+u=n
+for i=l:u //to compute the value of the numerator
+num=num*i
+end
+for j=1:r //to compute the value of the denominator
+denominator=denominator*j
+end
+result=num/denominator
+return result
+endfunction
+
+reqd_heads=4 //no of heads coming up
+ways_heads=combination(times,reqd_heads)
+pH=2/3 //biased coin with probability of heads for 1 head
+pT=1-pH //probability of tails is total probability-heads probability
+rpH=pH**reqd_heads //probability of 4 heads outcome
+rpT=pT**(times-reqd_heads) //probability of tails outcome
+
+prob_four_heads=ways_heads*rpH*rpT //probability of exactly four heads appearing
+
+disp(prob_four_heads,'The probability of exactly four heads appearing is')
diff --git a/3808/CH7/EX7.9/Ex7_9.sce b/3808/CH7/EX7.9/Ex7_9.sce
new file mode 100644
index 000000000..8d98ca511
--- /dev/null
+++ b/3808/CH7/EX7.9/Ex7_9.sce
@@ -0,0 +1,30 @@
+//Chapter 07: Discrete Probability
+
+clc;
+clear;
+
+p0=0.9 //prob of bit 0 generation
+p1=1-p0 //prob of bit 1 generation
+total_bits=10 //total bits generated
+reqd_bits=8 //reqd bits out of totalbits generated
+
+function result=combination(n,r) //function definition
+i=n
+num=1
+denominator=1
+l=(n-r)+1
+u=n
+for i=l:u //to compute the value of the numerator
+num=num*i
+end
+for j=1:r //to compute the value of the denominator
+denominator=denominator*j
+end
+result=num/denominator
+return result
+endfunction
+
+//Using theorem 2
+prob_eight_0=combination(total_bits,reqd_bits)*((p0)**reqd_bits)*((p1)**(total_bits-reqd_bits))
+
+disp(prob_eight_0,'Probability of exactly eight 0 bits generated is')