Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

PROBABILITY, STATISTICS AND LINEAR

PROGRAMMING LAB
PRACTICAL FILE

Faculty Name: Mr. Bhrama Prakaash

Name: Vivek Kumar Mishra


Roll No.: 00114822722
Semester: 4
Group: 4CST1

Maharaja Agrasen Institute Of Technology, Psp Area,


Sector – 22, Rohini, New Delhi - 110085
INDEX
Name: Vivek Kumar Mishra
Enrolment Number: 00114822722
Branch: Computer Science and Technology
Group: 4CST1

Date of Date of
S. No Experiment checking Signature Remark
Performance

Installation of Scilab and


demonstration of simple
1. programming concepts like
transpose of a matrix, matrix
addition, and matrix
multiplication (using loops).
Fitting of binomial distributions
2. after computing mean and
variance

3. Fitting of Poisson distributions


after computing Mean

4. Fitting of regression lines

5 To obtain the first four moments


about Mean

Solve a LPP of three variables


6
using Simplex Method

7. Solve a transportation problem of


three variables

8. Solve an Assignment problem of


three variables
EXPERIMENT NO 1
AIM: Installation of Scilab and demonstration of simple programming concepts like
transpose of a matrix, matrix addition, and matrix multiplication (using loops).

Source Code:

For Matrix Addition Output:

m=3;
n=3;
A=[1 2 3; 4 5 6; 7 8 9;]
B=[10 20 30; 40 50 60; 70 80 90;]
for i=1:m
for j=1:n
C(i,j)=A(i,j)+B(i,j);
end
end
disp("Matrix A: ");
disp(A);
disp("Matrix B: ");
disp(B);
disp("Sum Matrix C: ");
disp(C);
disp("Vivek Mishra")

For Matrix Transpose Output:

m=3;
n=3;
A=[1 2 3; 4 5 6; 7 8 9;]
B=[10 20 30; 40 50 60; 70 80 90;]
for i=1:m
for j=1:n
C(i,j)=A(j,i);
end
end
disp("Matrix A: ");
disp(A);
disp("Transpose of Matrix A : ");
disp(C);
disp("Vivek Mishra");

For Matrix Multiplication Output:


