Kishan PSLP
Kishan PSLP
TECHNOLOGY
LAB FILE
a = [1 23 3;1 4 6;1 5 6]
a = 3×3
1 23 3
1 4 6
1 5 6
b = [1 1 1;8 5 4;2 5 8]
b = 3×3
1 1 1
8 5 4
2 5 8
l = (a+b)
l = 3×3
2 24 4
9 9 10
3 10 14
m = (a - b)
m = 3×3
0 22 2
-7 -1 2
-1 0 -2
n = (a')
n = 3×3
1 1 1
23 4 5
3 6 6
o = (b')
o = 3×3
1 8 2
1 5 5
1 4 8
p = trace(a)
p = 11
p = 11
p = 11
q = trace(b)
q = 14
q = 14
q = 14
KISHAN KUMAR
08215603123
r = (a*b)
r = 3×3
191 131 117
45 51 65
53 56 69
% USING LOOP
a = 5;
for i =[1:5]
a
end
a = 5
a = 5
a = 5
a = 5
a = 5
sprintf('\n')
ans =
'
'
c = 3
c = 9
c = 27
c = 81
c = 243
sprintf('\n')
ans =
'
'
ans = 2
for i = [1:10]
sum = sum+i
end
sum = 1
sum = 3
KISHAN KUMAR
08215603123
sum = 6
sum = 10
sum = 15
sum = 21
sum = 28
sum = 36
sum = 45
sum = 55
sprintf('\n')
ans =
'
'
% Plotting
x=[0:0.1:10]
x = 1×101
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 ⋯
y=sin(x)
y = 1×101
0 0.0998 0.1987 0.2955 0.3894 0.4794 0.5646 ⋯
g=cos(x)
g = 1×101
1.0000 0.9950 0.9801 0.9553 0.9211 0.8776 0.8253 ⋯
plot(x,y,"m--",x,g,"c")
xlabel("x")
ylabel("sin(x)/cos(x)")
title("graph bw sin x and cos x")
grid on;
KISHAN KUMAR
08215603123
PROGRAM - 2
AIM: Demonstrating Bernoulli process. Specifically, WAP to find the probability that in case of a Bernoulli
process, where.
function[]=bernoulli()
q = 0.10;
p = 1-q;
n = 8;
x = 4;
prob = nchoosek(n, x)*p*(p ^ x) * (q ^ (n - x));
disp(prob)
end
KISHAN KUMAR
08215603123
PROGRAM - 3
AIM- FITTING OF POISSON DISTRIBUTION FOR GIVEN VALUE OF LAMDA
x=0:15;
y=poisspdf(x,4);
bar(x,y,1);
xlabel("Observation");
ylabel("Probability");
stairs(x,y);
xlabel("Observation");
ylabel("Cumulative Probability");
lamda=50;
x1=0:100;
y1=poisspdf(x1,lamda);
mu=lamda;
KISHAN KUMAR
08215603123
sigma=sqrt(lamda);
x2=0:0.1:100;
y2=normpdf(x2,mu,sigma);
bar(x1,y1,1)
hold on
plot(x2,y2,"LineWidth",2)
xlabel("Observation")
ylabel("Probability")
title("Poisson and Normal Pdf's")
legend("Poissson Distribution","Normal Distribution","Location","Northwest")
hold off
KISHAN KUMAR
08215603123
PROGRAM - 4
AIM: - FITTING OF BINOMIAL DISTRIBUTION FOR GIVEN n(trials) & p(success)
q=0.45
q = 0.4500
p=1-q
p = 0.5500
n=6
n = 6
x=3
x = 3
prob = nchoosek(n,x)*(p^x)*(q^(n-x));
disp(prob)
0.3032
q=0.25
q = 0.2500
p=1-q
p = 0.7500
n=10
n = 10
x=4
x = 4
prob = nchoosek(n,x)*(p^x)*p*(q^(n-x));
disp(prob)
0.0122
KISHAN KUMAR
08215603123
PROGRAM - 5
AIM: - Fitting of Normal Distribution when parameters are given.
load examgrades
x = grades(:,1);
pd = fitdist(x,'Normal')
pd =
NormalDistribution
Normal distribution
mu = 75.0083 [73.4321, 76.5846]
sigma = 8.7202 [7.7391, 9.98843]
% Estimate Parameters
load examgrades
x = grades(:,1);
[mu,s,muci,sci] = normfit(x)
mu = 75.0083
s = 8.7202
muci = 2×1
73.4321
76.5846
sci = 2×1
7.7391
9.9884
x = [-3:.1:3];
y = normpdf(x,0,1);
plot(x,y)
mu = 500
sigma = sqrt(a*b^2)
sigma = 50
y_norm = normpdf(x,mu,sigma);
plot(x,y_gam,'-',x,y_norm,'-.')
title('Gamma and Normal pdfs')
xlabel('Observation')
ylabel('Probability Density')
legend('Gamma Distribution','Normal Distribution')
pd = makedist('Lognormal','mu',5,'sigma',2)
pd =
LognormalDistribution
Lognormal distribution
mu = 5
sigma = 2
mean(pd)
ans = 1.0966e+03
histfit(logx)
pd_normal = fitdist(logx,'Normal')
pd_normal =
NormalDistribution
Normal distribution
mu = 5.00332 [4.96445, 5.04219]
sigma = 1.98296 [1.95585, 2.01083]
x = [-5:0.1:5];
y1 = tpdf(x,5);
y2 = tpdf(x,15);
z = normpdf(x,0,1);
plot(x,y1,'-.',x,y2,'--',x,z,'-')
legend('Student''s t Distribution with \nu=5', ...
'Student''s t Distribution with \nu=15', ...
'Standard Normal Distribution','Location','best')
xlabel('Observation')
ylabel('Probability Density')
title('Student''s t and Standard Normal pdfs')
KISHAN KUMAR
08215603123
KISHAN KUMAR
08215603123
PROGRAM - 6
AIM: - Program to plot exponential distribution for various parametric values.
pd =
ExponentialDistribution
Exponential distribution
mu = 671.663 [557.262, 825.504]
muhat = 671.6626
muci = 2×1
557.2625
825.5035
muhat2 = 671.6626
muci2 = 2×1
557.2625
825.5035
x = 0:0.1:10;
y = exppdf(x,2);
figure;
plot(x,y)
xlabel('Observation')
ylabel('Probability Density')
x = 0:0.1:10;
KISHAN KUMAR
08215603123
y = expcdf(x,2);
figure;
plot(x,y)
xlabel('Observation')
ylabel('Cumulative Probability')
x = 1:5;
lambda1 = exppdf(x,2)./(1-expcdf(x,2))
lambda1 = 1×5
0.5000 0.5000 0.5000 0.5000 0.5000
mu = 1:5;
lambda2 = exppdf(3,mu)./(1-expcdf(3,mu))
lambda2 = 1×5
1.0000 0.5000 0.3333 0.2500 0.2000
x2 = 5:5:25;
x3 = x2 + 1;
deltap = (expcdf(x3,10)-expcdf(x2,10))./(1-expcdf(x2,10))
deltap = 1×5
0.0952 0.0952 0.0952 0.0952 0.0952
KISHAN KUMAR
08215603123
PROGRAM - 7
AIM: - Fitting of multiple linear regression (MLR) curve through given data set and testing of goodness of fit
using mean error.
x1 = 100×1
3504
3693
3436
3433
3449
4341
4354
4312
4425
3850
⋮
x2= Acceleration
x2 = 100×1
12.0000
11.5000
11.0000
12.0000
10.5000
10.0000
9.0000
8.5000
10.0000
8.5000
⋮
y=MPG
y = 100×1
18
15
18
16
17
15
14
14
14
15
⋮
X=[ones(size(x1)) x1 x2 x1.*x2]
X = 100×4
104 ×
0.0001 0.3504 0.0012 4.2048
0.0001 0.3693 0.0011 4.2470
0.0001 0.3436 0.0011 3.7796
0.0001 0.3433 0.0012 4.1196
0.0001 0.3449 0.0010 3.6214
0.0001 0.4341 0.0010 4.3410
0.0001 0.4354 0.0009 3.9186
KISHAN KUMAR
08215603123
0.0001 0.4312 0.0008 3.6652
0.0001 0.4425 0.0010 4.4250
0.0001 0.3850 0.0008 3.2725
⋮
b=regress(y,X)
b = 4×1
37.1906
-0.0057
0.7261
-0.0002
scatter3(x1,x2,y,"filled")
hold on
x1fit=min(x1):100:max(x1)
x1fit = 1×30
1795 1895 1995 2095 2195 2295 ⋯
x2fit=min(x2):10:max(x2)
x2fit = 1×2
8 18
[X1FIT,X2FIT]=meshgrid(x1fit,x2fit)
X1FIT = 2×30
1795 1895 1995 2095 2195 2295 ⋯
1795 1895 1995 2095 2195 2295
X2FIT = 2×30
8 8 8 8 8 8 8 8 8 8 8 8 8 ⋯
18 18 18 18 18 18 18 18 18 18 18 18 18
YFIT = b(1)+b(2)*X1FIT+b(3)*X2FIT+b(4)*X1FIT.*X2FIT
YFIT = 2×30
30.2368 29.5258 28.8148 28.1038 27.3927 26.6817 25.9707 ⋯
34.4255 33.5433 32.6611 31.7789 30.8967 30.0145 29.1324
mesh(X1FIT,X2FIT,YFIT)
xlabel("Weight")
ylabel("Acceleration")
zlabel("MPG")
view(100,20)
hold off
KISHAN KUMAR
08215603123
KISHAN KUMAR
08215603123
PROGRAM - 8
AIM: - Solve LPP of three variable using Simplex method.
f = 1×3
-3 1 1
b = 3×1
2
10
5
lb = 3×1
0
0
0
ub=[];
% Solve the LPP using Simplex Method
[x,fval,exitflag]=linprog(f,A,b,[],[],lb,ub)
x1 = 1×20
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789 ⋯
x2=linspace(0,10,20)
x2 = 1×20
KISHAN KUMAR
08215603123
0 0.5263 1.0526 1.5789 2.1053 2.6316 3.1579 ⋯
[x1,x2]=meshgrid(x1,x2)
x1 = 20×20
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789 ⋯
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
0 0.2632 0.5263 0.7895 1.0526 1.3158 1.5789
⋮
x2 = 20×20
0 0 0 0 0 0 0 ⋯
0.5263 0.5263 0.5263 0.5263 0.5263 0.5263 0.5263
1.0526 1.0526 1.0526 1.0526 1.0526 1.0526 1.0526
1.5789 1.5789 1.5789 1.5789 1.5789 1.5789 1.5789
2.1053 2.1053 2.1053 2.1053 2.1053 2.1053 2.1053
2.6316 2.6316 2.6316 2.6316 2.6316 2.6316 2.6316
3.1579 3.1579 3.1579 3.1579 3.1579 3.1579 3.1579
3.6842 3.6842 3.6842 3.6842 3.6842 3.6842 3.6842
4.2105 4.2105 4.2105 4.2105 4.2105 4.2105 4.2105
4.7368 4.7368 4.7368 4.7368 4.7368 4.7368 4.7368
⋮
x3 = 20×20
2.0000 1.7368 1.4737 1.2105 0.9474 0.6842 0.4211 ⋯
2.5263 2.2632 2.0000 1.7368 1.4737 1.2105 0.9474
3.0526 2.7895 2.5263 2.2632 2.0000 1.7368 1.4737
3.5789 3.3158 3.0526 2.7895 2.5263 2.2632 2.0000
0 0 0 0 0 2.7895 2.5263
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
⋮
KISHAN KUMAR
08215603123
KISHAN KUMAR
08215603123
PROGRAM - 9
AIM: - Solve a Transportation problem of three variables.
KISHAN KUMAR
08215603123
KISHAN KUMAR
08215603123
PROGRAM - 10
AIM: - Solve an assignment problem of three variable.
c = 4×4
600 670 960 560
900 280 970 540
310 350 950 820
325 290 600 540
M=matchpairs(c,1000)
M = 4×2
3 1
2 2
4 3
1 4
C = 3×8
84 93 35 97 97 22 82 13
92 67 59 24 54 48 97 87
21 18 97 98 82 93 69 94
[M,uR,uC]=matchpairs(C,1e4)
M = 3×2
3 2
2 4
1 8
uR =
x = 3×3
4 10 16
4 10 16
4 10 16
y = 3×3
4 4 4
KISHAN KUMAR
08215603123
10 10 10
16 16 16
x0=x(:)'
x0 = 1×9
4 4 4 10 10 10 16 16 16
y0=y(:)'
y0 = 1×9
4 10 16 4 10 16 4 10 16
plot(x0,y0,"g*")
hold on
rng default
x1=x0+randn(size(x0))
x1 = 1×9
4.5377 5.8339 1.7412 10.8622 10.3188 8.6923 15.5664 ⋯
y1=y0+randn(size(y0))
y1 = 1×9
6.7694 8.6501 19.0349 4.7254 9.9369 16.7147 3.7950 ⋯
plot(x1,y1,"r*")
C=zeros(size(x).^2)
C = 9×9
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
for k=1:length(y1)
C(k,:)=vecnorm([x1(k)-x0; y1(k)-y0],2,1)'
end
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
KISHAN KUMAR
08215603123
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
15.2037 9.3130 3.7833 17.1539 12.2408 8.7988 20.7211
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
15.2037 9.3130 3.7833 17.1539 12.2408 8.7988 20.7211
6.9004 8.6551 13.1987 1.1267 5.3446 11.3075 5.1888
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
15.2037 9.3130 3.7833 17.1539 12.2408 8.7988 20.7211
6.9004 8.6551 13.1987 1.1267 5.3446 11.3075 5.1888
8.6703 6.3191 8.7571 5.9455 0.3249 6.0714 8.2173
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
15.2037 9.3130 3.7833 17.1539 12.2408 8.7988 20.7211
6.9004 8.6551 13.1987 1.1267 5.3446 11.3075 5.1888
8.6703 6.3191 8.7571 5.9455 0.3249 6.0714 8.2173
13.5530 8.1918 4.7464 12.7818 6.8409 1.4903 14.6652
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
15.2037 9.3130 3.7833 17.1539 12.2408 8.7988 20.7211
6.9004 8.6551 13.1987 1.1267 5.3446 11.3075 5.1888
8.6703 6.3191 8.7571 5.9455 0.3249 6.0714 8.2173
13.5530 8.1918 4.7464 12.7818 6.8409 1.4903 14.6652
11.5682 13.1257 16.8150 5.5702 8.3359 13.4144 0.4796
0 0 0 0 0 0 0
0 0 0 0 0 0 0
C = 9×9
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
15.2037 9.3130 3.7833 17.1539 12.2408 8.7988 20.7211
6.9004 8.6551 13.1987 1.1267 5.3446 11.3075 5.1888
8.6703 6.3191 8.7571 5.9455 0.3249 6.0714 8.2173
13.5530 8.1918 4.7464 12.7818 6.8409 1.4903 14.6652
11.5682 13.1257 16.8150 5.5702 8.3359 13.4144 0.4796
13.6699 12.3432 13.7784 8.6461 6.3438 8.8167 5.8858
0 0 0 0 0 0 0
C = 9×9
KISHAN KUMAR
08215603123
2.8211 3.2750 9.2462 6.1243 6.3461 10.7257 11.7922 ⋯
4.9987 2.2771 7.5752 6.2434 4.3794 8.4485 11.1792
15.2037 9.3130 3.7833 17.1539 12.2408 8.7988 20.7211
6.9004 8.6551 13.1987 1.1267 5.3446 11.3075 5.1888
8.6703 6.3191 8.7571 5.9455 0.3249 6.0714 8.2173
13.5530 8.1918 4.7464 12.7818 6.8409 1.4903 14.6652
11.5682 13.1257 16.8150 5.5702 8.3359 13.4144 0.4796
13.6699 12.3432 13.7784 8.6461 6.3438 8.8167 5.8858
20.6072 17.2853 15.6495 16.5444 12.1590 9.6935 13.9562
M=matchpairs(C,1)
M = 5×2
4 4
5 5
6 6
7 7
8 8
xc=[x0(M(:,2));x1(M(:,1))]
xc = 2×5
10.0000 10.0000 10.0000 16.0000 16.0000
10.8622 10.3188 8.6923 15.5664 16.3426
yc=[y0(M(:,2));y1(M(:,1))]
yc = 2×5
4.0000 10.0000 16.0000 4.0000 10.0000
4.7254 9.9369 16.7147 3.7950 9.8759
plot(xc,yc,"-o")
KISHAN KUMAR
08215603123