#!/usr/bin/perl -w
use 5.034;
# One question that arises often is wheter one density function is higher
# than other when both are normal, but the "better" by the mean has a
# much higher variance, thus this.
say "PI = ", 4*atan2(1,1);
my ($m1, $sd1) = (1.2, 1);
my ($m2, $sd2) = (1.1, 2);
my $last = 0;
for (my $i = -2; $i <= 4; $i += 0.01){
my $post = (fdensity($i, $m1, $sd1) >fdensity($i, $m2, $sd2)) ? "mejor 1" : "mejor 2";
if ($post ne $last){
say "$i -> $post";
}
$last = $post;
}
exit 2;
sub fdensity {
my ($x, $mean, $stddev) = @_;
my $tocho = (1/ ($stddev * sqrt( 2 * 4 * atan2(1,1) ))) * exp(1)**(-(($x-$mean)**2)/(2*$stddev**2));
return $tocho;
}