Jesus Fernandez wrote:
Dear friends,
Hello
I'm trying to write a program that draws 5,000 numbers from an exponential distribution with mean 4N/k(k-1) N=10 000 k = 25 I have this: #!jesusafernandez/bin/perl
use warnings; use strict;
$k = 25;
my $k = 25;
$N = 10000;
my $N = 10_000;
for ($samp=0; $samp<5000; $samp++) {
for my $samp ( 0 .. 4_999 ) {
while ($k!= "$25")
The numeric variable $25 can only be used with regular expressions. Perhaps you meant:
while ( $k != 25 )
{ $mean = 4$N/$k($k-1));
You are missing an operator between 4 and $N and between $k and ($k-1). Perhaps you meant:
my $mean = 4 * $N / $k * ( $k - 1 );
$time = (-log (rand)*$ mean);
Although a space between '$' and 'mean' is allowed it is usually not good practice.
my $time = -log( rand ) * $mean;
push (@xx,$time); $k=$k-y}
The string literal 'y' should be in quotes, but a string literal used in numerical context will just evaluate to the number 0 so:
$k -= 0; } Although using 0 there does not make much sense.
print "$time\n";
You are missing the closing } for the for loop. John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/