Created
January 11, 2019 07:09
-
-
Save sangheonhan/6140e885b6e00d9cbf1a179ef7acd8ef to your computer and use it in GitHub Desktop.
숫자들의 표준 편차를 구하는 스크립트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use strict; | |
use warnings; | |
use POSIX qw/floor ceil/; | |
my @data; | |
while ( <> ) { | |
chomp; | |
push @data, $_; | |
} | |
my $total = 0; | |
foreach ( @data ) { | |
$total += $_; | |
} | |
print "number of data = ", $#data + 1, "\n"; | |
my $avg = $total / @data; # 평균 | |
print "average = $avg\n"; | |
my $sum_of_dev = 0; | |
my $sum_of_dev_sqr = 0; | |
foreach ( @data ) { | |
my $deviation = $_ - $avg; | |
$sum_of_dev += $deviation; | |
$sum_of_dev_sqr += $deviation * $deviation; | |
} | |
print "sum of dev = $sum_of_dev\n"; | |
print "sum of dev square = $sum_of_dev_sqr\n"; | |
my $variance = $sum_of_dev_sqr / $#data; | |
print "variance = $variance\n"; # 분산 | |
my $standard_deviation = sqrt $variance; | |
print "standard deviation = $standard_deviation\n"; # 표준 편차 | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment