function V=P4_numgenTP1_2017(9801081)
randn(‘seed’,98.0108);
rand(‘seed’,108.9009);
A1=[50,100,200,500,1000,2000,5000];
A=A1(randi(7));
B=(randi(15)+5)/400;
%V=(randn(1,50)*(rand()*20+5)/300+(1+(randi(2)*2-3)*(rand()+0.2)/100)^2)*A;
V=(randn(1,100)*(rand()*20+5)/300+(1+(randi(2)*2-3)*(rand()+0.2)/100)^2)*A;
fprintf(‘nmu=%gnnalpha=%gnnn=%gnnm=%gnn’,A,A*B,20+round(rand()*1000)/100,35+round(rand()*1000)/100);
end
You are in charge of the Quality Control systems for a resistor production line. The key process in the production line requires a resistor to be within a specific range of resistance. If the resistance lies outside this range, it is defective Run P4 numgenTP1 2017. m in MATLAB with your student number to generate your data for this portfolio. The code will output: the data of measured resistances for 100 units of the resistor Au i.e. mul a e. alpha Your tasks: 1. Write one MATLAB function that calculates and returns the sample mean (T) and sample variance (s?) of your data, using a while loop. Do not use the built-in functions mean and var. Provide the MATLAB function as a separate .m file and the resulting mean and variance. 2. The process is supposed to have a mean value of w (i.e. mu as per printout from P4 numgenTP1 2017.m). There are concerns that the system may be incorrectly calibrated. To determine if there is sufficient evidence to support the concerns: (a) find the 95% confidence interval for the mean value Au (b) perform a hypothesis test.
Expert Answer
function [_mean, variance] = findMeanVar(A)
_sum=0;
for i=1:length(A)
_sum=_sum+A(i);
end
_mean=_sum/length(A); %mean
var_sum=0;
for i=1:length(A)
var_sum=var_sum+ (A(i)-_mean)^2;
end
variance = var_sum/length(A); %Varaince
end
A=rand(1000,1); %your array
_mean = 0;
variance = 0;
[_mean variance] = findMeanVar(A);
fprintf(‘mean: %f’,_mean)
fprintf(‘nVariance: %f’,variance)
Sample output
mean: 0.489680 Variance: 0.081566
—————————————————————————————————————————————————————
2)
a)
function [_mean, variance] = findMeanVar(A)
_sum=0;
for i=1:length(A)
_sum=_sum+A(i);
end
_mean=_sum/length(A); %mean
var_sum=0;
for i=1:length(A)
var_sum=var_sum+ (A(i)-_mean)^2;
end
variance = var_sum/length(A); %Varaince
end
A=rand(1000,1); %your array
_mean = 0;
variance = 0;
[_mean variance] = findMeanVar(A);
fprintf(‘mean: %f’,_mean)
fprintf(‘nVariance: %f’,variance)
standard_error = std(A)/sqrt(length(A)); % Standard Error
total_score = tinv([0.025 0.975],length(A)-1); % T-Score
Confidence_interval = _mean + total_score*standard_error; % Confidence Intervals
fprintf(‘nConfidence interval: %f’,Confidence_interval)
Sample output
mean: 0.495790 Variance: 0.082837 Confidence interval: 0.477921 Confidence interval: 0.513660
—————————————————————————————————————————————————————-
2)b)
function [_mean, variance] = findMeanVar(A)
_sum=0;
for i=1:length(A)
_sum=_sum+A(i);
end
_mean=_sum/length(A); %mean
var_sum=0;
for i=1:length(A)
var_sum=var_sum+ (A(i)-_mean)^2;
end
variance = var_sum/length(A); %Varaince
end
A=rand(1000,1); %your array
_mean = 0;
variance = 0;
[_mean variance] = findMeanVar(A);
fprintf(‘mean: %f’,_mean)
fprintf(‘nVariance: %f’,variance)
standard_error = std(A)/sqrt(length(A)); % Standard Error
total_score = tinv([0.025 0.975],length(A)-1); % T-Score
Confidence_interval = _mean + total_score*standard_error; % Confidence Intervals
fprintf(‘nConfidence interval: %f’,Confidence_interval)
normplot(A)
Sample output