Next Trivial Utilities 46

lr

        while (<>) {
          chomp;
          my ($x, $y) = split;
          ($x, $y) = ($., $x) if not defined $y;
          $X += $x;
          $Y += $y;
          $X2 += $x*$x;
          $Y2 += $y*$y;
          $XY += $x*$y;
          $N += 1;
        }

        my $Xm = $X / $N;
        my $Ym = $Y / $N;
        my $Xv = $X2 / $N - $Xm*$Xm;
        my $Yv = $Y2 / $N - $Ym*$Ym;
        my $Xs = sqrt($Xv);
        my $Ys = sqrt($Yv);

        my $m = $X*$X == $N * $X2 ? "Inf" : ($X*$Y/$N - $XY) / ($X*$X/$N - $X2);
        my $b = $m eq "Inf" ? "None" : $Ym - $m * $Xm;
        my $r = $Ys ? $m * $Xs/$Ys : "Inf";



Next Menu Copyright © 2012 M. J. Dominus