PSLP Lab File
PSLP Lab File
TECHNOLOGY
PRACTICLE FILE
PROBABLITY, STATISTCS AND LINEAR
PROGRAMMING
(BS-202)
Submitted by Submitted to
Name: Vipul Singh Name: Dr Maan
Prof. MaanSingh
Singh
A) Installation of Scilab
Visit the official Scilab website at www.scilab.org and go to the "Download" page. Choose
the appropriate version of Scilab for your operating system. Scilab is available for
Windows, Linux, and macOS.
Click on the download link to start the download process.
Choose the installation directory and follow the prompts to complete the installation
process.
After the installation is complete, you can launch Scilab from the Start menu on Windows, or
from the Applications folder on macOS.
When you launch Scilab for the first time, you may need to configure some settings, such as
the default working directory and the editor preferences.
B) Matrix Multiplication
Code:
clc;
mat1 (1 2 3; 4 5 6);
mat2 (2 3; 4 5; 6 7);
disp(mat1);
disp(mat2);
disp(mat1 mat2);
disp([4]*mat1);
disp([4 2]*mat1);
C) Multiplication Table Using For Loop Example
Code:
clc;
printf("\t");
for i=1:10
end
output :
D) Conditional Statement If-Else Example
Code:
Clc:
total = 80;
if per<50 then
else
end
Output :
E) Quadratic plot (y=x²)
Code:
clc;
function f = curve(x)
f = x^2;
endfunction
x = (1:10);
y = curve(x);
xlabel("Values of X","color","blue");
title('Quadratic Plot');
plot(x,y);
Output:
PROGRAM NO. - 2
Code:
clc;
printf("----- PROBABILITY OF TOSSING COIN N TIMES----\n");
N= input(" Enter the no of tosses: ");
head =0;
for i=1:N
var= round(rand(1));
if var == 1 then
head =head +1
end
proh(i)=head/i;
end
prot =1-proh;
plot(1:N,proh, 'b');,
plot(1:N,prot, 'r');
xlabel("--- Number of tosses----")
ylabel ("---Probability Distibution----")
title("Plot-Probability of Tossing a Coin N Times ");
legend('Head','Tail');
Output :
B) Probability Of Getting a Six Øn Rolling a Dice N Times
Code:
clc;
printf(" PROBABILITY OF ROLLING DICE N TIMES--\n");
N = input(" Enter the no of dice rolls: ");
gotsix = 0;
for i = 1:N
var = ceil(rand(1)*6);
if var == 6 then
gotsix = gotsix + 1;
end
pros(i) = gotsix/i;
end
plot(pros,'b');
xlabel('-- Number of Dice Rolls---','b');
ylabel('-- Probability Distribution---','r');
title(' Plot of getting Six');
Output :
PROGRAM NO. - 3
Code:
clc;
q=1-p;
r=factorial(n)/(factorial(y)* factorial(n-y))*(p^n)*(q^(n-y));
Output :
B) Let 'X' be binomial random variable with parameter n = 6 and p = 0.4. Find probability.
Code:
clc;
n=6;
p=0.4;
q=1-p;
r=factorial(n)/(factorial(y)* factorial(n-y))*(p^n)*(q^(n-y));
printf("Probability: %f",r);
Output:
Code:
clc;
n=6;
p=0.5;
q=1-p;
total=0;
for x = 4:6
end
D) The probability that a bomb dropped from a plane will hit the target is 1/5. If 6 bombs
are dropped, Find the probability:
Code:
clc;
n=6;
p=0.2;
q=1-p
y=2;
r=factorial(n)/(factorial(y)*factorial*(n-y))* (p^n)*(q^(n-y));
Output:
II) Atleast 2 bombs will hit the target.
Code:
clc;
n=6;
p=0.2;
q=1-p;
total=0;
for x=2:6;
end
printf("Probability that Atleast 2 bombs will hit the target: %f", total);
Output:
PROGRAM NO. - 4
7 coins are tossed and no. of heads are noted. The experiment is repeated 128 times and the
following distribution is obtained.
Frequency of Heads
Frequency 7 6 19 35 30 23 7 1 128
Fit the binomial distribution assuming nature of coin is not known, write Scilab code.
Code :
clc();
f = [7 6 19 35 30 23 7 1];
x= [0 1 2 3 4 5 6 7];
n = 7;
N = sum(f);
sigma = 0;
for i = 1:length(x)
end
mu = sigma/N;
p = mu/n;
q = 1-p;
var = n*p*q;
s = n;
r = 0;
select(choice)
case 1 then
p=0.5;
q=0.5;
data = [1 1 1 1 1 1 1];
for i = 1:length(data)
s = s -1;
r = r +1;
end
disp(data);
case 2 then
data= [1 1 1 1 1 1 1];
for i = 1:7
s = s-1;
r=r+1;
end
disp(data);
end
Output :
Probability:
i. P (X=0)
ii. P (X<3)
iii. P (X=4)
iv. P (X=8)
CODE:
clc;
lambda=4;
endfunction
code:
PROGRAM NO. - 6
a) Consider that on an average 1 House in 1000 Houses catches fire in a year in a district. If there
are 2000 houses in that district, find the probability that exactly 5 houses will catch fire.
CODE:
n=2000,
p=1/1000;
lambda = n* p;
function y = p(x)
y=(exp(-lambda)* (lambda^x))/factorial(x)
endfunction
output :
b) The Distribution of the number of road Accident per day in a city is Poisson with Mean
4.Find the number of days out of 100 days that have
i. No Accident
iii..Atmost 3 Accident
CODE:
clc;
l = 4;
printf("\nMean = %d\n",1);
N=100;
function y = p(x)
y = (exp(-l)*(l^x))/factorial(x);
endfunction
Output :
PROGRAM NO.- 7
Aim: Program to plot Normal distribution and Exponential Distribution for various
parametric values.
a) A Normal Curve Have Mean, μ=20 and Varience σ=10t Find the area between x=26, x=38 and
Also between x=15, x=40.
CODE:
clc;
mean = 20;
variance = 100;
SD=sqrt(variance);
rp=sqrt(2* %pi);
function y=z(x)
y=(x-mean)/SD;
endfunction
function y=p(x)
y=exp(-(z(x)^2)/2)/(SD*rp);
endfunction
r1=0;
r2=0;
for i=26:38
r1=r1+p(i);
end
for j=15:40
r2=r2+p(j);
end
x=linspace(-20,60,100);
plot(x,p);
OUTPUT:
CODE:
clc;
mean=1200;
lambda = 1/mean;
function y=f(x)
y = lambda*exp(-(lambda*x))
endfunction
r1=0;
r2=0;
r3=0;
for i=0:300
r1=r1+f(i);
end
for j=0:1500
r2=r2+f(j);
end
for u=1200:1500
r3=r3+f(u);
end
printf("\n Probability that the Computer Componenet: \n");
x=linspace(0,10000,100);
plot(x,f(x));
OUTPUT:
CODE:
clc;
N=100;
mean = 12;
SD=3;
rp=sqrt(2* %pi);
function y=z(x)
y=(x-mean)/SD;
endfunction
function y=p(x)
y=exp(-(z(x)^2)/2)/(SD*rp);
endfunction
r1=0;
r2=0;
r3=0;
for i=0:15
r1=r1+p(i);
end
for j=0:6
r2=r2+p(j);
end
for u =10:14
r3=r3+p(u);
end
x=linspace(0,24,50);
plot(x,p);
OUTPUT:
CODE:
clc;
x = [2 4 6 8];
y = [3 7 5 10];
x2 = x .* x; // Element-wise square of x
xy = x .* y; // Element-wise multiplication of x and y
n = length(x);
printf("\n Fitting of Linear Regression Line Through Given data set :\n");
disp("x = ", x);
disp("y = ", y);
disp("x2 = ", x2);
disp("xy = ", xy);
printf("\n Length, n = %d\n", n);
Ex = sum(x);
Ey = sum(y);
Ex2 = sum(x2);
Exy = sum(xy);
Aim: Fitting of Multiple Linear regression curve through given data set.
X 2 4 6 8
Y 3 7 5 10
CODE:
clc();
x = [2, 4, 6, 8];
y = [3, 7, 5, 10];
n = 4;
sigmax = sum(x);
sigmay = sum(y);
sigmax3 = sum(x.^3);
sigmax4 = sum(x.^4);
OUTPUT :