我的数学有什么问题

我的数学有什么问题

本文介绍了我的数学有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我的老师指派我们制作了一个使用一组数字并找出其标准偏差的程序.我的程序发现平均数就好了.但是,我的数学有问题.怎么了它的平均值为59,偏差为8.4.平均值是正确的,但偏差应为96.4.我的数学怎么了?

Ok, so my instructor assigned us to make a program that used a set of numbers and finds the standard deviation of it. My program finds the Mean just fine. However, there is an issue with my math. What is wrong with it. It is giving me a mean of 59 and a deviation of 8.4. The mean is right however the deviation should be 96.4. Whats wrong with my math.

编辑:我的程序"现在可以使用.
建议.我已将以下代码更改为当前的代码版本.

My Program now works.
P.S. I have changed the following code to my current version of code.

#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;
}

推荐答案

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

It's the variance that should be 96.4. It is calculated as the average of squared differences from the mean, so you don't need square root at all:

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

取方差的平方根可得出9.81835.

Taking square root of variance yields 9.81835.

这篇关于我的数学有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:58