如何使用JAVA计算标准偏差 [英] How to calculate standard deviation using JAVA

查看:31
本文介绍了如何使用JAVA计算标准偏差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的,目前我正在尝试用 Java 计算标准偏差(我用谷歌搜索了它哈哈)但我在让它工作时遇到了很多问题

I'm very new here, at the moment I am trying to calculate standard deviation with Java (I have googled it haha) but I am having a lot of issues on getting it working

我有十个由用户输入的值,然后我必须计算到目前为止我的理解感谢回复的人是我找到了数组的平均值然后完成计算

I have ten values that are inputed by a user which I then have to calculate the standard deviation of my understanding so far thanks to people who have replied is I find the mean of the array then complete the calculations

                double two = total[2];
                double three = total[3];
                double four = total[3];
                double five = total[4];
                double six = total[6];
                double seven = total[7];
                double eight = total[8];
                double nine = total[9];
                double ten = total[10];

                double eleven = average_total;


mean = one + two + three + four + five + six + seven + eight + nine + ten + eleven;

mean = mean/11;
//one = one - mean;
//System.out.println("I really hope this prints out a value:" +one);
*/
 //eleven = average_total - mean;
 //eleven = Math.pow(average_total,average_total);
 //stand_dev = (one + two + three + four + five + six + seven + eight + nine + ten + eleven);
 //stand_dev = stand_dev - mean;
// stand_dev = (stand_dev - mean) * (stand_dev - mean);
// stand_dev = (stand_dev/11);
// stand_dev = Math.sqrt(stand_dev);

我的数据已经存储在 10 个值的数组中,但我不太确定如何从数组中打印数据然后进行计算而不必在此处存储输入代码数据一些我已经操纵的其他地方

I already have my data that is stored in an array of 10 values but I am not too sure how to print the data out of the array then do the calculations with out having to store the enter code here data some where else that I have manipulated

感谢您的宝贵时间,非常感谢:)

Thank you for your time, much appreciated :)

推荐答案

  calculate mean of array.

  loop through values

       array value = (indexed value - mean)^2    

  calculate sum of the new array.

  divide the sum by the array length

  square root it 

我将向您展示如何遍历数组,所有内容几乎都是相同的步骤,只是计算方式不同.

I'll show you how to loop through the array and everything is pretty much this same step just with a different calculation.

// calculating mean.

int total = 0;

for(int i = 0; i < array.length; i++){
   total += array[i]; // this is the calculation for summing up all the values
}

double mean = total / array.length;

阅读您的代码后,您做错的部分是您没有正确地遍历这些值并用平均值减去它.

After reading your code, the part you are doing wrong is that you are not looping through the values and subtracting it with average correctly.

又名这部分.

十一=average_total - 平均值;
十一 = Math.pow(average_total,average_total);

eleven = average_total - mean;
eleven = Math.pow(average_total,average_total);

你需要这样做.

for(int i = 0; i < array.length; i++){
   array[i] = Math.pow((array[i]-mean),2)
}

本质上,您需要使用 newvalue = oldvalue - mean(average) 更改数组中的每个值.

essentially you need to change every value in the array with newvalue = oldvalue - mean(average).

然后计算总和...然后平方根.

then calculate the sum... then square root that.

这篇关于如何使用JAVA计算标准偏差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