java 标准偏差函数std,如何使用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);

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

edited:

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;

edit2:

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.

aka this part.

eleven = average_total - mean;

eleven = Math.pow(average_total,average_total);

you need to do this.

for(int i = 0; i < array.length; i++){

array[i] = Math.pow((array[i]-mean),2)

}

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值