Matrix error must agree problem
3 views (last 30 days)
Show older comments
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 Comments
dpb
on 21 Jul 2019
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
on 5 Aug 2019
Please provide the error log. Also make correction as pointed by Walter Roberson.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!