修正方差计算
This commit is contained in:
parent
f9992eecc9
commit
843f1929ab
1 changed files with 6 additions and 6 deletions
|
@ -195,6 +195,7 @@ int main()
|
|||
#include <stdio.h>
|
||||
|
||||
double score[5][3];
|
||||
double average[5];
|
||||
|
||||
void Average_Student(void)
|
||||
{
|
||||
|
@ -204,6 +205,7 @@ void Average_Student(void)
|
|||
avg += score[i][j];
|
||||
}
|
||||
avg /= 3;
|
||||
average[i] = avg;
|
||||
printf("第%d个学生的平均成绩是%f\n", i + 1, avg);
|
||||
}
|
||||
}
|
||||
|
@ -240,13 +242,11 @@ void Calc_Var(void)
|
|||
{
|
||||
double sum_xi = 0;
|
||||
double sum_xi2 = 0;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
sum_xi2 += score[i][j];
|
||||
sum_xi2 += score[i][j] * score[i][j];
|
||||
}
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
sum_xi += average[i];
|
||||
sum_xi2 += average[i] * average[i];
|
||||
}
|
||||
double sigma = sum_xi2 / 15 - sum_xi * sum_xi / 225;
|
||||
double sigma = sum_xi2 / 5 - sum_xi * sum_xi / 25;
|
||||
printf("方差是%f\n", sigma);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue