Matrix error must agree problem
显示 更早的评论
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 个评论
Walter Roberson
2019-7-21
In the first two parts you have ./(s) but in the third part you have /(s) without the period
dpb
2019-7-21
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
2019-8-5
Please provide the error log. Also make correction as pointed by Walter Roberson.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Hypothesis Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!