Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Names:

1. Muhammad Saad Saleem - 336893

Question 1
i.
We proceed by simply defining the functions and ploting them:

%defining our interval


x=-5:.05:5;
%defining our parameters
means=[-2,0,2];
sigmas=[0.25,0.5,0.75];
%defining normal functions with loop
for i=1:3
for j=1:3
eval("y"+((i-1)*3+j)+"=makedist('Normal'" + ...
",'mu',means(i),'sigma',sigmas(j));");
end
end
%plotting them one by one
pdf_normal = pdf(y1,x);
plot(x,pdf_normal,'LineWidth',2);
xlabel("Population");
ylabel("Probability distribution");
hold on
axis([-5,5,0,2]);
for i=2:9
pdf_normal = pdf(eval("y"+string(i)),x);
plot(x,pdf_normal,'LineWidth',2);
hold on
end
strr=("'$\mu=-2.00,\sigma=0.25$'");
for i=1:3
for j=1:3
if i==1 && j==1
else
strr=strr+","+sprintf("'$%s=%.2f,%s=%.2f" + ...
"$'","\mu",means(i),"\sigma",sigmas(j));
end
end
end
eval(sprintf("legend(%s,'Interpreter','Latex')",strr));
legend('boxoff')
hold off

ii.
We repeat what we did last time:

x=-3:.05:3;
pd=makedist("Normal","mu",0,"sigma",1);
y = pdf(pd,x);
plot(x,y,'LineWidth',2);
axis([-3,3,0,0.5]);
xlabel("Population");
ylabel("Probability distribution");
iii.
We define the cumulative distribution function and plot it.

x=-2:0.05:2.5;
y=cdf("Normal",x,0.25,1);
plot(x,y,'LineWidth',2);
axis([-2,2.5,0,1]);
xlabel("Population");
ylabel("Cumulative Probability distribution");
v
We proceed as we do always:

x=-3:0.05:3;
pd=makedist("Normal");
y=cdf(pd,x);
plot(x,y,'LineWidth',2);
axis([-3,3,0,1]);
xlabel("Population");
ylabel("Cumulative Probability distribution");

vi
We define both cdfs and compare their results:

%defining original cfd


x=2.44;
mu=0.8;
sigma=2;
pdo=makedist("Normal","mu",mu,"sigma",sigma);
fprintf("The cumulative distribution from F(x) " + ...
"is %.4f while standardized distribution gives" + ...
" %.4f",cdf(pdo,x),cdf(pd,(x-mu)/sigma));

The cumulative distribution from F(x) is 0.7939 while standardized distribution gives 0.7939

Our value of standardized z lies at 0.82 giving 79.39%. From Table A-8 we receive z=0.806 for
F(z)=79% while z=0.842 for F(z)=80%. We perform interpolation to receive a value of 0.82004 for
79.39% which is close enough. On the Casio fx-991ES PLUS we integrate the Normal PDF from -
1000 to 0.82 and we get 0.7939.

