X=[1001.7 975.0 978.3 988.3 978.7 988.9 1000.3 979.2 968.9 983.5 999.2 985.6];

n=length(X);

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

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

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

n0=995;

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

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

oneminusalpha = 0.99;
alpha = 1-oneminusalpha;

v1=((n-1)*var(X))/(chi2inv(1-alpha/2, n-1));

v2=((n-1)*var(X))/(chi2inv(alpha/2,n-1));

s1=sqrt(v1);
s2=sqrt(v2);

printf("Confidence interval for the theoretical standard variance is (%4.3f, %4.3f)\n", s1,s2);
