Probability And Statistics For Engineers (3)
Scilab Textbook Companion for
Probability And Statistics For Engineers And
Scientists by S. M. Ross 1
Created by Deeksha Sinha Dual Degree Electrical Engineering IIT Bombay College Teacher None Cross-Checked by Mukul R. Kulkarni
August 10, 2013
1 Funded by a grant from the National Mission on Education through ICT, http:spoken-tutorial.orgNMEICT-Intro. This Textbook Companion and Scilab
codes written in it can be downloaded from the ”Textbook Companion Project” section at the website http:scilab.in
Book Description
Title: Probability And Statistics For Engineers And Scientists Author: S. M. Ross Publisher: Elsevier, New Delhi Edition: 3 Year: 2005 ISBN: 81-8147-730-8
Scilab numbering policy used in this document and the relation to the above book.
Exa Example (Solved example) Eqn Equation (Particular equation of the above book) AP Appendix to Example(Scilab Code that is an Appednix to a particular
Example of the above book) For example, Exa 3.51 means solved example 3.51 of this book. Sec 2.3 means
a scilab code whose theory is explained in Section 2.3 of the book.
Contents
List of Scilab Codes
2 Descriptive Statistics
3 Elements Of Probability
4 Random Variables And Expectation
5 Special Random Variables
6 Distribution of Sampling Statistics
7 Parameter Estimation
8 Hypothesis Testing
10 Analysis of Variance
11 Goodness of Fit Tests and Categorical Data Analysis
12 Non parametric Hypothesis Tests
13 Quality Control
14 Life Testing
List of Scilab Codes
Exa 2.2a Relative Frequency ....................
Exa 2.2b pie chart .........................
Exa 2.3a Sample mean .......................
Exa 2.3b Sample mean of age ...................
Exa 2.3c Sample Median ......................
Exa 2.3d Mean and Median ....................
Exa 2.3e Mean Median and Mode .................
Exa 2.3f sample variance .....................
Exa 2.3g sample variance of accidents ...............
Exa 2.3h Percentile .........................
Exa 2.3i Quartiles .........................
Exa 2.4a Chebyshev Inequality ..................
Exa 2.5a Empirical Rule ......................
Exa 2.6a Sample Correlation Coefficient .............
Exa 2.6b Sample Correlation Coefficient .............
Exa 3.4a Union ...........................
Exa 3.5a Basic Principle of Counting ...............
Exa 3.5b Basic Principle of Counting ...............
Exa 3.5c Basic Principle of Counting ...............
Exa 3.5d Committee Probability .................
Exa 3.5f Pairing Probability ....................
Exa 3.6a Acceptable Transistor ..................
Exa 3.6b Both Boys ........................
Exa 3.6c Branch Manager .....................
Exa 3.7a Accident Probability ...................
Exa 3.7b Accident within a year ..................
Exa 3.7c Multiple Choice Test ...................
Exa 3.7d blood test .........................
Exa 3.7e Criminal Investigation ..................
Exa 3.7f Missing Plane .......................
Exa 3.8a Independent Events ...................
Exa 4.1a sum of two fair dice ...................
Exa 4.1b Defective or Acceptable .................
Exa 4.1c
X exceeds 1 ........................
Exa 4.2a sum of pmf ........................
Exa 4.2b pdf ............................
Exa 4.3a Joint distribution of batteries ..............
Exa 4.3b Joint distribution of boys and girls ...........
Exa 4.3c Joint Density Function ..................
Exa 4.3e Density of Independent Random Variables .......
Exa 4.3f Conditional Probability Mass Function .........
Exa 4.3g Conditional Probability Mass Function .........
Exa 4.4a Expectation of a fair die .................
Exa 4.4d Expectation of the message time ............
Exa 4.5a Expectation ........................
Exa 4.5b Expected cost of breakdown ...............
Exa 4.5c Expectation ........................
Exa 4.5d Expectation ........................
Exa 4.5e Expected profit ......................
Exa 4.5f Letters in Correct Envelopes ..............
Exa 4.5g Different types of coupons ................
Exa 4.6a Variance of a fair die ...................
Exa 4.7a Variance of 10 rolls of a fair die .............
Exa 4.7b Variance of 10 tosses of a coin ..............
Exa 4.9a Inequalities ........................
Exa 5.1a Returning of disks ....................
Exa 5.1b Colour of Eyes ......................
Exa 5.1e Binomial Random Variable ...............
Exa 5.2a Probability of accident ..................
Exa 5.2b Defective Items ......................
Exa 5.2c Number of Alpha particles ...............
Exa 5.2d Claims handled by an insurance company .......
Exa 5.2f Defective stereos .....................
Exa 5.3a Functional system ....................
Exa 5.3b Determining Population Size ..............
Exa 5.3c Conditional Probability .................
Exa 5.4b Bus Timings .......................
Exa 5.4c Current in a diode ....................
Exa 5.5a Normal Random Variable ................
Exa 5.5b Noise in Binary Message .................
Exa 5.5c Power dissipation .....................
Exa 5.5d Yearly precipitation ...................
Exa 5.6a Wearing of Battery ....................
Exa 5.6b Working Machines ....................
Exa 5.6c Series System .......................
Exa 5.8a Chi square random variable ...............
Exa 5.8b Chi square random variable ...............
Exa 5.8c Locating a Target ....................
Exa 5.8d Locating a Target in 2D space .............
Exa 5.8e T distribution ......................
Exa 5.8f
F Distribution ......................
Exa 6.3a Claims handled by an insurance company .......
Exa 6.3c Class strength ......................
Exa 6.3d Weights of workers ....................
Exa 6.3e Distance of a start ....................
Exa 6.5a Processing time ......................
Exa 6.6a Candidate winning an election .............
Exa 6.6b Pork consumption ....................
Exa 7.2a Maximum likelihood estimator of a bernoulli parameter 51 Exa 7.2b Errors in a manuscript ..................
Exa 7.2c Maximum likelihood estimator of a poisson parameter
Exa 7.2d Number of traffic accidents ...............
Exa 7.2e Maximum likelihood estimator in a normal population
Exa 7.2f Kolmogorovs law of fragmentation ...........
Exa 7.2g Estimating Mean of a Uniform Distribution ......
Exa 7.3a Error in a signal .....................
Exa 7.3b Confidence interval ....................
Exa 7.3c Confidence interval ....................
Exa 7.3d Weight of a salmon ....................
Exa 7.3e Error in a signal .....................
Exa 7.3f Average resting pulse ..................
Exa 7.3g Evaluating integrals ...................
Exa 7.3h Thickness of washers ...................
Exa 7.4a Cable insulation .....................
Exa 7.4b Battery production ....................
Exa 7.5a Transistors ........................
Exa 7.5b Survey ..........................
Exa 7.5c Acceptable chips .....................
Exa 7.6a Life of a product .....................
Exa 7.7a Point estimator ......................
Exa 7.7b Point estimator ......................
Exa 7.7c Point estimator of a uniform distribution .......
Exa 7.8a Bayes estimator .....................
Exa 7.8b Bayes estimator of a normal population ........
Exa 7.8d estimator of the signal value ...............
Exa 8.3a Noise in a Signal .....................
Exa 8.3b Error in a signal .....................
Exa 8.3c Error in a signal .....................
Exa 8.3d Number of signals to be sent ..............
Exa 8.3e Number of signals to be sent ..............
Exa 8.3f Nicotine content in a cigarette .............
Exa 8.3g Blood cholestrol level ..................
Exa 8.3h Water usage .......................
Exa 8.3i Life of a tire .......................
Exa 8.3j Service Time .......................
Exa 8.4a Tire lives .........................
Exa 8.4b Medicine for cold .....................
Exa 8.4c Unknown population variance ..............
Exa 8.4d effectiveness of safety program .............
Exa 8.5a effectiveness of machine .................
Exa 8.5b Catalyst ..........................
Exa 8.6a Computer chip manufacturing ..............
Exa 8.6b Finding p value ......................
Exa 8.6c Change in manufacturing pattern ............
Exa 8.7a Mean number of defective chips .............
Exa 8.7b Safety Conditions in a plant ...............
Exa 8.7c Better proof reader ....................
Exa 9.1a Scatter Diagram .....................
Exa 9.2a Relative humidity and moisture content ........
Exa 9.3a Moisture against Density ................
Exa 9.4a Effect of speed on mileage ................
Exa 9.4b Confidence interval estimate ...............
Exa 9.4c Regression to the mean .................
Exa 9.4d Motor vehicle deaths ...................
Exa 9.4e Confidence interval for height ..............
Exa 9.4f Confidence interval for height ..............
Exa 9.5a Height of son and father .................
Exa 9.7a Percentage of chemical used ...............
Exa 9.8b Distance vs Travel Time .................
Exa 9.9a Polynomial Fitting ....................
Exa 9.10a Multiple Linear Regression ...............
Exa 9.10b Estimate of variance ...................
Exa 9.10c Diameter of a tree ....................
Exa 9.10d Estimating hardness ...................
Exa 9.11a Animal fsickalling ....................
Exa 10.3a Dependence of mileage on gas used ...........
Exa 10.3b Dependence of mileage on gas used ........... 100 Exa 10.3c Difference in GPA .................... 101 Exa 10.4b Estimating Parameters ................. 102 Exa 10.5a Species collected ..................... 103 Exa 11.2a Relation between death date and birth date ...... 105 Exa 11.2b Quality of bulbs ..................... 106 Exa 11.2d Six outcomes ....................... 106 Exa 11.3a Weekly accidents ..................... 107 Exa 11.4a Ploitical affiliation and Gender ............. 109 Exa 11.4b Machine Breakdown and shift .............. 110 Exa 11.5a Lung cancer and smoking ................ 111 Exa 11.5b Females reporting abuse ................. 112 Exa 11.6a Testing distribution of a population .......... 113 Exa 12.2a testing the median .................... 115 Exa 12.2b testing the median .................... 115 Exa 12.3b Signed Rank Test .................... 116 Exa 12.3c Determining Population Distribution .......... 117 Exa 12.4a Treatments against corrosion .............. 117 Exa 12.4b Determining P ...................... 118 Exa 12.4c Finding p value ...................... 119 Exa 12.4d Comparing production methods ............. 119 Exa 12.4e Determining p value ................... 119 Exa 12.5a Testing randomness ................... 120 Exa 12.5c Determining p value ................... 121
Exa 13.2a Steel shaft diameter ................... 122 Exa 13.2b unknown mean and variance .............. 123 Exa 13.3a determining control limits ................ 123 Exa 13.4a Defectives Screws .................... 126 Exa 13.5a Control during production of cars ............ 127 Exa 13.6b Service Time ....................... 128 Exa 13.6c Exponentially weighted moving average control .... 129 Exa 13.6d Finding control limit ................... 131 Exa 14.3a Lifetime of a transistor ................. 133 Exa 14.3b Lifetime of Battery .................... 134 Exa 14.3c One at a time sequential test .............. 134 Exa 14.3d Lifetime of semiconductors ............... 135 Exa 14.3e Bayes estimator ..................... 135 Exa 14.4a Lifetime of items produced by two plants ....... 135
List of Figures
2.1 pie chart .............................
9.1 Scatter Diagram .........................
9.2 Relative humidity and moisture content ............
9.3 Moisture against Density ....................
9.4 Regression to the mean .....................
9.5 Percentage of chemical used ..................
9.6 Percentage of chemical used ..................
9.7 Polynomial Fitting .......................
13.1 determining control limits ................... 124
13.2 determining control limits ................... 125
13.3 Exponentially weighted moving average control ....... 130
Chapter 2 Descriptive Statistics
Scilab code Exa 2.2a Relative Frequency
3 total= sum (frequency);
4 relative_frequency=frequencytotal;
5 disp ( ” The relative frequencies are”)
6 disp (relative_frequency)
Scilab code Exa 2.2b pie chart
1 v a l u e s = [42 50 32 55 9 12];
2 p e r c e n t a g e s = v a l u e s 100 sum (values);
3 new_text= string (percentages);
4 text = [ ” Lung ” , ” B r e a s t ” , ” C o l o n ” , ” P r o s t a t e ” , ”
Melanoma ” , ” B l a d d e r ” ];
5 p e r c e n t a g e _ s i g n = [ ”” , ”” , ”” , ”” , ”” , ”” ];
6 f i n a l _ t e x t = text + n e w _ t e x t + p e r c e n t a g e _ s i g n ;
Figure 2.1: pie chart
7 p i e ( [ 4 2 50 32 55 9 1 2 ] , [ ” Lung ” , ” B r e a s t ” , ” C o l o n
” , ” P r o s t a t e ” , ” Melanoma ” , ” B l a d d e r ” ] ) ;
8 pie ( v a l u e s , f i n a l _ t e x t ) ;
Scilab code Exa 2.3a Sample mean
1 s c o r e s =[284 , 280 , 277 , 282 , 279 , 285 , 281 , 283 , 278 ,
2 n e w _ s c o r e s = s c o r e s - 280;
3 final_mean= mean ( n e w _ s c o r e s ) + 280;
4 disp (final_mean)
Scilab code Exa 2.3b Sample mean of age
1 age = [15 16 17 18 19 20];
2 f r e q u e n c i e s = [2 5 11 9 14 13];
3 product = age . f r e q u e n c i e s ;
4 total_people= sum (frequencies);
5 mean_age= sum (product)total_people;
6 disp ( ” The s a m p l e mean o f theages is”)
7 disp (mean_age)
Scilab code Exa 2.3c Sample Median
1 age = [15 16 17 18 19 20];
2 f r e q u e n c i e s = [2 5 11 9 14 13];
3 i =1;
4 for j =1:6
5 for k = 1: f r e q u e n c i e s ( j )
6 f i n a l _ a g e ( i ) = age ( j ) ;
12 final_median= median (final_age);
13 disp (final_median);
Scilab code Exa 2.3d Mean and Median
1 g e r m _ f r e e _ m i c e = [158 192 193 194 195 202 212 215
2 c o n v e n t i o n a l _ m i c e = [159 189 191 198 235 245 250 256
3 disp ( mean ( g e r m _ f r e e _ m i c e ) , ” S a m p l e mean f o r germ−
free mice is”);
4 disp ( median (germ_free_mice),”Samplemedian for
germ− f r e e mice is”);
5 disp ( mean ( c o n v e n t i o n a l _ m i c e ) , ” S a m p l e mean f o r
conventionalmice is”);
6 disp ( median ( c o n v e n t i o n a l _ m i c e ) , ” S a m p l e mean f o r
conventionalmice is”);
Scilab code Exa 2.3e Mean Median and Mode
4 for j =1:6
5 for k = 1: f r e q u e n c i e s ( j )
6 final_value(i)=value(j);
7 i = i +1 ;
8 end ;
9 end
10 product = v a l u e . f r e q u e n c i e s ;
11 disp (product, sum (product))
13 total_value= sum (frequencies);
14 mean_value= sum (product)total_value; t h e a n s w e r
inthetextbook is incorrect
15 [ m1 m2 ]= max (frequencies);
16 n = m2 ;
18 disp ( ” The s a m p l e mean is”)
19 disp (mean_value)
20 disp ( median ( f i n a l _ v a l u e ) , ” The m e d i a n is”)
21 disp ( v a l u e ( n ) , ” The mode is”)
Scilab code Exa 2.3f sample variance
1 A = [ 3 4 6 7 10];
2 B = [ -20 5 15 24];
3 disp ( variance ( A ) , ” The s a m p l e variance ofAis”)
4 disp ( variance ( B ) , ” The s a m p l e variance ofBis”)
Scilab code Exa 2.3g sample variance of accidents
1 a c c i d e n t s = [22 22 26 28 27 25 30 29 24];
2 n e w _ a c c i d e n t s = a c c i d e n t s - 22;
3 disp ( variance ( n e w _ a c c i d e n t s ) , ” The v a r i a n c e of the
number o f accidents is”)
Scilab code Exa 2.3h Percentile
1 population=[7333253344861327317431702086
2 disp ( perctl ( p o p u l a t i o n , 10) , ” The s a m p l e 1 0
percentile is”)
3 disp ( perctl ( p o p u l a t i o n , 80) , ” The s a m p l e 8 0
percentile is”)
4 disp ( perctl ( p o p u l a t i o n , 50) , ” The s a m p l e 8 0
percentile is”)
5 disp ( median ( p o p u l a t i o n ) , ” The m e d i a n is”)
Scilab code Exa 2.3i Quartiles
2 disp ( quart ( n o i s e ) , ” The quartiles are”)
Scilab code Exa 2.4a Chebyshev Inequality
1 cars = [ 4 4 8 1 6 2 4 0 4 1 9 2 3 6 8 3 2 7 3 1 8 3 0 8 2 7 2 1 2 2 2 6 0 4 8 6
2 interval1= mean ( cars ) - ( 1 . 5 st_deviation ( cars ) ) ;
3 interval2= mean ( cars ) + ( 1 . 5 st_deviation ( cars ) ) ;
4 data = 1 0 0 5 9 ;
5 disp (interval2,,”to”,interval1,”Atleast
of thedata lies inthe interval”);
Scilab code Exa 2.5a Empirical Rule
1 data = [90 91 94 83 85 85 87 88 72 74 74 75 77 77 78
2 disp (”According tothe empirical rule”)
3 disp ( ” 6 8 o f thedata lies between”)
4 disp ( mean ( data ) + st_deviation ( data ) , ” and ” , mean ( data
)- st_deviation ( data ) )
5 disp ( ” 9 5 o f thedata lies between”)
6 disp ( mean ( data ) +(2 st_deviation ( data ) ) , ” and ” , mean (
data ) -(2 st_deviation ( data ) ) )
7 disp ( ” 9 9 . 7 o f thedata lies between”)
8 disp ( mean ( data ) +(3 st_deviation ( data ) ) , ” and ” , mean (
data ) -(3 st_deviation ( data ) ) )
Scilab code Exa 2.6a Sample Correlation Coefficient
3 t e m p _ n e w = temp - mean ( temp ) ;
4 defects_new=defects- mean (defects);
8 for i=1:22
9 num = num + ( t e m p _ n e w ( i ) d e f e c t s _ n e w ( i ) ) ;
10 s1 = s1 + ( t e m p _ n e w ( i ) t e m p _ n e w ( i ) ) ;
11 s2 = s2 + ( d e f e c t s _ n e w ( i ) d e f e c t s _ n e w ( i ) ) ;
12 end
13 c o e f f i c i e n t = num sqrt ( s1 s2 ) ;
14 disp (coefficient)
Scilab code Exa 2.6b Sample Correlation Coefficient
1 year = [12 16 13 18 19 12 18 19 12 14];
2 p u l s e r a t e = [73 67 74 63 73 84 60 62 76 71];
3 y e a r _ n e w = year - mean ( year ) ;
4 pulserate_new=pulserate- mean (pulserate);
8 for i=1:10
13 c o e f f i c i e n t = num sqrt ( s1 s2 ) ;
14 disp (coefficient)
Chapter 3 Elements Of Probability
Scilab code Exa 3.4a Union
1 cigarette=0.28;
2 cigar=0.07;
3 c i g a r _ a n d _ c i g a r e t t e = 0.05 ;
4 cigar_or_cigarette=cigarette+cigar-
cigar_and_cigarette;
5 disp ( ” o f t h e m a l e s smoke n e i t h e r cigar nor
c i g a r e t t e ” , (1 - c i g a r _ o r _ c i g a r e t t e ) 100 )
Scilab code Exa 3.5a Basic Principle of Counting
1 w h i t e _ b a l l s = 6;
2 b l a c k _ b a l l s = 5;
3 total=white_balls+black_balls;
4 probability_whiteandblack=white_ballsblack_balls
( t o t a l ( total -1) ) ;
5 probability_blackandwhite=white_ballsblack_balls
( t o t a l ( total -1) ) ;
6 reqd_probability=probability_whiteandblack+
probability_blackandwhite;
7 disp ( r e q d _ p r o b a b i l i t y , ” Thus , the required
probability is”)
Scilab code Exa 3.5b Basic Principle of Counting
factorial(chemistry)factorial(history)factorial (language);
6 disp ( t o t a l _ a r r a n g e m e n t s , ” The t o t a l number o f
possible arrangements is”)
Scilab code Exa 3.5c Basic Principle of Counting
1 men = 6;
2 w o m e n = 4;
3 disp ( f a c t o r i a l ( men + w o m e n ) , ”No o f different rankings
possible is”)
4 w o m e n _ t o p 4 = f a c t o r i a l ( w o m e n ) f a c t o r i a l ( men ) ;
5 prob = w o m e n _ t o p 4 f a c t o r i a l ( men + w o m e n ) ;
6 disp ( prob , ” P r o b a b i l i t y t h a t women r e c e i v e thetop4
scores is”)
Scilab code Exa 3.5d Committee Probability
1 men = 6;
2 w o m e n = 9;
3 r e q d _ s i z e =5;
4 t o t a l = f a c t o r i a l ( men + w o m e n ) ( f a c t o r i a l ( r e q d _ s i z e )
f a c t o r i a l ( men + women - r e q d _ s i z e ) ) ;
5 g i v e n _ c o m m i t t e e = f a c t o r i a l ( men ) f a c t o r i a l ( w o m e n ) (
f a c t o r i a l (3) f a c t o r i a l (2) f a c t o r i a l ( men -3)
f a c t o r i a l ( women -2) ) ;
6 prob = g i v e n _ c o m m i t t e e t o t a l ;
7 disp ( prob , ” P r o b a b i l i t y thatthecommittee consists
o f 3 men and 2 women i s ” )
Scilab code Exa 3.5f Pairing Probability
4 total_p=black_p+white_p;
9 total_pairs = 1;
10 while ( t o t a l _ p >0)
11 t o t a l _ p a i r s = t o t a l _ p a i r s f a c t o r i a l ( t o t a l _ p ) (
f a c t o r i a l ( pair ) f a c t o r i a l ( t o t a l _ p - pair ) )
17 black_pairs = 1;
18 while ( b l a c k _ p >0)
19 b l a c k _ p a i r s = b l a c k _ p a i r s f a c t o r i a l ( b l a c k _ p ) ((
f a c t o r i a l ( pair ) f a c t o r i a l ( b l a c k _ p - pair ) ) );
27 white_pairs=black_pairs;
28 allowed_pairs=black_pairswhite_pairs;
29 probb=allowed_pairstotal_pairs;
30 disp ( probb , ” Probability t h a t a random p a i r i n g will
not result
i n any o f t h e w h i t e and b l a c k players
roomingtogether is”)
Scilab code Exa 3.6a Acceptable Transistor
4 disp ( a c c e p t a b l e ( a c c e p t a b l e + p a r t i a l l y _ d e f e c t i v e ) , ”
The r e q u i r e d probability is”)
Scilab code Exa 3.6b Both Boys
1 prob_bb=0.25;
2 prob_bg=0.25;
3 prob_gb=0.25;
4 prob_gg=0.25;
5 disp ( p r o b _ b b ( p r o b _ b g + p r o b _ g b + p r o b _ b b ) , ” P r o b a b i l i t y
thatbothareboys is”)
Scilab code Exa 3.6c Branch Manager
1 p r o b _ p h o e n i x = 0.3;
2 p r o b _ m a n a g e r = 0.6;
3 disp (prob_phoenixprob_manager,”Probability that
Perez will
be a P h o e n i x b r a n c h office manager is”
Scilab code Exa 3.7a Accident Probability
1 a c c i d e n t _ p r o n e = 0.4;
2 n o n a c c i d e n t _ p r o n e = 0.2;
3 p o p _ a c c i d e n t = 0.3;
4 prob = p o p _ a c c i d e n t a c c i d e n t _ p r o n e + (1 - p o p _ a c c i d e n t
)nonaccident_prone;
5 disp ( prob , ” The r e q u i r e d probability is”);
Scilab code Exa 3.7b Accident within a year
1 a c c i d e n t _ p r o n e = 0.4;
2 n o n a c c i d e n t _ p r o n e = 0.2;
3 p o p _ a c c i d e n t = 0.3;
4 p r o b _ o f _ a c c i d e n t = p o p _ a c c i d e n t a c c i d e n t _ p r o n e + (1 -
pop_accident)nonaccident_prone;
5 prob = p o p _ a c c i d e n t a c c i d e n t _ p r o n e
prob_of_accident;
6 disp ( prob , ” The r e q u i r e d probability is”)
Scilab code Exa 3.7c Multiple Choice Test
1 m = 5;
2 p=12;
3 disp ( ( m p ) ( 1 + ( ( m -1) p ) ) , ” The r e q u i r e d probability
is”)
Scilab code Exa 3.7d blood test
1 detect_present=0.99;
2 detect_notpresent=0.01;
3 pop_disease=0.005;
4 prob = d e t e c t _ p r e s e n t p o p _ d i s e a s e (( d e t e c t _ p r e s e n t
p o p _ d i s e a s e ) +( d e t e c t _ n o t p r e s e n t (1 - p o p _ d i s e a s e ) )
5 disp ( prob , ” The r e q u i r e d probability is”)
Scilab code Exa 3.7e Criminal Investigation
1 c r i m i n a l _ c h a r = 0.9
2 c o n v i n c e d = 0.6;
3 p o p _ c h a r = 0.2;
4 prob = ( c o n v i n c e d c r i m i n a l _ c h a r ) (( c o n v i n c e d
c r i m i n a l _ c h a r ) + ( p o p _ c h a r (1 - c o n v i n c e d ) ) ) ;
5 disp ( prob , ” The r e q u i r e d probability is”)
Scilab code Exa 3.7f Missing Plane
1 a l p h a 1 = 0.4;
2 p l a n e _ i n _ r e g i o n 1 = 13;
3 p l a n e _ i n _ r e g i o n 2 = 13;
4 p l a n e _ i n _ r e g i o n 3 = 13;
5 p r o b 1 = ( a l p h a 1 p l a n e _ i n _ r e g i o n 1 ) (( a l p h a 1
p l a n e _ i n _ r e g i o n 1 ) + 1 p l a n e _ i n _ r e g i o n 2 + 1 plane_in_region3);
6 p r o b 2 = (1 p l a n e _ i n _ r e g i o n 2 ) (( a l p h a 1
p l a n e _ i n _ r e g i o n 1 ) + 1 p l a n e _ i n _ r e g i o n 2 + 1 plane_in_region3);
7 disp ( p r o b 1 , ” The p r o b a b i l i t y thatthe planes is in
region1given thatthe search of region1did notuncover it”);
8 disp ( p r o b 2 , ” The p r o b a b i l i t y thatthe planes is in
region23given thatthe search of region1did notuncover it”);
Scilab code Exa 3.8a Independent Events
1 prob_A=452;
2 prob_H=1352;
3 disp ( p r o b _ A p r o b _ H , ”P (AH) is”)
Chapter 4 Random Variables And
Expectation
Scilab code Exa 4.1a sum of two fair dice
1 p11 = 1 3 6 ;
2 p12 = 1 3 6 ;
3 p13 = 1 3 6 ;
4 p14 = 1 3 6 ;
5 p15 = 1 3 6 ;
6 p16 = 1 3 6 ;
7 p21 = 1 3 6 ;
8 p22 = 1 3 6 ;
9 p23 = 1 3 6 ;
10 p24 = 1 3 6 ;
11 p25 = 1 3 6 ;
12 p26 = 1 3 6 ;
13 p31 = 1 3 6 ;
14 p32 = 1 3 6 ;
15 p33 = 1 3 6 ;
16 p34 = 1 3 6 ;
17 p35 = 1 3 6 ;
18 p36 = 1 3 6 ;
19 p41 = 1 3 6 ;
37 disp ( p11 , ” P r o b a b i l i t y t h a t t h e sum i s 2 ” )
38 disp ( p12 + p21 , ” P r o b a b i l i t y t h a t t h e sum i s 3 ” )
39 disp ( p13 + p31 + p22 , ” P r o b a b i l i t y t h a t t h e sum i s 4 ” )
40 disp ( p14 + p41 + p32 + p23 , ” P r o b a b i l i t y t h a t t h e sum i s 5
”)
41 disp ( p15 + p51 + p24 + p42 + p33 , ” P r o b a b i l i t y t h a t t h e sum
is6”)
42 disp ( p16 + p61 + p25 + p52 + p34 + p43 , ” P r o b a b i l i t y thatthe
sum i s 7 ” )
43 disp ( p26 + p62 + p35 + p53 + p44 , ” P r o b a b i l i t y t h a t t h e sum
is8”)
44 disp ( p36 + p63 + p45 + p54 , ” P r o b a b i l i t y t h a t t h e sum i s 9
”)
45 disp ( p46 + p64 + p55 , ” P r o b a b i l i t y t h a t t h e sum i s
10 ” )
46 disp ( p65 + p56 , ” P r o b a b i l i t y t h a t t h e sum i s
11 ” )
47 disp ( p66 , ” P r o b a b i l i t y t h a t t h e sum i s
12 ” )
Scilab code Exa 4.1b Defective or Acceptable
6 disp ( pdd , ” P r o b a b i l i t y t h a t t h e number o f acceptable
components is0is”)
7 disp ( pda + pad , ” P r o b a b i l i t y t h a t t h e number o f
acceptablecomponents is1is”)
8 disp ( paa , ” P r o b a b i l i t y t h a t t h e number o f acceptable
components is2is”)
9 disp ( pdd , ” P r o b a b i l i t y thatI is0
is”)
11 disp ( paa + pad + pda , ” P r o b a b i l i t y thatI is1is”)
Scilab code Exa 4.1c X exceeds 1
1 prob = 1 -(1 -(1 e ) ) ;
2 disp ( prob , ” P r o b a b i l i t y thatXexceeds1is”)
Scilab code Exa 4.2a sum of pmf
1 p1 = 12;
2 p2 = 13;
3 disp (1 -( p1 + p2 ) , ” P r o b a b i l i t y thatXis3is”)
Scilab code Exa 4.2b pdf
2 integral= integrate ( ’ ( 4 ∗ x ) −(2∗ x ∗ x ) ’ , ’ x ’ , 0 , 2) ;
3 C = 1 i n t e g r a l ;
4 disp ( C , ” The v a l u e ofCis”)
5 integral_new= integrate ( ’C ∗ ( ( 4 ∗ x ) −(2∗ x ∗ x ) ) ’ , ’x’,
6 disp (1 - i n t e g r a l _ n e w , ” P r o b a b i l i t y thatXis greater
than1is”)
Scilab code Exa 4.3a Joint distribution of batteries
4 t o t a l = f a c t o r i a l (12) ( f a c t o r i a l (3) f a c t o r i a l (9) ) ;
5 disp ( f a c t o r i a l (5) ( f a c t o r i a l (3) f a c t o r i a l (2) t o t a l ) ,
”Probability t h a t X=0 and Y=0” ) ;
6 disp ( f a c t o r i a l (5) f a c t o r i a l (4) ( f a c t o r i a l (3)
f a c t o r i a l (2) f a c t o r i a l (3) t o t a l ) , ” P r o b a b i l i t y t h a t X=0 and Y=1” ) ;
7 disp ( f a c t o r i a l (5) f a c t o r i a l (4) ( f a c t o r i a l (2)
f a c t o r i a l (2) f a c t o r i a l (4) t o t a l ) , ” P r o b a b i l i t y t h a t X=0 and Y=2” ) ;
8 disp ( f a c t o r i a l (4) ( f a c t o r i a l (3) f a c t o r i a l (1) t o t a l ) ,
”Probability t h a t X=0 and Y=3” ) ;
9 disp ( f a c t o r i a l (3) f a c t o r i a l (5) ( f a c t o r i a l (2)
f a c t o r i a l (2) f a c t o r i a l (3) t o t a l ) , ” P r o b a b i l i t y t h a t X=1 and Y=0” ) ;
10 disp ( f a c t o r i a l (5) f a c t o r i a l (4) f a c t o r i a l (3) (
f a c t o r i a l (2) f a c t o r i a l (3) f a c t o r i a l (4) t o t a l ) , ” Probability t h a t X=1 and Y=1” ) ;
11 disp ( f a c t o r i a l (3) f a c t o r i a l (4) ( f a c t o r i a l (2)
f a c t o r i a l (2) f a c t o r i a l (2) t o t a l ) , ” P r o b a b i l i t y t h a t X=1 and Y=2” ) ;
12 disp ( f a c t o r i a l (3) f a c t o r i a l (5) ( f a c t o r i a l (2)
f a c t o r i a l (4) f a c t o r i a l (1) t o t a l ) , ” P r o b a b i l i t y t h a t X=2 and Y=0” ) ;
13 disp ( f a c t o r i a l (3) f a c t o r i a l (4) ( f a c t o r i a l (2)
f a c t o r i a l (1) f a c t o r i a l (3) t o t a l ) , ” P r o b a b i l i t y t h a t X=2 and Y=1” ) ;
14 disp ( f a c t o r i a l (3) ( f a c t o r i a l (3) t o t a l ) , ” P r o b a b i l i t y
t h a t X=3 and Y=3” ) ;
Scilab code Exa 4.3b Joint distribution of boys and girls
1 child0=0.15;
2 c h i l d 1 = 0.2;
6 p g i r l = 0.5;
8 disp (child0,”Probability t h a t B=0 and G=0” )
9 disp (child1pgirl,”Probability t h a t B=0 and G=1” )
10 disp (child2pgirlpgirl,”Probability t h a t B=0 and
G=2” )
11 disp (child3pgirlpgirlpgirl,”Probability thatB
=0 and G=3” )
12 disp ( c h i l d 1 pboy , ” P r o b a b i l i t y t h a t B=1 and G=0” )
13 disp ( c h i l d 2 p g i r l pboy , ” P r o b a b i l i t y t h a t B=1 and G
=1” )
14 disp ( c h i l d 3 p g i r l p g i r l pboy , ” P r o b a b i l i t y t h a t B=1
and G=2” )
15 disp ( c h i l d 2 pboy pboy , ” P r o b a b i l i t y t h a t B=2 and G
=0” )
16 disp ( c h i l d 3 p g i r l pboy pboy , ” P r o b a b i l i t y t h a t B=2
and G=1” )
17 disp ( c h i l d 3 pboy pboy pboy , ” P r o b a b i l i t y t h a t B=3
and G=0” )
Scilab code Exa 4.3c Joint Density Function
1 intx = integrate ( ’ eˆ(− x ) ’ , ’ x ’ ,0 , 1 ) ;
2 inty = integrate ( ’ 2∗eˆ( −2∗ y ) ’ , ’ y ’ , 0 , 1) ;
3 a n s w e r = (1 - intx ) inty ;
4 disp (answer,”Probability t h a t X>1 and Y<1 i s ” )
6 For o t h e r two p a r t s , symbolic manipulations are
required
Scilab code Exa 4.3e Density of Independent Random Variables
1 pdec3=0.05;
2 p d e c 2 = 0.1;
3 p d e c 1 = 0.2;
4 p0 = 0.3
5 p i n c 1 = 0.2;
6 p i n c 2 = 0.1;
7 pinc3=0.05;
8 disp ( p i n c 1 p i n c 2 p0 , ” P r o b a b i l i t y thatthestock
price will increase s u c c e s s i v e l y by 1 , 2 and 0 points inthenext3days is”)
Scilab code Exa 4.3f Conditional Probability Mass Function
1 disp (0.10.3875,”probability t h a t B =0 g i v e n G=1 ” )
2 disp (0.1750.3875,”probability t h a t B =1 g i v e n G=1
”);
3 disp (0.11250.3875,”probability t h a t B =2 g i v e n G=1
”);
4 disp (00.3875,”probability t h a t B =3 g i v e n G=1 ” ) ;
5 The v a l u e s aretakenfromTable4.2
Scilab code Exa 4.3g Conditional Probability Mass Function
7 disp ( p01 pY1 , ” P r o b a b i l i t y t h a t X=0 and Y=1” )
8 disp ( p11 pY1 , ” P r o b a b i l i t y t h a t X=1 and Y=1” )
Scilab code Exa 4.4a Expectation of a fair die
8 disp (expec)
Scilab code Exa 4.4d Expectation of the message time
1 expec= integrate (’(x)1.5’, ’ x ’ , 0 ,1.5) ;
2 disp ( ” h o u r s ” , expec , ”On an a v e r a g e , you h a v e t o
wait for”)
Scilab code Exa 4.5a Expectation
5 disp ( expec , ” E x p e c t a t i o n o f Xˆ2 is”)
Scilab code Exa 4.5b Expected cost of breakdown
1 expec= integrate (’xˆ3’, ’ x ’ , 0 , 1) ;
2 disp ( expec , ” The e x p e c t a t i o n is”)
Scilab code Exa 4.5c Expectation
5 disp ( expec , ” E x p e c t a t i o n o f Xˆ2 is”)
Scilab code Exa 4.5d Expectation
1 expec= integrate (’xˆ3’, ’ x ’ , 0 , 1) ;
2 disp ( expec , ” The e x p e c t a t i o n is”)
Scilab code Exa 4.5e Expected profit
4 p r o b 1 = 0.2;
5 p r o b 2 = 0.8;
6 p r o b 3 = 0.3;
7 expec=profit1prob1+profit2prob2+profit3
prob3;
8 disp (”thousand
d o l l a r s ” , expec , ” The e x p e c t d profit
is”)
Scilab code Exa 4.5f Letters in Correct Envelopes
1 As s c i l a b doesnotsymboliccomputations, this
example is solved t a k i n g N=5
2 prob = 15 p r o b a b i l i t y thataletter is putinto
the right envelope
3 EX1 = 1 prob +0(1 - prob ) ;
4 EX2 = 1 prob +0(1 - prob ) ;
5 EX3 = 1 prob +0(1 - prob ) ;
6 EX4 = 1 prob +0(1 - prob ) ;
7 EX5 = 1 prob +0(1 - prob ) ;
8 EX = EX1 + EX2 + EX3 + EX4 + EX5 ;
9 disp ( EX , ” Thus , the expectation is”)
Scilab code Exa 4.5g Different types of coupons
4 disp ( EX , ” The e x p e c t a t i o n is”)
Scilab code Exa 4.6a Variance of a fair die
1 p r o b X e q u a l s i = 16;
2 e x p e c X s q u a r e d = 0;
3 for n =1:6
4 expecXsquared=expecXsquared+(nn
9 disp ( var , ” The v a r i a n c e is”)
Scilab code Exa 4.7a Variance of 10 rolls of a fair die
1 p r o b X e q u a l s i = 16;
2 e x p e c X s q u a r e d = 0;
3 for n =1:6
4 expecXsquared=expecXsquared+(nn
10 disp ( var10 , ” The v a r i a n c e is”)
Scilab code Exa 4.7b Variance of 10 tosses of a coin
1 p r o b I j = 0.5;
2 v a r I j = p r o b I j (1 - p r o b I j ) ;
3 var = 10 v a r I j ;
4 disp ( var , ” Thus , the required variance is”)
Scilab code Exa 4.9a Inequalities
1 avg = 50;
2 p r o b X 7 5 = avg 75;
3 disp ( probX75 , ” P r o b a b i l i t y t h a t X>75 i s ” )
4 var = 25;
5 u p p e r l i m i t = var 1 0 0 ;
6 disp (1 - u p p e r l i m i t , ” P r o b a b i l i t y thatXlies between
40 and 60 is”)
Chapter 5 Special Random Variables
Scilab code Exa 5.1a Returning of disks
9) f a c t o r i a l ( disks -1) ;
6 prob = 1 - p r o b d e f e c t 0 - p r o b d e f e c t 1 ;
7 disp ( prob , ” P r o b a b i l i t y thatapackage will be
returned is”)
8 n e w p r o b = f a c t o r i a l ( p a c k a g e ) prob ((1 - prob ) 2)
f a c t o r i a l ( package -1) ;
9 disp ( newprob , ” P r o b a b i l i t y that exactlyoneof the
packages will
be r e t u r n e d among 3 i s ” )
11 t h e solution inthetextbook is approximate
Scilab code Exa 5.1b Colour of Eyes
1 function result= binomial (n,k,p)
2 r e s u l t = f a c t o r i a l ( n ) ( p k ) ((1 - p ) ( n - k ) ) (
factorial(k)factorial(n-k))
8 prob = binomial ( children , r e q d b l u e y e s , p r o b b l u e e y e s )
9 disp ( prob , ” The r e q d probability is”)
Scilab code Exa 5.1e Binomial Random Variable
1 function r e s u l t = bin ( n , k , p )
2 if ( k ==0)
3 r e s u l t = (1 - p ) n ;
4 else
5 result = p ( n - k +1) bin ( n , k -1 , p ) ((1 - p ) k
9 disp ( bin (6 , 0 , 0.4) , ” P r o b a b i l i t y t h a t X=0 i s ” )
10 disp ( bin (6 , 1 , 0.4) , ” P r o b a b i l i t y t h a t X=1 i s ” )
11 disp ( bin (6 , 2 , 0.4) , ” P r o b a b i l i t y t h a t X=2 i s ” )
12 disp ( bin (6 , 3 , 0.4) , ” P r o b a b i l i t y t h a t X=3 i s ” )
13 disp ( bin (6 , 4 , 0.4) , ” P r o b a b i l i t y t h a t X=4 i s ” )
14 disp ( bin (6 , 5 , 0.4) , ” P r o b a b i l i t y t h a t X=5 i s ” )
15 disp ( bin (6 , 6 , 0.4) , ” P r o b a b i l i t y t h a t X=6 i s ” )
Scilab code Exa 5.2a Probability of accident
1 [ probX0 , Q ]= cdfpoi ( ”PQ” , 0 , 3) ;
2 probX1=1-probX0;
3 disp ( probX1 , ” P r o b a b i l i t y that there is at least one
accident t h i s week i s ” )
Scilab code Exa 5.2b Defective Items
1 function r e s u l t = bino ( n , k , p )
2 r e s u l t = f a c t o r i a l ( n ) ( p k ) ((1 - p ) ( n - k ) ) (
factorial(k)factorial(n-k))
3 endfunction
5 prob = bino (10 ,0 , 0.1) + bino (10 , 1 ,0.1 ) ;
6 disp ( prob , ” The e x a c t probability is”);
8 probp= cdfpoi ( ”PQ” , 1 , 1)
9 disp ( probp , ” The p o i s s o n approximation is”)
Scilab code Exa 5.2c Number of Alpha particles
1 Xlam = 3.2;
2 i =2;
3 prob = cdfpoi ( ”PQ” , i , Xlam ) ;
4 disp ( prob )
Scilab code Exa 5.2d Claims handled by an insurance company
1 function r e s u l t = bino ( n , k , p )
2 r e s u l t = f a c t o r i a l ( n ) ( p k ) ((1 - p ) ( n - k ) ) (
factorial(k)factorial(n-k))
6 prob = cdfpoi ( ”PQ” , 2 , avg ) ;
7 disp ( prob , ” P r o p o r t i o n ofdaysthathave less than3
claims is”)
8 probX4= cdfpoi ( ”PQ” , i +1 , avg ) - cdfpoi ( ”PQ” , i , avg
10 r e q d p r o b = bino (5 ,3 , p r o b X 4 ) ;
11 disp ( reqdprob , ” P r o b a b i l i t y that3of thenext5
days will haveexactly4claims is”)
Scilab code Exa 5.2f Defective stereos
1 avg = 4;
2 prob = cdfpoi ( ”PQ” , 3 , 2 avg )
3 disp ( prob )
Scilab code Exa 5.3a Functional system
1 function result=hyper(N,M,n,i)
2 result=factorial(N)factorial(M)factorial(n)
f a c t o r i a l ( N + M - n ) ( f a c t o r i a l ( i ) f a c t o r i a l ( N - i ) factorial(n-i)factorial(M-n+i)factorial(N+ M));
3 endfunction
5 prob = h y p e r (15 , 5 ,6 , 4) + h y p e r (15 , 5 ,6 ,5) + h y p e r
6 disp ( prob , ” P r o b a b i l i t y thatthesystem will be
functional is”)
Scilab code Exa 5.3b Determining Population Size
1 function result=hyper(N,M,n,i)
2 result=factorial(N)factorial(M)factorial(n)
f a c t o r i a l ( N + M - n ) ( f a c t o r i a l ( i ) f a c t o r i a l ( N - i ) factorial(n-i)factorial(M-n+i)factorial(N+ M));
8 disp (rnX,”Estimate of t h e number o f animals in
the region is”)
Scilab code Exa 5.3c Conditional Probability
1 function r e s u l t = bino ( n , k , p )
2 r e s u l t = f a c t o r i a l ( n ) ( p k ) ((1 - p ) ( n - k ) ) (
factorial(k)factorial(n-k))
3 endfunction
5 function answer=condprob(n,k,p,i)
6 a n s w e r = bino ( n , i , p ) bino ( m , k - i , p ) bino ( n + m , k , p
9 The f u n c t i o n c o n d p r o b will
g i v e P{X= i | X+Y=k }
Scilab code Exa 5.4b Bus Timings
1 pass_f=130;
2 p r o b 1 = (15 -10) p a s s _ f + (30 -25) p a s s _ f ;
3 p r o b 2 = (3 -0) p a s s _ f + (18 -15) p a s s _ f ;
4 disp ( prob1 , ” P r o b a b i l i t y t h a t he w a i t s less than5
minutes forabus”)
5 disp ( prob2 , ” P r o b a b i l i t y t h a t he w a i t s a t least 12
minutes forabus”)
Scilab code Exa 5.4c Current in a diode
7 expec= integrate ( ’ ( e ˆ ( a ∗ x ) ) 2 ’ , ’ x ’ , 1 ,3) ;
8 e x p e c I = I0 ( e x p e c -1) ;
9 disp (expecI)
Scilab code Exa 5.5a Normal Random Variable
4 prob1= cdfnor ( ”PQ” , 11 , u , sqrt ( var ) ) ;
5 disp ( prob1 , ” P{X<11} ” ) ;
6 prob2=1- cdfnor ( ”PQ” , -1 , u , sqrt ( var ) ) ;
7 disp ( prob2 , ”P{X>−1}” ) ;
8 prob3= cdfnor ( ”PQ” , 7 , u , sqrt ( var ) ) - cdfnor ( ”PQ” ,
2,u, sqrt ( var ) ) ;
9 disp ( prob3 , ”P{2 Scilab code Exa 5.5b Noise in Binary Message 1 disp ( cdfnor ( ”PQ” , -1.5 , 0 , 1) , ”P{ e r r o r | m e s s a g e is 1} ” ) 2 disp (1 - cdfnor ( ”PQ” , 2.5 , 0 , 1) , ”P{ e r r o r | m e s s a g e is 0}”) Scilab code Exa 5.5c Power dissipation 7 disp ( expecW , ” E x p e c t a t i o n ofWis”) 8 limw = 1 2 0 ; 9 limV = sqrt ( limw r ) ; 10 disp (1 - cdfnor ( ”PQ” , limV , avg , std ) , ”P{W>120} is”) Scilab code Exa 5.5d Yearly precipitation 4 meanX=meanX1+meanX2; 5 varX = 2 ( 3 . 1 2 ) ; 6 lim = 25; 7 disp (1 - cdfnor ( ”PQ” , lim , meanX , sqrt ( varX ) ) , ” Probability thatthe total precipitation during thenext2years will e x c e e d 25 i n c h e s ” ) 9 meanXnew=meanX1-meanX2; 10 n e w _ l i m = 3; 11 disp (1 - cdfnor ( ”PQ” , new_lim , meanXnew , sqrt ( varX ) ) , ”Probability that precipitation inthenextyear will exceedthat inthe following y e a r by more than3inches”) Scilab code Exa 5.6a Wearing of Battery 1 lamda=110000; 2 x =5000; 3 prob = e ( -1 l a m d a x ) ; 4 disp ( prob , ” Probability thatshe will be a b l e t o completeher trip withouthavingto replace her car battery is”); Scilab code Exa 5.6b Working Machines 1 When C i s puttouse,oneothermachine(eitherA orB) will still be w o r k i n g . The p r o b a b i l i t y of this machineorCfailing is e q u a l due t o t h e memorylesspropoerty of e x p o n e n t i a l random variables. 3 disp (12 , ” The p r o b a b i l i t y thatmachinewhich is still operable is machineCis”) Scilab code Exa 5.6c Series System 1 function r e s u l t = new ( lamda , n , t ) 4 newsum=newsum+lamda(i) Scilab code Exa 5.8a Chi square random variable 1 disp ( cdfchn ( ”PQ” , 30 , 26 , 0) ) ; Scilab code Exa 5.8b Chi square random variable 1 disp ( cdfchn ( ”X” , 15 , 0 ,0.95 , 0.05 ) ) Scilab code Exa 5.8c Locating a Target 1 disp (1 - cdfchn ( ”PQ” , 94 , 3 , 0) ) Scilab code Exa 5.8d Locating a Target in 2D space 1 disp (1 - cdfchn ( ”PQ” , 2.25 ,2 ,0) ) Scilab code Exa 5.8e T distribution 1 disp ( cdft ( ”PQ” , 1.4 , 12) , ”P{ T12 <=1.4} ” ) ; 2 disp ( cdft ( ”T” , 9 , 0.975 , 0 . 0 2 5 ) , ” t 0 . 0 2 5 , 9”) Scilab code Exa 5.8f F Distribution 1 disp ( cdff ( ”PQ” , 1.5 , 6 , 14) ) Statistics Scilab code Exa 6.3a Claims handled by an insurance company 1 number=25000; 2 m e a n e a c h = 320; 3 s d e a c h = 540; 4 claim=8300000; 5 meantotal=meaneachnumber; 6 sdtotal=sdeach sqrt (number); 7 disp (1 - cdfnor ( ”PQ” , claim , m e a n t o t a l , s d t o t a l ) ) Scilab code Exa 6.3c Class strength 1 i d e a l _ n u m = 150; 2 a c t u a l _ n u m = 450; 3 a t t e n d = 0.3; 4 t o l e r a n c e = 0.5 5 disp (1 - cdfnor ( ”PQ” , i d e a l _ n u m + t o l e r a n c e , a c t u a l _ n u m attend , sqrt ( a c t u a l _ n u m a t t e n d (1 - a t t e n d ) ) ) ) Scilab code Exa 6.3d Weights of workers 4 sdtotal=sdeach sqrt ( num ) ; 5 s d t o t a l = s d t o t a l ∗ s d t o t a l ; 6 d i s p ( s d t o t a l ) 7 disp ( cdfnor ( ”PQ” , 170 , meaneach , s d t o t a l ) - cdfnor ( ”PQ ” , 163 , meaneach , sdtotal ) , ” P r o b a b i l i t y thatthe s a m p l e mean o f their weights lies between163 and 1 7 0 ( when s a m p l e size is 36)”) 9 num = 1 4 4 ; 10 sdtotal=sdeach sqrt ( num ) ; 11 d i s p ( s d t o t a l ) 12 disp ( cdfnor ( ”PQ” , 170 , meaneach , s d t o t a l ) - cdfnor ( ”PQ ” , 163 , meaneach , sdtotal ) , ” P r o b a b i l i t y thatthe s a m p l e mean o f their weights lies between163 and 1 7 0 ( when s a m p l e size is 144)”) 14 The a n s w e r g i v e n inthetextbook is incorrect as (170−167)4.5 is notequalto0.6259 . Scilab code Exa 6.3e Distance of a start 1 prob = 0 . 9 5 ; 2 lim = 0.5; 3 X= cdfnor ( ”X” , 0 ,1 , 0.975 , 0 . 0 2 5 ) 4 disp ( ceil ((4 X ) 2) , ” O b s e r v a t i o n s are necessary ( atleast)”) Scilab code Exa 6.5a Processing time 5 prob = 1- cdfchi ( ”PQ” , a c t u a l _ l i m , ( n -1) ) 6 disp ( prob ) Scilab code Exa 6.6a Candidate winning an election 1 favour=0.45; 2 s a m p l e s i z e = 200; 3 expec=favoursamplesize; 4 sd = sqrt ( s a m p l e s i z e f a v o u r (1 - f a v o u r ) ) ; 5 disp ( expec , ” The e x p e c t e d value is”) 6 disp ( sd , ” The s t a n d a r d deviation is”) 8 function r e s u l t = bino ( n , k , p ) 9 r e s u l t = f a c t o r i a l ( n ) ( p k ) ((1 - p ) ( n - k ) ) ( factorial(k)factorial(n-k)) 13 f o r i=1:10 14 newsum = newsum + b i n o ( 2 0 0 , i , favour) 15 end 16 p r o b = 1−newsum ; ∗ 18 lim = 101; 19 t o l e r a n c e = 0.5; 20 lim = lim - t o l e r a n c e ; 21 prob = 1 - cdfnor ( ”PQ” , lim , expec , sd ) 22 23 disp ( prob , ” P r o b a b i l i t y t h a t more t h a n half the members o f thesamplefavourthecandidate”) Scilab code Exa 6.6b Pork consumption 1 m e a n e a c h = 147; 5 samplemean=meaneach; 6 samplesd=sdeach sqrt (samplesize) 7 prob = 1 - cdfnor ( ”PQ” , lim , s a m p l e m e a n , s a m p l e s d ) 8 disp ( prob ) Scilab code Exa 7.2a Maximum likelihood estimator of a bernoulli pa- rameter 1 samplesize=1000; 2 acceptable=921; 3 disp ( a c c e p t a b l e s a m p l e s i z e , ” The maximum l i k e l i h o o d estimate ofpis”) Scilab code Exa 7.2b Errors in a manuscript 1 function r e s u l t = t o t a l e r r o r ( n1 , n2 , n12 ) 2 r e s u l t = n1 n2 n12 ; 3 endfunction Scilab code Exa 7.2c Maximum likelihood estimator of a poisson param- eter 1 t o t a l _ p e o p l e = 857; 2 days = 20; 3 disp ( t o t a l _ p e o p l e days , ” The maximum l i k e l i h o o d estimate o f lambda ” ) Scilab code Exa 7.2d Number of traffic accidents 1 a c c i d e n t s = [4 0 6 5 2 1 2 0 4 3 ]; 2 lambda= mean (accidents) 3 disp ( cdfpoi ( ”PQ” , 2 , l a m b d a ) ) Scilab code Exa 7.2e Maximum likelihood estimator in a normal popula- tion 1 function [ u , s i g m a s q u a r e d ]= n o r m a l ( X , Xmean , n ) 2 u=Xmean; 7 sigmasquared= sqrt (( n e w s u m n ) ) ; 8 endfunction Scilab code Exa 7.2f Kolmogorovs law of fragmentation 4 upperlimlogX= log (upperlimX); 5 lowerlimlogX= log (lowerlimX); 7 logX = log (X) 8 samplemean= mean ( logX ) 9 samplesd= sqrt ( variance ( logX ) ) 10 d i s p ( samplemean ) 11 d i s p ( s a m p l e s d ) 12 prob = cdfnor ( ”PQ” , u p p e r l i m l o g X , s a m p l e m e a n , samplesd)- cdfnor ( ”PQ” , l o w e r l i m l o g X , s a m p l e m e a n ,samplesd) 13 disp ( prob ) Scilab code Exa 7.2g Estimating Mean of a Uniform Distribution 1 function r e s u l t = unif ( X , n ) 2 result= max ( X ) 2; 3 endfunction Scilab code Exa 7.3a Error in a signal 5 samplemean= mean (X); 6 lowerlim=samplemean-(1.96 sqrt ( var num ) ) 7 upperlim=samplemean+(1.96 sqrt ( var num ) ) 9 disp ( upperlim , ” t o ” , lowerlim , ” The 9 5 c o n f i d e n c e interval is”, Scilab code Exa 7.3b Confidence interval 5 samplemean= mean (X); 6 lowerlim=samplemean-(1.645 sqrt ( var num ) ) 7 upperlim=samplemean+(1.645 sqrt ( var num ) ) 9 disp (”to i n f i n i t y ” , lowerlim , ” The 95 u p p e r confidence interval is”) 10 disp ( upperlim , ” The 9 5 u p p e r confidence interval is minus infinity to”) Scilab code Exa 7.3c Confidence interval 4 samplemean= mean (X); 5 alpha=0.005; 6 zalpha= cdfnor ( ”X” , 0 , 1 ,1 - a l p h a , a l p h a ) ; 7 d i s p ( z a l p h a ) 8 lowerlim=samplemean-(zalpha sqrt ( var num ) ) 9 upperlim=samplemean+(zalpha sqrt ( var num ) ) 10 disp ( upperlim , ” t o ” , lowerlim , ” The 9 5 c o n f i d e n c e interval is”, 13 zalpha= cdfnor ( ”X” , 0 , 1 ,1 - a l p h a , a l p h a ) ; 14 lowerlim=samplemean-(zalpha sqrt ( var num ) ) 15 upperlim=samplemean+(zalpha sqrt ( var num ) ) 16 disp (”to i n f i n i t y ” , lowerlim , ” The 95 u p p e r confidence interval is”) 17 disp ( upperlim , ” The 9 5 u p p e r confidence interval is minus infinity to”) Scilab code Exa 7.3d Weight of a salmon 4 disp ( num , ” S a m p l e size s h o u l d be g r e a t e r t h a n ” ) ; Scilab code Exa 7.3e Error in a signal 1 X = [5 8.5 12 15 7 9 7.5 6.5 1 0 . 5 ] ; 2 num = 9; 3 meanX= mean (X); 4 X2 = X 2; 5 s2 = ( sum ( X2 ) - ( num ( m e a n X 2) ) ) ( num -1) ; 6 s= sqrt ( s2 ) ; 7 tval = cdft ( ”T” , num -1 , 0.975 , 0 . 0 2 5 ) ; 8 d i s p ( t v a l ) 9 u p p e r l i m = m e a n X + ( tval s ) sqrt ( num ) ; 10 l o w e r l i m = m e a n X - ( tval s ) sqrt ( num ) ; 11 disp ( upperlim , ” t o ” , lowerlim , ” The 9 5 c o n f i d e n c e interval is”, Scilab code Exa 7.3f Average resting pulse 1 X = [54 63 58 72 49 92 70 73 69 104 48 66 80 64 77]; 2 num = 15; 3 meanX= mean (X); 4 X2 = X 2; 5 s2 = ( sum ( X2 ) - ( num ( m e a n X 2) ) ) ( num -1) ; 6 s= sqrt ( s2 ) ; 7 tval = cdft ( ”T” , num -1 , 0.975 , 0 . 0 2 5 ) ; 8 d i s p ( t v a l ) 9 u p p e r l i m = m e a n X + ( tval s ) sqrt ( num ) ; 10 l o w e r l i m = m e a n X - ( tval s ) sqrt ( num ) ; 11 disp ( upperlim , ” t o ” , lowerlim , ” The 9 5 c o n f i d e n c e interval is”, 12 alpha=0.05; 13 tval = cdft ( ”T” , num -1 , 1 - alpha , a l p h a ) ; 14 lim = m e a n X + ( tval s ) sqrt ( num ) ; 15 disp ( lim , ” The 9 5 l o w e r confidence interval is from minus infinity to”) Scilab code Exa 7.3g Evaluating integrals 5 tval = cdft ( ”T” , num -1 , 1 - alpha , a l p h a ) ; 6 u p p e r l i m = m e a n X + ( tval s ) sqrt ( num ) ; 7 l o w e r l i m = m e a n X - ( tval s ) sqrt ( num ) ; 8 disp ( upperlim , ” t o ” , lowerlim , ” The 9 5 c o n f i d e n c e interval is”, Scilab code Exa 7.3h Thickness of washers 4 s2 = variance (X); 5 chi1 = cdfchi ( ”X” , num -1 ,0.95 , 0.05 ); 6 chi2 = cdfchi ( ”X” , num -1 ,0.05 , 0.95 ); 7 d i s p ( c h i 1 , chi2) 8 l o w e r l i m = ( num -1) s2 chi2 ; 9 u p p e r l i m = ( num -1) s2 chi1 ; 10 disp ( sqrt (upperlim),”to”, sqrt ( l o w e r l i m ) , ” The 9 0 confidence interval is” ) Scilab code Exa 7.4a Cable insulation 4 s i g m a B = 100; 5 a l p h a = 1 -0.95; 6 beta = a l p h a 2; 7 meanA= mean (A); 8 meanB= mean (B); 9 zbeta= cdfnor ( ”X” ,0 , 1 , 1 - beta , beta ) ; 11 lowerlim= mean (A)- mean (B)-(zbeta sqrt (( s i g m a A length (A))+(sigmaB length (B)))); 12 upperlim= mean (A)- mean (B)+(zbeta sqrt (( s i g m a A length (A))+(sigmaB length (B)))); 13 disp ( upperlim , ” t o ” , lowerlim , ” The 9 5 c o n f i d e n c e interval is” 15 beta = a l p h a ; 16 zbeta= cdfnor ( ”X” ,0 , 1 , 1 - beta , beta ) ; 18 upperlim= mean (A)- mean (B)+(zbeta sqrt (( s i g m a A length (A))+(sigmaB length (B)))); 19 disp ( upperlim , ”A v a l u e thatexceedthe difference of t h e means w i t h 95 c o n f i d e n c e is” Scilab code Exa 7.4b Battery production 1 t e c h 1 = [140 136 138 150 152 144 132 142 150 154 136 2 t e c h 2 = [144 132 136 140 128 150 130 134 130 146 128 5 mean1= mean (tech1); 6 mean2= mean (tech2); 7 d i s p ( mean1 ) 8 d i s p ( Sp ) 9 a l p h a = 0.9; 10 S1 = variance (tech1) ∗num1 ( num1−1) ; 11 S2 = variance (tech2) ∗num2 ( num2−1) ; 12 Sp = ((( num1 -1) S1 ) + (( num2 -1) S2 ) ) ( num1 + num2 -2) 13 Sp = sqrt ( Sp ) ; 14 num = (1 num1 ) +(1 num2 ) ; 15 b e t a a = (1 - a l p h a ) 2; 16 tval = cdft ( ”T” , num1 + num2 -2 , 1 - betaa , b e t a a ) ; 17 u p p e r l i m = mean1 - m e a n 2 + ( tval Sp ) sqrt ( num ) ; 18 l o w e r l i m = mean1 - m e a n 2 - ( tval Sp ) sqrt ( num ) ; 19 disp ( upperlim , ” t o ” , lowerlim , ” The 9 0 c o n f i d e n c e interval is” 20 a l p h a = 0.95 21 betaaa=1-alpha; 22 tval = cdft ( ”T” , num1 + num2 -2 , 1 - betaaa , b e t a a a ) ; 23 l o w e r l i m = mean1 - m e a n 2 - ( tval Sp ) sqrt ( num ) ; 24 disp (”the upperconfidence interval is”) 25 disp (”to i n f i n i t y ” , l ow er li m ) Scilab code Exa 7.5a Transistors 4 s a m p l e s i z e = 100; 5 l o w e r l i m = phat - ( z a l p h a sqrt ( phat (1 - phat ) samplesize)); 6 u p p e r l i m = phat + ( z a l p h a sqrt ( phat (1 - phat ) samplesize)); 7 disp ( upperlim , ” t o ” , lowerlim , ” The 9 5 c o n f i d e n c e interval is” Scilab code Exa 7.5b Survey 6 samplesize=( error z a l p h a ) 2( phat (1 - phat ) ) ; 7 disp (1 s a m p l e s i z e ) Scilab code Exa 7.5c Acceptable chips 1 i n i t i a l s a m p l e = 30; 2 a c c e p t a b l e = 26; 3 phat = a c c e p t a b l e i n i t i a l s a m p l e ; 4 error =0.052; 5 zalpha=2.58; 7 samplesize=( error z a l p h a ) 2( phat (1 - phat ) ) ; 8 finalsize= ceil (1 s a m p l e s i z e ) ; 9 a c c e p t a b l e n e w = 1040 + a c c e p t a b l e ; 10 phat = a c c e p t a b l e n e w f i n a l s i z e ;Chapter 6 Distribution of Sampling
Chapter 7 Parameter Estimation