PSLP Pages
PSLP Pages
1
MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY
VISION
MISSION
M2. To foster moral values in students and equip them for developing sustainable
solutions to serve both national and global needs in society and industry.
M3. To digitize educational resources and process for enhanced teaching and
effective learning.
2
PROBABILITY, STATISTICS AND LINEAR PROGRAMMING LAB
PAPER CODE: BS-252
COURSE OBJECTIVE
COURSE OUTCOMES
C.252.2 Analyze joint distributions and visualize data using statistical tools.
(Unit II)
[3]
PROGRAM OUTCOMES (POs):
Engineering Knowledge: Apply the knowledge of basic sciences and engineering fundamentals to
1 solve engineering problems.
Problem Analysis: Analyze the complex engineering problems and give solutions related to
2 chemical & allied industries.
Design/ development of solutions: Identify the chemical engineering problems, design and formulate
3 solutions to solve both industrial & social related problems.
Conduct investigations of complex problems: Design & conduct experiments, analyze and
4 interpret the resulting data to solve Chemical Engineering problems.
Modern tool usage: Apply appropriate techniques, resources and modern engineering & IT tools for
5 the design, modeling, simulation and analysis studies.
The engineer and society: Assess societal, health, safety, legal and cultural issues and their
6 consequent responsibilities relevant to professional engineering practice.
Environment and sustainability: Understand the relationship between society, environment and work
7 towards sustainable development.
Ethics: Understand their professional and ethical responsibility and enhance their commitment
8 towards best engineering practices.
Individual and team work: Function effectively as a member or a leader in diverse teams, and be
9 competent to carry out multidisciplinary tasks.
Communication: Communicate effectively in both verbal & non-verbal and able to comprehend &
10 write effective reports.
Project management and finance: Understand the engineering and management principles to manage
11 the multidisciplinary projects in whatsoever position they are employed.
Life-long learning: Recognize the need of self education and life-long learning process in order to
12 keep abreast with the ongoing developments in the field of engineering.
[4]
INDEX
2. Fitting of Binomial
[5]
EXPERIMENT 1(A):PROGRAM FOR FINDING MATRIX ADDITION
Theory: A Matrix is a rectangular array of numbers, expressions or symbols, arranged in rows and
columns. Matrix addition is commutative and associative just like addition of arithmetic numbers.
Addition or subtraction can be performed on two matrices if and only if they are of same order.
𝑎11 𝑎12 𝑎13 𝑏11 𝑏12 𝑏13
𝑎
𝐴 = ( 21 𝑎22 𝑎23) 𝐵 = (𝑏21 𝑏22 𝑏23)
𝑎31 𝑎32 𝑎33 𝑏31 𝑏32 𝑏33
𝑎11 ± 𝑏11 𝑎12 ± 𝑏12 𝑎13 ± 𝑏13
Then 𝐴 ± 𝐵 = (𝑎21 ± 𝑏21 𝑎22 ± 𝑏22 𝑎23 ± 𝑏23)
𝑎31 ± 𝑏31 𝑎32 ± 𝑏32 𝑎33 ± 𝑏33
Matrix Addition Algorithm:
• Declare variables and initialize necessary variables
• Enter the elements of matrices row wise using loops
• Add the corresponding elements of the matrices using nested loops
• Print the resultant matrix as console output
CODE& OUTPUT
clc;
clear;
disp("Enter dimensions of matrices");
r = input("No. of rows: ");
c = input("No. of cols: ");
disp("Enter elements of 1st matrix: ");
A = zeros(r, c);
B = zeros(r, c);
for i = 1:r
for j = 1:c
A(i, j) = input("Enter element: ");
end
end
C = zeros(r, c);
for i = 1:r
for j = 1:c
C(i, j) = A(i, j) + B(i, j);
end
[6]
end
disp("Matrix A: ");
for i = 1:r
l = "";
for j = 1:c
l = l + string(A(i, j)) + " ";
end
disp(l);
end
disp("Matrix B: ");
for i = 1:r
k = "";
for j = 1:c
k = k + string(B(i, j)) + " ";
end
disp(k);
end
disp("Answer: ");
for i = 1:r
m = "";
for j = 1:c
m = m + string(C(i, j)) + " ";
end
disp(m);
end
[7]
[8]
EXPERIMENT 1(B):PROGRAM TO COMPUTE MATRIX MULTIPLICATION
Theory: Matrix product 𝐴𝐵 is possible only if number of columns in matrix 𝐴 are same as number
of rows in matrix 𝐵.
𝑎11 𝑎12 𝑎13 𝑏11 𝑏12
𝐴 = (𝑎 𝑎 𝑎 ) 𝐵 = (𝑏21 𝑏22 )
21 22 23
𝑏31 𝑏32
𝑐 = 𝑎11𝑏11 + 𝑎12 𝑏21 + 𝑎13𝑏31𝑐12 = 𝑎11𝑏12 + 𝑎12 𝑏22 + 𝑎13𝑏32
𝐶 = 𝐴𝐵 = ( 11 )
𝑐21 = 𝑎21𝑏11 + 𝑎22 𝑏21 + 𝑎23𝑏31𝑐22 = 𝑎21𝑏12 + 𝑎22 𝑏22 +
𝑎23𝑏32
Note that: (i) 𝐴𝑚×𝑛𝐵𝑛×𝑘 = 𝐶𝑚×𝑘
(ii) 𝐴𝐵 ≠ 𝐵𝐴 in general
Matrix Multiplication Algorithm:
• Declare variables and initialize necessary variables
• Enter the elements of matrices row wise using loops
• Check the number of rows and column of first and second matrices
• If number of rows of first matrix is equal to the
number of columns of second matrix, go to next step.
Otherwise, print ’Matrices are not conformable for
multiplication’ and abort.
• Multiply the matrices using nested loops
• Print the product in matrix form as console output
CODE & OUTPUT
clc;
clear;
disp("Enter dimensions of 1st matrix");
r1 = input("No. of rows: ");
c1 = input("No. of cols: ");
disp("Enter dimensions of 2nd matrix");
r2 = input("No. of rows: ");
c2 = input("No. of cols: ");
if c1 ~= r2 then
disp("Matrices are not conformable for multiplication");
abort;
end
disp("Enter elements of 1st matrix: ");
A = zeros(r1, c1);
B = zeros(r2, c2);
for i = 1:r1
for j = 1:c1
A(i, j) = input("Enter element: ");
end
] [10]
end
disp("Enter elements of 2nd matrix: ");
for i = 1:r2
for j = 1:c2
B(i, j) = input("Enter element: ");
end
end
C = zeros(r1, c2);
for i = 1:r1
for j = 1:c2
for k = 1:c1
C(i, j) = C(i, j) + A(i, k) * B(k, j);
end
end
end
disp("Matrix A: ");
for i = 1:r1
l = "";
for j = 1:c1
l = l + string(A(i, j)) + " ";
end
disp(l);
end
disp("Matrix B: ");
for i = 1:r2
k = "";
for j = 1:c2
k = k + string(B(i, j)) + " ";
end
disp(k);
end
disp("Answer: ");
for i = 1:r1
m = "";
for j = 1:c2
m = m + string(C(i, j)) + " ";
end
disp(m);
end
] [10]
[11]
EXPERIMENT 1(C):PROGRAM TO COMPUTE MATRIX TRANSPOSE
0 2 3 5 4 3
Matrix Transpose Algorithm:
• Declare variables and initialize necessary variables
• Enter the elements of matrix by row wise using loop
• Interchange rows to columns using nested loops
• Print the transposed matrix as console output
clc;
clear;
disp("Enter dimensions of matrix: ");
r = input("Rows: ");
c = input("Columns: ");
disp("Enter elements of matrix: ");
A = zeros(r, c);
for i = 1:r
for j = 1:c
A(i, j) = input("Enter element: ");
end
end
T = zeros(c, r);
for i = 1:r
for j = 1:c
T(j, i) = A(i, j);
end
end
disp("Matrix A: ");
for i = 1:r
l = "";
for j = 1:c
l = l + string(A(i, j)) + " ";
end
disp(l);
end
disp("Transpose of A: ");
for i = 1:c
m = "";
for j = 1:r
[13]
m = m + string(T(i, j)) + " ";
end
disp(m);
end
[13]
EXPERIMENT 2: PROGRAM FOR FITTING BINOMIAL DISTRIBUTION WITH GIVEN N AND P
Theory:A series of independent trials which result in one of the two mutually exclusive
outcomes ‘success’ or ‘failure’ such that the probability of the success (or failure) in each
trials is constant, then such repeated independent trials are called as ‘Bernoulli trials’. A
discrete random variable which results in only one of the two possible outcomes (success or
failure) is called Binomial variable.
Let there be 𝑛 independent finite trials in an experiment such that
i.Each trial has only two possible outcomes success and failure
ii.Probability of success (𝑝) and probability of failure (𝑞) are constant for all the trials and 𝑝 +
𝑞 = 1.
Then if a random variable 𝑋𝑋 denotes the number of successes in 𝑛 trials, then
𝑃(𝑋𝑋 = 𝑟) = 𝑛𝐶𝑟𝑝𝑟𝑞𝑛−𝑟or 𝑃(𝑟) = 𝑛𝐶𝑟𝑞𝑛−𝑟𝑝𝑟
clc;
clear;
disp("Enter no. of observations: ");
n=input('n = ');
disp("Enter no of frequency");
for j=1:n
F(1,j)=input('P(X) = ');
end
p=MEA/n;
EF=sum(F)*binomial(p,n-1);
[15]
plot2d3(0:n-1, F);
plot2d(0:n-1, EF);
[15]
[16]
EXPERIMENT 3: FITTING POISSON DISTRIBUTION AFTER COMPUTING MEAN
𝑒−𝜆𝜆𝜆𝑟𝑟
Theory: Poisson distribution with𝑃(𝑟) = is a limiting case of Binomial distribution, under
𝑟!
the conditions𝑖. 𝑛 → ∞ 𝑖𝑖. 𝑝 → 0 𝑖𝑖𝑖. 𝑛𝑝 = 𝜆 is finite
clc;
disp("Enter no. of observations:")
n = input('n = ')
for i = 1:n
P(1, i) = sum(F) * exp(-M) * M^X(i) / factorial(X(i));
end
plot2d3(X,F)
plot2d(X, P)
[18]
[18]
[19]
EXPERIMENT 4: PROGRAM FOR FITTING STANDARD NORMAL DISTRIBUTION
Theory:The normal distribution developed by Gauss is a continuous distribution and is very useful
in practical applications. It can be considered as the limiting form of the Binomial Distribution when
the number of trials (𝑛), is very large and neither 𝑝 nor𝑞is very small. The probability curve of a
normal variate𝑥 with mean𝜇 and standard deviation𝜎 is given by:
1 𝑥−𝜇 2
1
𝑝(𝑥) = 𝑒−2( 𝜎𝜎 ) , −∞ < 𝑥 < ∞
𝜎𝜎√2𝜋
Any normal variate 𝑥with mean 𝜇 and
standard deviation 𝜎 is changed to a
𝑥−𝜇
standard normal variate 𝑧 = , and
𝜎𝜎
hence the probability density function of 𝑧
is given by:
1 1 2
𝜙(𝑧) = 𝑒− 2𝑧 , −∞ < 𝑧 < ∞
√2𝜋
The normal distribution with
mean 𝜇 and variance 𝜎2 is
denoted by 𝑁(𝜇 , 𝜎2).
Adjoining figure shows a normal distribution curve for standard normal variate 𝑧.
for i = 1:n
m_values(i) = input(msprintf("Enter mean value for distribution %d: ", i));
s_values(i) = input(msprintf("Enter standard deviation for distribution %d: ", i));
end
scf(0);
gca().auto_clear = "off";
for k = 1:n
m = m_values(k);
s = s_values(k);
[21]
x = linspace(m - 4 * s, m + 4 * s, 100);
y = (1 / (s * sqrt(2 * %pi))) * exp(-((x - m).^2) / (2 * s^2));
xgrid();
legend(legends, "upper right");
xlabel("Values of X");
ylabel("Probability Density Function");
title("Normal Distributions");
[21]
EXPERIMENT 5: COMPUTE COVARIANCE AND CORRELATION FOR 2 DATASETS
Theory: Correlation is a measure of association between two variables; which may be dependent or
independent. Whenever two variables 𝑥 and 𝑦 are so related; that increase in one is accompanied by
an increase or decrease in the other, then the variables are said to be
correlated. Coefficient of correlation (𝑟) lies between −1 and +1,
i.e.−1 ≤ 𝑟 ≤ 1.
If 𝑟 is zero; no correlation between two variables, positive
correlation (0 < 𝑟 ≤ +1); when both variables increase or decrease
simultaneously, and negative correlation (−1 ≤ 𝑟 < 0); when
increase in one is associated with decrease in other variable and
vice-versa.
4.4 Karl Pearson Coefficient of Correlation
Coefficient of correlation (𝑟) between two variables 𝑥 and 𝑦 is defined as
𝐶𝑜𝑣𝑎𝑟𝑖𝑎𝑛𝑐𝑒 (𝑥,𝑦) ∑ 𝑑𝑥𝑑𝑦 𝜌
𝑟 = �𝑉𝑎𝑟𝑖𝑎𝑛𝑐𝑒 (𝑥)�𝑉𝑎𝑟𝑖𝑎𝑛𝑐𝑒 (𝑦) = �(∑ 𝑑2)(∑ 𝑑2 ) = 𝜎𝜎 𝜎𝜎
𝑥 𝑦
𝑥 𝑦
∑ 𝑑2 ∑ 𝑑2
Also 𝜎𝑥 = � 𝑛
𝑥
and 𝜎𝑦 = � 𝑦
𝑛
Algorithm:
1. Input two datasets as vectors.
2. Compute the mean of each dataset.
3. Calculate the covariance using the formula:
Cov(X, Y) = sum((X - mean(X)) .* (Y - mean(Y))) / (n - 1)
4. Compute the correlation using the formula: Corr(X, Y) = Cov(X, Y) / (std(X) *
std(Y))
5. Display the results.
CODE & OUTPUT
clc;clear;
disp("Enter the number of data points:");
n=input("");
disp("Enter the value of Dataset X:");
X=zeros(1,n);
for i=1:n
X(i)=input("");
end
disp("Enter the value of Dataset Y:");
Y=zeros(1,n);
for i=1:n
Y(i)=input("");
[23]
end
mean_X=sum(X)/n;
mean_Y=sum(Y)/n;
std_X=sqrt(sum((X-mean_X).^2)/n);
std_Y=sqrt(sum((Y-mean_Y).^2)/n);
cov_XY=sum((X-mean_X).*(Y-mean_Y))/n;
corr_XY=cov_XY/(std_X*std_Y);
disp("Mean of X:"),disp(mean_X);
disp("Mean of Y:"),disp(mean_Y);
disp("Covariance:"),disp(cov_XY);
disp("Correlation Coefficient:"),disp(corr_XY);
[23]