Java
 Computer >> コンピューター >  >> プログラミング >> Java

標準偏差を計算するJavaプログラム


この記事では、標準偏差の計算方法を理解します。標準偏差は、数値の広がりの尺度です。そのシンボルはsigma(σ)です。これは分散の平方根です。

標準偏差は、∑(Xi--ų)2 / Nの式の平方根を使用して計算されます。ここで、Xiは配列の要素、ųは配列の要素の平均、Nは要素の数、∑は各要素。

以下は同じのデモンストレーションです-

入力が-であるとします

Input Array : [ 35.0, 48.0, 60.0, 71.0, 80.0, 95.0, 130.0 ]

必要な出力は-になります

Standard Deviation: 29.313227

アルゴリズム

Step 1 - START
Step 2 – Declare a double array namely input_array, two doube values namely sum and standard_deviation.
Step 3 - Read the required values from the user/ define the values.
Step 4 – Compute ∑(Xi - ų)2 / N and store the value in result variable.
Step 5 - Display the result
Step 6 - Stop

例1

ここでは、ユーザーがプロンプトに基づいて入力を入力しています。

public class StandardDeviation {

   public static void main(String[] args) {
      double[] input_array = { 35, 48, 60, 71, 80, 95, 130};
      System.out.println("The elements of the array is defined as");
      for (double i : input_array) {
         System.out.print(i +" ");
      }

      double sum = 0.0, standard_deviation = 0.0;
      int array_length = input_array.length;

      for(double temp : input_array) {
         sum += temp;
      }

      double mean = sum/array_length;

      for(double temp: input_array) {
         standard_deviation += Math.pow(temp - mean, 2);
      }

      double result = Math.sqrt(standard_deviation/array_length);

      System.out.format("\n\nThe Standard Deviation is: %.6f", result);
   }
}

出力

The elements of the array is defined as
35.0 48.0 60.0 71.0 80.0 95.0 130.0

The Standard Deviation is: 29.313227

例2

ここでは、標準偏差を計算する関数を定義しました。

public class StandardDeviation {

   public static void main(String[] args) {
      double[] input_array = { 35, 48, 60, 71, 80, 95, 130};
      System.out.println("The elements of the array is defined as");
      for (double i : input_array) {
         System.out.print(i +" ");
      }
      double standard_deviation = calculateSD(input_array);

      System.out.format("\n\nThe Standard Deviation is: %.6f", standard_deviation);
   }

   public static double calculateSD(double input_array[]) {
      double sum = 0.0, standard_deviation = 0.0;
      int array_length = input_array.length;

      for(double temp : input_array) {
         sum += temp;
      }

      double mean = sum/array_length;

      for(double temp: input_array) {
         standard_deviation += Math.pow(temp - mean, 2);
      }

      return Math.sqrt(standard_deviation/array_length);
   }
}

出力

The elements of the array is defined as
35.0 48.0 60.0 71.0 80.0 95.0 130.0

The Standard Deviation is: 29.313227

  1. 標準偏差を計算するCプログラム

    標準偏差は、データの平均からの偏差を測定するために使用されます。標準偏差を計算する式は次のとおりです- $$ s =\ sqrt {Variance} $$ ここで Variance $$ =\ frac {1} {n} \:\:\ displaystyle \ sum \ Limits_ {i =1} ^ n(x_ {i} -m)^ {2} $$ および $$ m =mean =\ frac {1} {n} \:\ displaystyle \ sum \ Limits_ {i =1} ^ n x_ {i} $$ アルゴリズム 与えられた数値の標準偏差を計算するには、

  2. 二重積分を計算するC++プログラム

    変数xの下限、変数xの上限、変数yの下限、変数yの上限、対応するxに対して実行されるステップ、および対応するyに対して実行されるステップが与えられ、タスクは二重積分を生成することです。結果を表示します。 例 Input-: steps for x = 1.2 steps for y = 0.54 lower limit of x = 1.3 upper limit of x = 2.1 lower limit of y = 1.0 upper limit for y = 2.1 Output-: double integration is : 2.1 以下のプログラムで使用されるアプローチは