我的数学有什么问题?

What is wrong with my math?

好的,所以我的老师让我们制作一个程序,该程序使用一组数字并找出它的标准差。我的程序发现平均值很好。但是,我的数学有问题。它有什么问题。它给了我 59 的平均值和 8.4 的偏差。平均值是正确的,但偏差应为 96.4。我的数学有什么问题。

编辑: 我的程序现在可以运行了。
P.S. 我已将以下代码更改为我当前版本的代码。

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
//Used To Round The Decimal Points
cout << setiosflags(ios::fixed|ios::showpoint);
cout << setprecision(1);

//Declaring
double Numbers[] = {65, 49, 74, 59, 48}; //Work On Making This A User Input----------Deivation = 96.4
double Mean = 0, Items = 0, Sum = 0, Deviation = 0;
int Counter;

//Finds The Mean Of The Set Of Numbers
for (Counter = 0; Counter < sizeof(Numbers) / sizeof(double); Counter++)
{
    for (Counter = 0; Counter < sizeof(Numbers) / sizeof(double); Counter++)
    {
        Sum += Numbers[Counter]; //Adds All Numbers In Array Together
    }
    Items = sizeof(Numbers) / sizeof(double); //Gets The Number Of Items In The Array
    Mean = Sum / Items; //Finds The Mean
}

//Finds The Standard Deviation
for (Counter = 0; Counter < sizeof(Numbers) / sizeof(double); Counter++)
{
    Deviation += pow((Numbers[Counter] - Mean), 2) / Items; //Does Math Things...
}
Deviation = sqrt(Deviation);
cout << "Deviation = " << Deviation << endl; //Print Out The Standard Deviation

system("pause");
return 0;
}

将sqrt画出循环并在求和后应用。

[...] however the deviation should be 96.4

方差应该是96.4。它计算为平均值的平方差的平均值,因此您根本不需要平方根:

for (Counter = 0; Counter < sizeof(Numbers) / sizeof(double); Counter++)
{
    Variance += pow((Numbers[Counter] - Mean), 2) / Items;
}
Deviation = sqrt(Variance);

对方差求平方根得到 9.81835。

偏差的数学表达式有误,应该是集合方差的平方根:

方差 = 总和 ( pow(set[i] - mean, 2) ) / n

偏差 = sqrt(方差)

顺便说一句,我认为这里的 9.82 比 96.4 更正确

错误是因为人们指出不能直接添加标准偏差。计算标准偏差的更好方法是取均方根(元素从其均值中减去)。