Introduction To SCILAB: Ece Department (Maharaja Agrasen Institute of Technology)
Introduction To SCILAB: Ece Department (Maharaja Agrasen Institute of Technology)
– An interpreter
3. On the Console, Click the leftmost icon on the toolbar. The Editor named as SciNotes pops up.
Experiment-2
Theory
Probability defines the likelihood of occurrence of an event. There are many real-life
situations in which we may have to predict the outcome of an event. We may be sure or
not sure of the results of an event. In such cases, we say that there is a probability of this
event to occur or not occur. Probability generally has great applications in games, in
business to make probability-based predictions, and also probability has extensive
applications in this new area of artificial intelligence.
Probability Formula
The probability formula defines the likelihood of the happening of an event. It is the
ratio of favorable outcomes to the total favorable outcomes. The probability formula
can be expressed as,
where,
Probability formula with addition rule: Whenever an event is the union of two other
events, say A and B, then
Probability formula with the conditional rule: When event A is already known to
have occurred and the probability of event B is desired, then P(B, given A) = P(A and
B), P(A, given B). It can be vice versa in the case of event B.
P(B∣A) = P(A∩B)/P(A)
P(AandB)=P(A)⋅P(B).
P(A∩B) = P(A)⋅P(B∣A)
//Program of Tossing two dice and observing Probability of sum of their front face .
// for e . g . Probability of sum of two dice = 2 is 1/36 as there are 36 possibilities and
sum = 2 can// occur only one combination that is both face = 1
clc ;
clear ;
clf ;
N = 10000; // Number of tim e s t o s s i n g of d i ep e rf o rm e d
count = 0; // Coun te r f o r c o u n t i n g number of tim e ssum of die 11
for i = 1:N
y1 = ceil(rand(1)*6); // output of die 1 13
y2 = ceil(rand(1)*6); // output of die 2
if((y1+y2) == 3) // check for sum of front face of both die is == 3( change sum and)
count = count + 1;//increment the count value when sum = 3 occurs
end
prob1(i) = count/i; // no . of times sum of die = 3/ total no . trials
end
plot(prob1)
xlabel( 'Number of Trials');
ylabel( 'Probability');
title('Probability of getting sum of dots on faces of a dice to be 3');
//This program find probability of getting Head when a coin is tossed .
// Probability = 1/2 = 0.5 as there are two possible outcomes in coin tossing experiment
clc;
clear all;
clf;
a1 = 1000;
count1 = 0;
for i = 1:a1
x = round(rand(1));//round : the elements to nearest integer
//rand : returns a pseudorandom , scalar value drawn from a uniform
// distribution on the unit interval .
if(x==1)// HEAD− ’1 ’ , condition that detects ’ HEAD’ comes or not
count1 = count1 + 1;//increment the count value when head occurs
end
p(i)= count1/i;// probability of head occuring at ith trail
end
plot(1:a1,p)
// plot the prob . at ith trail ( plots discrete sequence )
xlabel( 'Number of Trials');
ylabel( 'Probability');
title( 'Probability of getting head');
Aim: Program to plot normal distributions and exponential distributions for various
parametric values.
Theory
Normal distribution
The Normal distribution was first discovered by the English Mathematician De-Moivre
in 1733, and he obtained this distribution as a limiting case of Binomial distribution and
applied it to problems arising in the game of chance. In 1774 Laplace used it to estimate
historical errors and in 1809 it was used by Gauss as the distribution of errors in
Astronomy. Thus throughout the 18th and 19th centuries efforts were made for a
common law for all continuous distributions which was then known as the Normal
distribution.
{ }
−λ x
f x ( X )= λ e x >0
0 otherwise
Output
clc;
clear all;
lambda = 2;
X = grand(1000,1,"exp", 1/lambda);//Exponential data generation using function
Xmax = max(X);
histplot(40, X, style=2)
x = linspace(0,max(Xmax),100)';
plot2d(x,lambda*exp(-lambda*x),strf="000",style=5)
legend(["exponential random sample histogram" "exact density curve"]);
xlabel('sample value');
ylabel( 'Exponential output values');
title('Exponential distributed data');
Expo_true_mean=mean(X)
mprintf( 'Exponential True Mean = %f',Expo_true_mean)
Expo_true_var=variance(X)
mprintf( '\n Exponential True Variance = %f', Expo_true_var)
//Mean and variance calcultaion using formula
ex_mean=integrate('x*lambda*exp(-lambda*x)', 'x', 0,100);
ex_fsq=integrate('(x^2)*lambda*exp(-lambda*x)', 'x', 0,100);
ex_var = ex_fsq - ex_mean.^2
mprintf( '\n Exponential Calculated Mean = %f ', ex_mean)
mprintf( '\n Exponential Calculated Variance = %f', ex_var)
Output:
Viva Voce:
Theory
There are many probability distributions of which some can be fitted more closely to the
observed frequency of the data than others, depending on the characteristics of the
variables. Therefore one needs to select a distribution that suits the data well.
A set of three similar coins are tossed 100 times with the following results
POISSION DISTRIBUTION
Introduction
In a Binomial distribution with parameter n and p if the exact value of n is not definitely
known and if p is very small then it is not possible to the find the binomial
probabilities .Even if n is known and it is very large, calculations are tedious. In such
situations a distribution called Poisson distribution is very much useful.
Conditions:
ii. The probability of a success ‘p’ for each trial is very small i.e.,p→ 0
Definition
(i) Poisson distribution is a discrete distribution i.e., X can take values 0, 1, 2,…
(ii) p is small, q is large and n is indefinitely large i.e., p →0 q →1 and n→3 and np is
finite
(iii) Values of constants : (a) Mean = λ = variance (b) Standard deviation = √λ (c)
Skewness = 1/ √λ (iv) Kurtosis =1/ λ
(v) If X and Y are two independent Poisson variates, X+Y is also a Poisson variate.
(vi) If X and Y are two independent Poisson variates, X-Y need not be a Poisson
variate.
(viii) It is leptokurtic.
Example 10.35
Solution:
Result:
In fitting a Normal distribution to the observed data, given in class intervals, we follow
the following procedure:-
Example 10.36
Find expected frequencies for the following data, if its calculated mean and standard
deviation are 79.945 and 5.545.
Solution: