0% found this document useful (0 votes)
272 views

Introduction To SCILAB: Ece Department (Maharaja Agrasen Institute of Technology)

Here are the key points about normal distributions: - A normal distribution, also called a Gaussian distribution, is a continuous probability distribution that is symmetric around a central peak. - It is characterized by two parameters: the mean (μ) and the standard deviation (σ). - About 68% of the values lie within 1 standard deviation of the mean, 95% within 2 standard deviations, and 99.7% within 3 standard deviations. - The normal distribution is useful for modeling many natural phenomena because of the central limit theorem, which states that the sum of independent random variables will tend toward a normal distribution even if the individual variables themselves are not normally distributed. - Areas under the normal distribution curve can be used

Uploaded by

radha gulati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
272 views

Introduction To SCILAB: Ece Department (Maharaja Agrasen Institute of Technology)

Here are the key points about normal distributions: - A normal distribution, also called a Gaussian distribution, is a continuous probability distribution that is symmetric around a central peak. - It is characterized by two parameters: the mean (μ) and the standard deviation (σ). - About 68% of the values lie within 1 standard deviation of the mean, 95% within 2 standard deviations, and 99.7% within 3 standard deviations. - The normal distribution is useful for modeling many natural phenomena because of the central limit theorem, which states that the sum of independent random variables will tend toward a normal distribution even if the individual variables themselves are not normally distributed. - Areas under the normal distribution curve can be used

Uploaded by

radha gulati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction to SCILAB

• Scilab is matrix-oriented, just like SCILAB

• It allows matrix manipulations, 2D/3D plotting, animation, etc.

• It is an open programming environment

• Main components of Scilab are:

– An interpreter

– Libraries of functions (procedures, macros)

– Developed by French institutions and companies

• Case Sensitive Language

ECE DEPARTMENT (MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY)


2

ECE DEPARTMENT (MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY)


3

ECE DEPARTMENT (MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY)


4

ECE DEPARTMENT (MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY)


5

Common Procedure to all Programs in SCILAB

1. Click on the SCILAB Icon on the desktop.

2. SCILAB Console window opens.

3. On the Console, Click the leftmost icon on the toolbar. The Editor named as SciNotes pops up.

4. Start typing commands on SciNotes.

5. Now SAVE the file in directory with sce/sci extension

6. Finish by running (executing) the script by a Click the Execute icon

Experiment-2

Aim: Program for demonstration of theoretical probability limit


Software Used: Scilab 5.5.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.

The probability of an event can be calculated by probability formula by simply dividing


the favorable number of outcomes by the total number of possible outcomes. The value
of the probability of an event to happen can lie between 0 and 1 because the favorable
number of outcomes can never cross the total number of outcomes. Also, the favorable
number of outcomes cannot be negative.

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,

P(B) is the probability of an event 'B'.

n(B) is the number of favorable outcomes of an event 'B'.

n(S) is the total number of events occurring in a sample space.

Different Probability Formulas

Probability formula with addition rule: Whenever an event is the union of two other
events, say A and B, then

P(A or B) = P(A) + P(B) - P(A∩B)


P(A ∪ B) = P(A) + P(B) - P(A∩B)
Probability formula with the complementary rule: Whenever an event is the
complement of another event, specifically, if A is an event, then

P(not A) = 1 - P(A) or P(A') = 1 - P(A).


P(A) + P(A′) = 1.

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)

Probability formula with multiplication rule: Whenever an event is the intersection


of two other events, that is, events A and B need to occur simultaneously. Then

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');

Conclusion: The theoretical value of probability lies between 0 and 1


Experiment-3

Aim: Program to plot normal distributions and exponential distributions for various
parametric values.

Software Used: Scilab 5.5.2

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.

Properties of Normal Distribution


Exponential Distribution

In Probability theory and statistics, the exponential distribution is a


continuous probability distribution that often concerns the amount of time until some
specific event happens. It is a process in which events happen continuously and
independently at a constant average rate. The exponential distribution has the key
property of being memoryless. The exponential random variable can be either more
small values or fewer larger variables. For example, the amount of money spent by the
customer on one trip to the supermarket follows an exponential distribution.

Exponential Distribution Formula


The continuous random variable, say X is said to have an exponential distribution, if it
has the following probability density function:
Where

{ }
−λ x
f x ( X )= λ e x >0
0 otherwise

λ is called the distribution rate.

Mean and Variance of Exponential Distribution


