clear all close all mu = 75; % Population mean sigma = 2; % Population standard deviation n = 20; % Sample size e = normrnd(mu,sigma,n,1); % Random sample from population xbar = mean(e) % Sample mean s = std(e) % Sample standard deviation gamma = 0.95 % P(-A< T < A) =0.95 t = tinv((1+gamma)/2,n-1) %correspond to P(T <= A) =(1+gamma)/2 lb = xbar-t*s/sqrt(n) ub = xbar+t*s/sqrt(n) figure; subplot(131),plot(e,'o') hold on subplot(131),plot(zeros(1,n)+ub,'r'); subplot(131),plot(zeros(1,n)+xbar,'k'); subplot(131),plot(zeros(1,n)+lb,'g'); mu = 75; % Population mean sigma = 2; % Population standard deviation n = 10; % Sample size e = normrnd(mu,sigma,n,1); % Random sample from population xbar = mean(e) % Sample mean s = std(e) % Sample standard deviation gamma = 0.95 % P(-A< T < A) =0.95 t = tinv((1+gamma)/2,n-1) %correspond to P(T <= A) =(1+gamma)/2 lb = xbar-t*s/sqrt(n) ub = xbar+t*s/sqrt(n) subplot(132),plot(e,'o') hold on subplot(132),plot(zeros(1,n)+ub,'r'); subplot(132),plot(zeros(1,n)+xbar,'k'); subplot(132),plot(zeros(1,n)+lb,'g'); mu = 75; % Population mean sigma = 2; % Population standard deviation n = 5; % Sample size e = normrnd(mu,sigma,n,1); % Random sample from population xbar = mean(e) % Sample mean s = std(e) % Sample standard deviation gamma = 0.95 % P(-A< T < A) =0.95 t = tinv((1+gamma)/2,n-1) %correspond to P(T <= A) =(1+gamma)/2 lb = xbar-t*s/sqrt(n) ub = xbar+t*s/sqrt(n) subplot(133),plot(e,'o') hold on subplot(133),plot(zeros(1,n)+ub,'r'); subplot(133),plot(zeros(1,n)+xbar,'k'); subplot(133),plot(zeros(1,n)+lb,'g');