Hi. I'm doing a stand alone matlab code for ztest. And when it comes to computing for the z-value, it keeps saying matrix error. Please help thank you!
%Hypothesis testing: Z-test for mean
format bank
disp 'Hypothesis Testing for Mean - Variance Known'
n=input('Sample size = ');
mu=input('Population mean = ');
mean=input('Sample mean = ');
s=input('Standard deviation = ', 's');
a=input('Alpha = ');
disp 'Using Traditional Method'
disp 'Step I. State the hypothesis'
fprintf('H0: mu = %d. \n',mu);
ope = input(' The alternate is ', 's');
fprintf('H1: mu %s %d. \n',ope, mu);
if strcmp(ope,'<')
disp 'One-tailed'
disp 'Step II. Find the critical value'
cv = norminv(1-a);
fprintf('The critical value is %d. \n',cv);
disp 'Step III. Compute the test value'
zval = (sqrt(n).*(mean-mu))./(s);
fprintf('The test value is %d. \n',zval);
disp 'Step IV. Make a decision'
if cv>zval
fprintf('Reject H0!')
else
fprintf('Accept H0!')
end
elseif strcmp(ope,'>')
disp 'One-tailed'
disp 'Step II. Find the critical value'
cv = norminv(1-a);
fprintf('The critical value is %d. \n',cv);
disp 'Step III. Compute the test value'
zval = (sqrt(n).*(mean-mu)./s);
fprintf('The test value is %d. \n',zval);
disp 'Step IV. Make a decision'
if cv>zval
fprintf('Reject H0!')
else
fprintf('Accept H0!')
end
else
disp 'Two-tailed'
disp 'Step II. Find the critical value'
A = a./2;
cv1=norminv(A);
cv2=norminv(1-A);
fprintf('The critical values are %d. \n',cv1, cv2);
disp 'Step III. Compute the test value'
zval = (sqrt(n)*(mean-mu))/(s);
fprintf('The test value is %d. \n',zval);
disp 'Step IV. Make a decision'
if cv > zval
fprintf('Reject H0!')
else
fprintf('Accept H0!')
end
end

댓글 수: 4

dpb
dpb 2019년 7월 21일
편집: dpb 2019년 7월 21일
Well, provide the error text message or at least the input data you used...
Walter Roberson
Walter Roberson 2019년 7월 21일
In the first two parts you have ./(s) but in the third part you have /(s) without the period
But unless user enters multiple values (which seems unlikely usage) looks like it would be single value so wouldn't matter.
s=input('Standard deviation = ', 's');
But, of course, that's making a presumption; if there were more than one it would be a problem.
Dinesh Yadav
Dinesh Yadav 2019년 8월 5일
Please provide the error log. Also make correction as pointed by Walter Roberson.

댓글을 달려면 로그인하십시오.

답변 (0개)

태그

질문:

2019년 7월 21일

댓글:

2019년 8월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by