PSLP Lab Codes | Probability, Statistics and Linear Programming Lab

 disp('Jai Oberoi 00896402722 4C11');

m=input("enter number of rows of the Matrix: "); 
n=input("enter number of columns of the Matrix: "); 
disp('enter the first Matrix') 
for i=1:m 
for j=1:n 
A(i,j)=input('\'); 
end 
end 
disp('enter the second Matrix') 
for i=1:m 
for j=1:n 
B(i,j)=input('\'); 
end 
end 
for i=1:m 
for j=1:n 
C(i,j)=A(i,j)+B(i,j); 
end 
end 
disp('The first matrix is') 
disp(A) 
disp('The Second matrix is') 
disp(B) 
disp('The sum of the two matrices is') 
disp(C)


disp('Jai Oberoi 00896402722 4C11');
m=input ("Enter number of rows of the first Matrix: "); 
n=input ("Enter number of columns of the first Matrix: "); 
p=input ("Enter number of rows of the second Matrix: "); 
q=input ("Enter number of columns of the second Matrix: "); 
if n==p 
disp('Matrices are conformable for multiplication') 
else 
disp('Matrices are not conformable for multiplication') 
break; 
end 
disp('enter the first Matrix') 
for i=1:m 
for j=1:n 
A(i,j)=input('\'); 
end 
end 
disp('enter the second Matrix') 
for i=1:p 
for j=1:q 
B(i,j)=input('\'); 
end 
end 
C=zeros(m,q); 
for i=1:m 
for j=1:q 
for k=1:n 
C(i,j)=C(i,j)+A(i,k)*B(k,j); 
end 
end 
end 
disp('The first matrix is') 
disp(A) 
disp('The Second matrix is') 
disp(B) 
disp('The product of the two matrices is') 
disp(C)


disp('Jai Oberoi 00896402722 4C11'); 
m=input("Enter number of rows of the Matrix: "); 
n=input("Enter number of columns of the Matrix: "); 
disp('Enter the Matrix') 
for i=1:m 
for j=1:n 
A(i,j)=input('\'); 
end 
end 
B=zeros(n,m); 
for i=1:n 
for j=1:m 
B(i,j)=A(j,i) 
end 
end 
disp('Entered matrix is') 
disp(A) 
disp('Transposed matrix is') 
disp(B)


disp('Jai Oberoi 00896402722 4C11')
disp("enter no of observation") 
n=input('\') 
disp("value of p") 
p=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 
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('Jai Oberoi 00896402722 4C11');
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('Jai Oberoi 00896402722 4C11');
disp("Mean of the distribution is") 
m=input('\') 
disp("enter no of observation") 
n=input('\') 
disp("enter the value of x") 
for i=1:n 
X(1,i)=input('\') 
end 
disp("enter no of frequency") 
for j=1:n 
F(1,j)=input('\') 
[18] 
end 
for i=1:n 
P(1,i)=sum(F)*exp(-m)*m^(X(i))/factorial(X(i)) 
end 
disp("Expected frequencies are") 
disp(P) 
plot2d(X,P)


disp('Jai Oberoi 00896402722 4C11');
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) 
plot2d(X,P)


m_values=[0.5,1.5,-1.5]; 
s_values=[1,1.5,2]; 
for m=m_values 
for s=s_values 
t=grand (1,100,"nor",m,s); 
x=linspace(m-4*s,m+4*s,100); 
y=(1/(s*sqrt(2*%pi)))*exp(-(x-m).^2/(2*s^2)); 
plot(x,y); 
hold on; 
xgrid(); 
end 
end 
legend("m=0.5,s=1", "m=1.5,s=1.5", "m=-1.5, s=2"); 
xlabel("x"); 
ylabel("Probability density function"); 
title("Normal distributions for various parametric values");


disp('Jai oberoi 00896402722 4C11')
n=input('Enter the number of data ponts:')
printf('Enter the values of xi')
for i=1:n
x(i)=input('\')
end
printf('Enter the value of yi')
for i=1:n
    y(i)=input('\');
end
sumx=0;
sumy=0;
sumxy=0;
sumx2=0;
for i=1:n
    sumx=sumx+x(i);
    sumx2=sumx2+x(i)*x(i);
    sumy=sumy+y(i);
    sumxy=sumxy+x(i)*y(i);
end
a=((sumx2*sumy-sumx*sumxy)*1.0/(n*sumx2-sumx*sumx)*1.0);
b=((n*sumxy-sumx*sumy)*1.0/(n*sumx2-sumx*sumx)*1.0);
printf('The line is Y=%3.3f+%3.3f X',a,b)
x=(0:2:20)
plot(x,a+b*x)

Comments

Popular Posts