r1=3;
c1=3;
r2=3;
c2=3;
A=[1 2 3; 4 5 6; 7 8 9;]
B=[10 20 30; 40 50 60; 70 80 90;]
C=zeros(r1,c2);
if r2==c1 then
for i=1:r1
for j=1:c1
x=0;
for k=1:r2
x=x+(A(i,k)*B(k,j));
C(i,j)=x;
end
end
end
disp("Matrix A: ");
disp(A);
disp("Matrix B: ");
disp(B);
disp("Multiplication of A and B =
Matrix C: ");
disp(C);
disp("Vivek Mishra");
else(disp("Mathematical Error"))
end

For Subtraction: Output:


m=3;
n=3;
A=[10 20 30; 40 50 60; 70 80 90;]
B=[100 200 300; 400 500 600; 700 800 900;]
for i=1:m
for j=1:n
C(i,j)=B(i,j)-A(i,j);
end
end
disp("Matrix A: ");
disp(A);
disp("Matrix B: ");
disp(B);
disp("Subtraction Matrix C: ");
disp(C);
disp("Vivek Mishra");
EXPERIMENT NO 2
AIM: Fitting of Binomial Distributions after computing mean and varriance.
Source Code:
clc
clear all
disp("enter no of observation")
n=input('\')
disp("enter the vlaue of x")
for i=1:n
X(1,i)=input('\')
end
disp("enter no of frequency")
for j=1:n
F(1,j)=input('\')
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)
plot2d3(0:n-1, F)
plot2d(0:n-1,EF)
disp(“Vivek Mishra’”)
Output:
EXPERIMENT NO 3
AIM: Fitting of Poisson distributions after computing Mean
Source Code:
clc
clear
disp("Enter no of observation")
n=input('\')
disp("Enter the vlaue of x")
for i=1:n
X(1,i)=input('\')
end
disp("Enter no of frequency")
for j=1:n
F(1,j)=input('\')
end
disp("Mean of the distribution is")
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 are")
disp(P)
disp("Vivek Mishra")
plot2d(X,P)
Output:
EXPERIMENT NO 4
AIM: Fitting of regression lines

Source Code:

x = -30:30;

y = x.^3;
[a, b] = reglin(x, y);
plot(x, y, "red")
plot(x, a*x+b)
disp(“Vivek Mishra”)

Output:
EXPERIMENT NO 5
AIM: To obtain the first four moments about Mean
Source Code:
clc
n=input('Enter the no. of observations:');
disp('Enter the values of xi');
for i=1:n
x(i)=input('\');
end;
disp('Enter the corresponding frequences fi:')
sum=0;
for i=1:n
f(i)=input('\');
sum=sum+f(i);
end;
r=input('How many moments to be calculated:');
sum1=0
for i=1:n
sum1=sum1+f(i)*x(i);
end
A=sum1/sum;
//Calculate the average
disp('Average=%f\n',A);
for j=1:r
sum2 =0;
for i=1:n
y(i)=f(i)*(x(i)-A)^j;
sum2=sum2+y(i);
end
M(j)=(sum2/sum);//Calculate the moments
disp('Moment about mean M(%d)=%f\n',j,M(j));
end
sd=sqrt(M(2));//Calculate the standard deviation
disp('Standard deviation=%f\n',sd);
disp(“Vivek Mishra”);
Output:
EXPERIMENT NO 6
AIM: Solve a LPP of three variables using Simplex Method
Source Code:
function [f, g, ind]=rosenbrock(x, ind)
f=100*(x(2)-x(1)^2)^2+(1-x(1))^2;
g(1)=-400.*(x(2)-x(1)^2)*x(1)-2.*(1.-x(1))
g(2)=200.*(x(2)-x(1)^2)
endfunction
x0=[-1.21];
[x,f]=fminsearch(rosenbrock,x0);
disp("x = %s\n",strcat(string(x)," "));
disp("f = %e\n",f);
disp(“Vivek Mishra”)
Output:
EXPERIMENT NO 7
AIM: Solve a transportation problem of three variables
Source Code:
clc;
nCanneries = 2;
nWarehouses = 3;
ShippingCost = [2.5 1.7 1.8; 2.5 1.8 1.4];
demand = [300 300 300]';
supply = [350 650]';
nVar = nCanneries*nWarehouses;
lb = zeros(1,nVar);
for i = 1:nCanneries
indeX = (i-1)*nWarehouses+1:i*nWarehouses;
As(i,indeX) = ones(1,nWarehouses);
end
Bs = supply;
As
for i = 1:nWarehouses
indeX = i:nWarehouses:nVar;
Ad(i,indeX) = -1;
end
Bd = -demand;

A = cat(1,As,Ad);
b = cat(1,Bs,Bd);
Cost = zeros(nVar,1);
for i = 1:nCanneries
indeX = (i-1)*nWarehouses+1:i*nWarehouses;
Cost(indeX) = (ShippingCost(i,:)');
end
[xopt,fopt,exitflag,output,lambda] = linprog(Cost,A,b,[],[],lb,[]);
if exitflag == 0 then
disp(" Optimal Solution Found")

for i = 1:nCanneries
indeX = (i-1)*nWarehouses+1: i*nWarehouses;
X(i,1:nWarehouses) = xopt(indeX,1)';
end
Values = string(X); Markets(1,1) = [" "];
for j = 2:nWarehouses+1
Markets(1,j) = strcat(["M_",string(j-1)]);
End
for i = 1:nCanneries
Plants(i) = strcat(["P_",string(i)]);
end

table = [Markets; [Plants Values]];


f = gcf();
clf
as = f.axes_size;
ut = uicontrol("style","table",..
"string",table,..
"position",[150 as(2)-220 300 87])

matrix(ut.string,size(table))
elseif exitflag == 1 then
disp('Primal Infeasible')
elseif exitflag == 2 then
disp("Dual Infeasible")
else
disp("Technical error encountered")
end
disp(“Vivek Mishra”)

Output:
EXPERIMENT NO 8
AIM: Solve an Assignment problem of three variables
Source Code:
clc;
nProjects = 5;
nContractors = 3;
bids = [20 10000 10 9 15;18 12 13 8 16; 10000 11 12 7 17];
reqResource = [70 10000 40 30 50;65 40 40 35 55; 10000 45 35 40 50];
availResource = [120; 100; 70];

nVar = nProjects*nContractors;
IntCon = 1:nVar;
lb = zeros(1,nVar);
ub = ones(1,nVar);
beq = ones(nProjects,1);
for i = 1:nProjects
Aeq(i,i:nProjects:nVar) = 1;
b = availResource;
for j = 1:nContractors
index = (j-1)*nProjects+1:j*nProjects;
A(j,index) = reqResource(j,:);
end
for j = 1:nContractors
index = (j-1)*nProjects+1:j*nProjects;
Cost(index,1) = bids(j,:)';
end
options = list("time_limit", 2500);
[xopt,fopt,status,output] = symphonymat(Cost,IntCon,A,b,Aeq,beq,lb,ub,options);
disp(output)
for j = 1:nContractors
index = (j-1)*nProjects+1:j*nProjects;
Contractor(j).Project = string(find(xopt(index)==1));
end
ResolurceUtilized = ((A*xopt)./b)*100;

for j = 1:nContractors
disp(strcat(["Projects assigned to contractor",string(j)," : ", Contractor(j).Project],' '));
disp(strcat(["Resource utilized by contractor ",string(j)," :
",string(ResolurceUtilized(j)),"%"]));
end
disp(strcat(["Total cost : ",string(fopt)]))
disp(“Vivek Mishra”)

Output:

You might also like