The mean of the exponential distribution is 1/λ and the variance of the exponential
distribution is 1/λ2.
Code:

function f=normal_distribution(x, mu, s)


p1 = -.5 * ((x - mu)/s) .^ 2;
p2 = (s * sqrt(2*%pi));
f = exp(p1) ./ p2;
end
a = -100; b = 100;
x = a + (b-a) * rand(1, 500);
m = (a + b)/2;
s = 30;
f = normal_distribution(x, m, s);
plot(x,f,'.')
title('Bell Curve')
xlabel('Randomly produced numbers')
ylabel('Normal Distribution')

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:

Exponential True Mean = 0.508601

Exponential True Variance = 0.261809

Exponential Calculated Mean = 0.500000

Exponential Calculated Variance = 0.250000

Viva Voce:

What is a normal distribution in statistics?


A probability function that specifies how the values of a variable are distributed is called the normal
distribution. It is symmetric since most of the observations assemble around the central peak of the curve. The
probabilities for values of the distribution are distant from the mean narrow off evenly in both directions.

What does normal distribution mean?


In statistics (and in probability theory), the Normal Distribution, also called the Gaussian Distribution, is the
most important continuous probability distribution. Sometimes it is also called a bell curve.
What is a normal distribution used for?
A normal distribution is significant in statistics and is often used in the natural sciences and social arts to
describe real-valued random variables whose distributions are unknown.

What are the characteristics of a normal distribution?


The essential characteristics of a normal distribution are:
It is symmetric, unimodal (i.e., one mode), and asymptotic.
The values of mean, median, and mode are all equal.
A normal distribution is quite symmetrical about its center. That means the left side of the center of the peak is
a mirror image of the right side. There is also only one peak (i.e., one mode) in a normal distribution.

How do you know if data is normally distributed?


A histogram presents a useful graphical representation of the given data. When a histogram of distribution is
superimposed with its normal curve, then the distribution is known as the normal distribution.

What is meant by exponential distribution?


The exponential distribution is a probability distribution function that is commonly used to measure
the expected time for an event to happen.

What is the difference between the Poisson distribution and exponential


distribution?
Poisson distribution deals with the number of occurrences of events in a fixed period of time, whereas
the exponential distribution is a continuous probability distribution that often concerns the amount of
time until some specific event happens.

What is the mean and the variance of the exponential distribution?


The mean of the exponential distribution is 1/λ and the variance of the exponential distribution is 1/λ . 2

Why is the exponential distribution memoryless?


The key property of the exponential distribution is memoryless as the past has no impact on its future
behaviour, and each instant is like the starting of the new random period.

What does lambda mean in the exponential distribution?


The lambda in exponential distribution represents the rate parameter, and it defines the mean number
of events in an interval.
Experiment-6

Aim: Fitting of Poisson distributions for given value of lambda.


Software Used: Scilab 5.5.2

Theory

Fitting of Binomial, Poisson and Normal distributions


Introduction
 

Fitting of probability distribution to a series of observed data helps to predict the


probability or to forecast the frequency of occurrence of the required variable in a
certain desired interval.

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.

Fitting of Binomial Distribution


 

When a Binomial distribution is to be fitted to an observed data the following procedure


is adopted:-

A set of three similar coins are tossed 100 times with the following results

Fit a binomial distribution and estimate the expected frequencies.


Solution :
Solution :

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.

In 1837 French mathematician Simeon Dennis Poisson derived the distribution as a


limiting case of Binomial distribution. It is called after his name as Poisson distribution.

Conditions:

i. The number of trails ‘n’ is indefinitely large i.e., n→ ∞

ii. The probability of a success ‘p’ for each trial is very small i.e.,p→ 0

iii. np= λ is finite

iv. Events are Independent

Definition

 A random variable X is said to follow a Poisson distribution if it assumes only non-


negative integral values and its probability mass function is given by
 

Characteristics of Poisson Distribution

(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/ λ

(iv) It may have one or two modes

(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.

(vii) Poisson distribution is positively skewed.

(viii) It is leptokurtic.

Fitting of Poisson Distribution


 
When a Poisson distribution is to be fitted to an observed data the following procedure
is adopted:

Example 10.35

The following mistakes per page were observed in a book

Fit a Poisson distribution and estimate the expected frequencies.

Solution:
Result:

Fitting of Normal Distribution


 

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:

Given μ= 79.945, σ = 5.545, and N = 1000

 Hence the equation of Normal curve fitted to the data is

Theoretical Normal frequencies can be obtained as follows:

You might also like