X = [7 7 4 5 9 9 4 12 8 1 8 7 3 13 2 1 17 7 12 5 6 2 1 13 14 10 2 4 9 11 3 5 12 6 10 7];

n=length(X);

#oneminusalpha = input("Confidence level: (between 0 and 1)");
oneminusalpha = 0.95;
alpha = 1-oneminusalpha;

sigma=5;

#The null hypothesis is: H0: u=8.5 (it goes togheter with u>8.5, the standard is meet)
#The alternative hypothesis is: H1: u<8.5 (the standard is not meet)
#Left tail test for u when sigma is known

printf("This is a left tail test for the mean when sigma is known\n\n");

#n0 = input("Test value n0=");
n0=8.5;

[H, PVAL, CI, ZVALUE] = ztest(X,n0,sigma,'alpha',alpha,'tail','left');

z_alpha = norminv(alpha, 0, 1);

RR = [-inf z_alpha];

printf("The value of h is: %d\n\n",H);

if H==1
  printf("The null hypothesis is rejected\n\n");
  printf("The data suggests that the standard is not meet\n\n");
else
  printf("The null hypothesis is not rejected\n\n");
  printf("The data suggests that the standard is meet\n\n");
endif

printf("The regection region is: (%4.3f, %4.3f)\n",RR);
printf("The observed value of the test statistic is: %4.3f\n",ZVALUE );
printf("The Pvalue of the test is: %4.3f\n",PVAL);

#b use ttest
#2 a use vartest2
#2 b use ttest2
