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 commentaires

dpb
dpb le 21 Juil 2019
Modifié(e) : dpb le 21 Juil 2019
Well, provide the error text message or at least the input data you used...
Walter Roberson
Walter Roberson le 21 Juil 2019
In the first two parts you have ./(s) but in the third part you have /(s) without the period
dpb
dpb le 21 Juil 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
Dinesh Yadav le 5 Août 2019
Please provide the error log. Also make correction as pointed by Walter Roberson.

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by