#!/usr/local/bin/perl -w # reads a (difference in potential) from command line # and returns the mean number of goals and m.p. number of goals # - i.e., returns lambda = 1.0 * exp( a ) [duration 1.0 game] $a=-1000; $oldstyle = 1 ; # whether to print verbose answers $gmax = 5.0 ; # max number to consider eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if ( $a == -1000 ) { print STDERR "You must supply a and n\n" ; &print_usage (); exit(0); } sub print_usage { print STDERR " poisson.p a=1\n" ; } $lambda = exp ( $a ) ; printf "# mean number of goals = %9.3g\n" , $lambda ; if ( 2.0 * $lambda > $gmax ) { $gmax = 2.0 * $lambda ; } $tot = 0.0 ; $prob = exp ( - $lambda ) ; $maxprob = 0.0 ; for ( $x = 0 ; $x <= $gmax ; ) { if ( $oldstyle ) { printf "prob (%2d ) = %9.3g\n" , $x , $prob ; } else { printf "%2d %9.3g\n" , $x , $prob ; } $tot += $prob; if ( $prob > $maxprob ) { $maxprob = $prob ; $maxgoal = $x ; } $x ++ ; $prob *= $lambda / $x ; } if ( $oldstyle ) { printf "prob (%2d+) = %9.3g\n" , $x , 1.0 - $tot ; } else { printf "# (%2d or more)\n%2d %9.3g\n" , $x , $x , 1.0 - $tot ; } # printf "total prob = %9.3g, most probable number of goals = %2d\n" , $tot , $maxgoal ; printf "# most probable number of goals = %2d\n" , $maxgoal ; # ##### # itp/bigrams # lambda=15 # poisson.p a=2.70805 oldstyle=0 > poisson # #