Results 1 to 3 of 3
Thread: standard deviation error
 05032011, 04:52 AM #1Member
 Join Date
 Mar 2011
 Posts
 16
 Rep Power
 0
standard deviation error
My standard deviation is off, and I'm not sure why. I found this formula online, but there must be something wrong...Anyone have ideas? :confused:
Java Code:double deviation=0; for (int i = 0; i < numbers.length; i++) { sum += Math.pow((numbers[i]  average), 2); } deviation = Math.sqrt(sum /(number_of_elements1)); System.out.println ("The SD is : " + deviation);
 05032011, 05:31 AM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,716
 Rep Power
 18
Check that you are initialising sum to zero and that number_of_elements has the correct value. Also check that you are supposed to subtract one from it. (there are different ways of defining it). And check that average has the value you expect.
If you still get a strange result post a Short, Self Contained, Correct Example: something that others can run as well as a description of the result you expected.
 05032011, 05:43 AM #3Member
 Join Date
 Mar 2011
 Posts
 16
 Rep Power
 0
Hmmm, I've checked all of that. Here's my code:
Java Code:public class sample { public static void main (String[]args){ java.util.Scanner input = new java.util.Scanner(System.in); final int number_of_elements=10; double [] numbers = new double [number_of_elements]; double sum=0; for (int i=0; i < number_of_elements; i++) { System.out.print ("Enter a number: "); numbers[i] = input.nextDouble(); sum+=numbers[i]; } double average = sum/number_of_elements; System.out.println ("The mean is " + average); double deviation=0; for (int i = 0; i < numbers.length; i++) { sum += Math.pow((numbers[i]  average), 2); } deviation = Math.sqrt(sum /(number_of_elements1)); System.out.println ("The SD is : " + deviation); } }
Similar Threads

standard deviation calculation
By rochla16 in forum New To JavaReplies: 5Last Post: 04282011, 08:27 PM 
JSP standard actions
By subhashis_mohanty in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 11272010, 08:35 AM 
what is "standard error stream"
By Cylab in forum New To JavaReplies: 11Last Post: 07152010, 09:29 AM 
[SOLVED] Calculating Std. Deviation using Java
By random0munky in forum New To JavaReplies: 1Last Post: 12122008, 10:24 AM 
standard deviation and mean for an array
By peterdfl in forum New To JavaReplies: 3Last Post: 05292008, 05:09 AM
Bookmarks