arrays - Find standard deviation from text file with integers -


i have file containing list of numbers needs stored in array. how can compute population standard deviation of array? main class doesn't need altered.

main

import java.io.bufferedreader; import java.io.filereader;   public class main { private static int numbers=20;  public static void main(string[] args) {     double[] mynumbers =  new double[numbers];     calculations calculations = new calculations();     try {         calculations.readfile("numbers.txt", mynumbers);         double stddev = calculations.computestandarddeviation(mynumbers);         system.out.println("population std dev = " + stddev);     } catch (exception e) {         e.printstacktrace();     } } } 

calculations

import java.io.bufferedreader; import java.io.filereader;  public class calculations { // read integers text file, use myarray.length number read  // read numbers text , convert doubles. public void readfile(string filename, double[] myarray) throws exception {     filereader fr = null;     bufferedreader br;  } public double computestandarddeviation(double[] myarray) {     double result = 0;      return result; } } 

list

9 2 5 4 12 7 8 11 9 3 7 4 12 5 4 10 9 6 9 4

i guess question "how calculate standard deviation of population ?".

the calculation of standard deviation (sd short) relatively simple.

to understand sd means beyond scope of answer i'll go straight point. sd "the squareroot of average of squared differences mean".

breaking down in steps (what programming about):

1st: calculate mean.

2nd: now, every value in array, need calculate it's squared difference mean.

3rd: add above values (call s).

4th: find average squared difference (variance) diving s amount of numbers there are.

5th: lastly, squareroot last number you've got.

one example can found here.

edit:

if want sample code that, here (in java):

public class calculations {  public double computemean( double[] array ){      double sum = 0;      (double d : array){          sum += d;     }      return sum / array.length; }  public double computestandarddeviation(double[] array) {      double mean = computemean(array);      double sumofsqdiff = 0;      (double d : array){          sumofsqdiff += math.pow((d - mean), 2);     }      return math.sqrt(sumofsqdiff / array.length); } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -