develooper Front page | perl.beginners | Postings from March 2002

Trouble with Math::NumberCruncher

Thread Next
Tirthankar C. Patnaik
March 15, 2002 04:25
Trouble with Math::NumberCruncher
Message ID:
This might seem trivial, but it has me stumped. 

The variance of numbers 0..20 is 38.5. 
Then why does Math:NumberCruncher show it as 36.6667? 

Here's a sample prog, and it's output. Here test04.dat is a file that has
numbers 0 to 20, on separate lines.
#!/usr/bin/perl -w
use Math::NumberCruncher; 
# Program  to test Math::NumberCruncher

# Get a file from STDIN, print the variance, and the std. deviation.

@array = <>; 
map {chomp} @array; 

$variance = Math::NumberCruncher::Variance(\@array); 
$stddev = Math::NumberCruncher::StandardDeviation(\@array); 
$sd2 = $stddev**2; 

print scalar(@array), "\n"; 

printf "Var=$variance, S.D=$stddev S.D^2 = $sd2\n"; 


And the output is: 

Var=36.6666666666667, S.D=6.05530070819498 S.D^2 = 36.6666666666667

What could be possibly wrong? Even the standard value is wrong.  


 Tirthankar, IGIDR. 
 +91-22-8400919 x275 (r), x593(o), x542(CFL).

  LEGACY, n.  A gift from one who is legging it out of this vale of

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About