0% found this document useful (0 votes)
2 views23 pages

PSLP Pages

The document outlines the Probability, Statistics, and Linear Programming Lab course at Maharaja Agrasen Institute of Technology, detailing its vision, mission, course objectives, and outcomes. It includes a comprehensive index of lab experiments, programming tasks related to matrix operations, and statistical distributions. The course aims to equip students with practical skills in probability, data analysis, and linear programming techniques.

Uploaded by

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

PSLP Pages

The document outlines the Probability, Statistics, and Linear Programming Lab course at Maharaja Agrasen Institute of Technology, detailing its vision, mission, course objectives, and outcomes. It includes a comprehensive index of lab experiments, programming tasks related to matrix operations, and statistical distributions. The course aims to equip students with practical skills in probability, data analysis, and linear programming techniques.

Uploaded by

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

PROBABILITY, STATISTICS AND LINEAR PROGRAMMING LAB FILE

PAPER CODE: BS-252

STUDENT NAME: Arjun Jain


ENROLLMENT NUMBER: 65414802724
GROUP: 4C9
PROGRAM: CSE
FACULTY NAME: Mr. Brahm Prakash

1
MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY

VISION

To attain global excellence through education, innovation, research, and work


ethics with the commitment to serve humanity.

MISSION

M1. To promote diversification by adopting advancement in science, technology,


management, and allied discipline through continuous learning.

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.

M4. To cultivate an environment supporting incubation, product development,


technology transfer, capacity building and entrepreneurship.

M5. To encourage faculty-student networking with alumni, industry, institutions,


and other stakeholders for collective engagement.

2
PROBABILITY, STATISTICS AND LINEAR PROGRAMMING LAB
PAPER CODE: BS-252

COURSE OBJECTIVE

1. To understand probability and probability distributions.

2. To understand methods of summarization and visualization of data.

3. To understand the use of various hypothesis-testing techniques.

4. To understand methods for solving linear programming problems.

COURSE OUTCOMES

At the end of the course student will be able to:

C.252.1 Apply probability concepts and describe probability distributions to solve

real-world problems. (Unit I)

C.252.2 Analyze joint distributions and visualize data using statistical tools.

(Unit II)

C.252.3 Evaluate hypothesis-testing techniques and apply regression and correlation

methods for analyzing data and making predictions. (Unit III)

C.252.4 Formulate and solve linear programming problems using mathematical

methods. (Unit IV)

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

Mapping of Course Outcomes with Program Outcomes


BS-252 Probability Statistics and Linear Programming Lab
PO PO PO PO PO PO PO PO PO PO PO PO
01 02 03 04 05 06 07 08 09 10 11 12
CO.BS-252.1 3 3 2 2 2 - - - 2 2 2 3
CO.BS-252.2 3 3 2 2 2 - - - 2 2 2 3
CO.BS-252.3 3 3 3 3 2 - - - 2 2 2 3
CO.BS-252.4 3 3 3 3 2 - - - 2 2 2 3

[4]
INDEX

No. Title of Lab Experiment Date 𝘙1 𝘙𝟐 𝘙𝟑 𝘙𝟒 Remarks/ Sign


Demonstrations of SCILAB to simple
programming concepts like addition,
1.
multiplication and transpose of matrices
(using loops)

2. Fitting of Binomial

Fitting of Poisson distribution after


3.
computing mean
4. Fitting Standard Normal Distribution

Compute covariance and correlation for two


5.
datasets
Write a program to visualize statistical data
6.
using histogram.

7. Fitting of regression lines

Perform a Chi-square test for goodness of fit


8.
for a given dataset
Program for solving Assignment Problem
9.
of three variables.
Program for forming first simplex table
10. for a three variable linear programming
problem.
Program for solving Transportation
11.
Problem of three variables.
Perform t-test for comparing means of two
12.
samples.

[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

disp("Enter elements of 2nd matrix: ");


for i = 1:r
for j = 1:c
B(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

Theory:The matrix 𝐴′ or 𝐴𝑇 obtained by interchanging rows and columns of a matrix 𝐴 is known


as its transpose.
1 3 5 1 2 0
𝐴 = ( 2 −1 4) 𝐴 = ( 3 −1 2)
𝑇

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

CODE & 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 𝑃(𝑟) = 𝑛𝐶𝑟𝑞𝑛−𝑟𝑝𝑟

∴ Binomial distribution may be given as(𝑞 + 𝑝)𝑟


CODE & OUTPUT

clc;
clear;
disp("Enter no. of observations: ");
n=input('n = ');

disp("Enter the value of x: ");


for i=1:n
X(1,i)=input('x = ');
end

disp("Enter no of frequency");
for j=1:n
F(1,j)=input('P(X) = ');
end

disp("Mean of the distribution is : ");


MEA=sum(F.*X)/sum(F);
disp(MEA);

p=MEA/n;
EF=sum(F)*binomial(p,n-1);

disp("Given frequencies: ");


disp(F);

disp("Expected frequencies: ");


disp(EF);

[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

Algorithm for fitting Poisson distribution after computing mean:


• Input the number of observations
• Enter the elements 𝑥𝑖 using loop
• Enter the corresponding frequencies 𝑓𝑖 using loop −𝜆𝜆 𝑥
• 𝑒 𝜆 𝑖
Calculate theoretical frequencies using 𝑃(𝑥 ) =
𝑖 𝑟!
• Display 𝑃(𝑥𝑖)
• Plot the graph between expected and theoretical frequencies using plot2d command

CODE & OUTPUT

clc;
disp("Enter no. of observations:")
n = input('n = ')

disp("enter the value of x:")


for i = 1:n
X(1, i) = input('x = ')
end

disp("Enter no. of frequency:")


for j = 1:n
F(1, j) = input('P(X=x) = ')
end

disp("Mean of the distribution")


M = sum(F .* X) / sum(F)
disp(M)

for i = 1:n
P(1, i) = sum(F) * exp(-M) * M^X(i) / factorial(X(i));
end

disp("Expected frequencies: ")


disp(P)

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

CODE & OUTPUT

clc; clear; close; clear all;

n = input("Enter the number of distributions: ");

m_values = zeros(1, n);


s_values = zeros(1, n);

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

colors = [2, 3, 5, 4, 6, 7];


legends = [];

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

plot2d(x', y', colors(modulo(k, length(colors)) + 1));

legends($+1) = msprintf("m=%.1f, s=%.1f", m, s);


end

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 ) = 𝜎𝜎 𝜎𝜎
𝑥 𝑦
𝑥 𝑦

where 𝑑𝑥 = 𝑥 − 𝑥 , 𝑑𝑦 = 𝑦 − 𝑦 , 𝑥, 𝑦 are means of 𝑥 and 𝑦 data values.


∑ 𝑑𝑥𝑑𝑦
𝜌 = 𝐶𝑜𝑣 (𝑥, 𝑦) = is the covariance between the variables 𝑥 and 𝑦.
𝑛

∑ 𝑑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]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy