Respuesta :
Answer:
sigma formulas are executed by using for loop to sum all the values.
public class H4_Q3{
public static void main(String[] args)
{
//Part a
double[] values = {100000000.6, 99999999.8, 100000002.8, 99999998.5, 100000001.3};
int n = values.length;
//Part b;
double sum = 0;
double sample_average = 0;
double sample_variance = 0;
int i = 0;
for(i = 0; i < n; i++)
{
sum = sum + values[i];
}
sample_average = sum/n;
for(i = 0; i < n; i++)
{
sample_variance = sample_variance + (Math.sqrt(values[i]) - sample_average);
}
System.out.println("Sample variance (Part b formula): "+sample_variance);
//Part c
double sum_squared = 0;
double sum_values = sample_average;
for(i = 0; i < n; i++)
{
sum_squared = sum_squared + Math.sqrt(values[i]);
}
sum_squared = sum_squared/n;
sample_variance = (sum_squared - Math.sqrt(sum_values)) * (n/ (n - 1));
System.out.println("Sample variance (Part c formula): "+sample_variance);
//Part d
sample_variance = 0;
double[] M = new double[n];
double[] S = new double[n];
M[0] = values[0];
S[0] = 0;
i = 1;
while(i < n)
{
M[i] = M[i-1] + ((values[i] - M[i-1])/i+1);
S[i] = S[i-1] + (values[i] - M[i-1]) * (values[i] - M[i]);
i++;
}
System.out.println("Sample variance (Part d formula): "+S[n-1]/n);
}
}