vii.
fprintf("The cumulative distribution at 0.01 is %.4f, at 0.5 is %.4f," + ...
"at 2 is %.4f and at 3 is
%.4f",cdf(pd,0.01),cdf(pd,0.5),cdf(pd,2),cdf(pd,3));

The cumulative distribution at 0.01 is 0.5040, at 0.5 is 0.6915,at 2 is 0.9772 and at 3 is


0.9987

The tables correspond exactly to the ones received from Table A-7 and from our calculator.

viii.
We evaluate the left hand side and right hand side separately and print them in juxtaposition:

fprintf("The left hand side of the equation is %.4f while the right hand" + ...
"side is %.4f",cdf(pd,2.12),1-cdf(pd,-2.12));

The left hand side of the equation is 0.9830 while the right handside is 0.9830

Both the sides are equal up to fourth decimal place.

ix:
We use the inverse cumulative distribution function for verification:

fprintf("For F(z)=0.95 z is %.3f",icdf(pd,0.95));

For F(z)=0.95 z is 1.645

x.
If 𝐷(𝑧)=Φ(𝑧)−Φ(−𝑧)=0.95 then Φ(𝑧)=0.975, we can verify by using icdf:

fprintf("For D(z)=0.95 z is %.3f",icdf(pd,0.975));

For D(z)=0.95 z is 1.960

Question 2:
i.
As in the first question we define multiple distributions and plot them simultaneously:

%defining our interval


x=-5:.05:5;
%defining our parameters
ms=[1,2,3,5,30,40];
%defining distribution functions with loop
for i=1:6
eval("y"+i+"=tpdf(x,"+ms(i)+");");
end
plot(x,y1,'LineWidth',2,'LineStyle','--');
xlabel("Population");
ylabel("Probability distribution");
hold on
axis([-5,5,0,0.41]);
linestyles=["':'","'-'","'--'","'-.'","':'"];
for i=2:6
eval("plot(x,"+"y"+i+","+"'LineWidth',2,'LineStyle',"+linestyles(i-
1)+");");
hold on
end
strrt="'m=1'";
for i=2:6
strrt=strrt+",'m="+ms(i)+"'";
end
eval(sprintf("legend(%s)",strrt));
legend('boxoff')
hold off

We observe that m=30 and m=40 have almost conincident curves.

ii.
We plot again:
%defining a bigger interval
x=-7:.05:7;
%defining cumulative distribution functions with loop
for i=1:6
eval("y"+i+"=tcdf(x,"+ms(i)+");");
end
plot(x,y1,'LineWidth',2,'LineStyle','--');
xlabel("Population");
ylabel("Cumulative Probability distribution");
hold on
axis([-7,7,0,1]);
linestyles=["':'","'-'","'--'","'-.'","':'"];
for i=2:6
eval("plot(x,"+"y"+i+","+"'LineWidth',2,'LineStyle',"+linestyles(i-
1)+");");
hold on
end
eval(sprintf("legend(%s)",strrt));
legend('boxoff')
hold off

iii.
We use the tcdf function we used previously:

fprintf("The value of t-distribution with 9 degrees of freedom at x=1.83 is


%.2f",tcdf(1.83,9));
The value of t-distribution with 9 degrees of freedom at x=1.83 is 0.95

iv.
We use the tinv function for this purpose:

fprintf("The value of z for t-distribution with 2 degrees of freedom which


returns " + ...
"0.99 is %.2f",tinv(0.99,2));

The value of z for t-distribution with 2 degrees of freedom which returns 0.99 is 6.96

Question 3:
i.
As in the first question we define multiple distributions and plot them simultaneously:

%defining our interval


x=0:.05:15;
%defining our parameters
ms=[2,3,5,15];
%defining distribution functions with loop
for i=1:4
eval("y"+i+"=chi2pdf(x,"+ms(i)+");");
end
plot(x,y1,'LineWidth',2,'LineStyle','--');
xlabel("Population");
ylabel("Probability distribution");
hold on
axis([0,15,0,0.5]);
linestyles=["':'","'-'","'--'","'-.'","':'"];
for i=2:4
eval("plot(x,"+"y"+i+","+"'LineWidth',2,'LineStyle',"+linestyles(i-
1)+");");
hold on
end
strrx="'m=2'";
for i=2:4
strrx=strrx+",'m="+ms(i)+"'";
end
eval(sprintf("legend(%s)",strrx));
legend('boxoff')
hold off
ii.
We plot again:

%defining cumulative distribution functions with loop


for i=2:4
eval("y"+i+"=chi2cdf(x,"+ms(i)+");");
end
plot(x,y1,'LineWidth',2,'LineStyle','--');
xlabel("Population");
ylabel("Probability distribution");
hold on
axis([0,15,0,1]);
linestyles=["':'","'-'","'--'","'-.'","':'"];
for i=2:4
eval("plot(x,"+"y"+i+","+"'LineWidth',2,'LineStyle',"+linestyles(i-
1)+");");
hold on
end
eval(sprintf("legend(%s)",strrx));
legend('boxoff')
hold off
iii.
We use the tcdf function we used previously:

fprintf("The value of X2-distribution with 9 degrees of freedom at x=1.83 is


%.4f",chi2cdf(1.83,9));

The value of X2-distribution with 9 degrees of freedom at x=1.83 is 0.0061

iv.
We use the tinv function for this purpose:

fprintf("The value of z for X2-distribution with 2 degrees of freedom which


returns " + ...
"0.99 is %.2f",chi2inv(0.99,2));

The value of z for X2-distribution with 2 degrees of freedom which returns 0.99 is 9.21

Question 4:
We define the functions for the last time:

%defining X2distribution and t functions with loop simultaneously


x=-5:0.05:5;
ms=[2,3,5,10];
for i=1:4
eval("t"+i+"=tpdf(x,"+ms(i)+");");
eval("X"+i+"=chi2pdf(x,"+ms(i)+");");
end
pdf_normal = pdf(pd,x);
plot(x,pdf_normal,'LineWidth',2);
xlabel("Population");
ylabel("Probability distribution");
hold on
axis([-5,5,0,0.5]);
strr="'Normal'";
for i=1:4

eval("plot(x,"+"X"+i+","+"'LineWidth',2,'LineStyle',"+linestyles(i+1)+");");
hold on

eval("plot(x,"+"t"+i+","+"'LineWidth',2,'LineStyle',"+linestyles(i+1)+");");
hold on
strr=strr+",'$\chi^2$,m="+ms(i)+"','t,m="+ms(i)+"'";
end
eval(sprintf("legend(%s,'Interpreter','latex')",strr));
legend('boxoff')

You might also like