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 个评论

dpb
dpb 2019-7-21
编辑:dpb 2019-7-21
Well, provide the error text message or at least the input data you used...
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.
Please provide the error log. Also make correction as pointed by Walter Roberson.

请先登录,再进行评论。

回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by