我的数学有什么问题?

编程入门 行业动态 更新时间:2024-10-25 00:29:41
本文介绍了我的数学有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好的,所以我的老师指派我们制作了一个使用一组数字并找出其标准偏差的程序.我的程序发现平均数就好了.但是,我的数学有问题.怎么了它的平均值为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

[...] however the deviation should be 96.4

应为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.

更多推荐

我的数学有什么问题?

本文发布于:2023-10-22 23:02:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   数学

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!