Hi TNX bro
i have a new code that calculate the mean of random number and then calculate the variance , so make gaussian function
#Hi First practice for PR class
use warnings ;
use strict ;
use GD::Graph::linespoints ;
#use DBI ;
#use utf8 ;
#use Encode ;
#my $sfile = '/root/source.txt' ;
print 'First Number > ' ;
chomp(my $A = <STDIN>) ;
print 'Second Number > ' ;
chomp(my $B = <STDIN>) ;
#my @range = ($A..$B) ;
#my $rndn = $range[int (rand(@range))] ;
my @points = () ;
my $counter = 0 ;
while ($counter <= 999) {
my $rndn = $A + (int rand($B - $A + 1));
push (@points,$rndn) ;
$counter++ ;
}
#Calculate the Mean and Variance
my $running_sum = 0;
my $meansum ;
my $vari ;
my $element1 ;
my $element2 ;
foreach $element1 (@points) {
$meansum += $element1;
}
my $mean = $meansum/1000 ;
print "MEAN = $mean" , "\n" ;
foreach $element2 (@points) {
$vari += (($meansum - $element2)^2) ;
}
my $variance = ($vari/1000) ;
print "Variance = $variance" , "\n" ;
print 'Second Number > ' ;
chomp(my $xi = <STDIN>) ;
my $Gs1 = (1/sqrt(2*3.14*$variance)) ;
my $Gs2 = 2.718^(-(($xi - $mean)^2)/(2*$variance)) ;
my $Go = $Gs1 * $Gs2 ;
print "$Gs1" , "\n" ;
print "$Gs2" , "\n" ;
print "$Go" , "\n" ;
my $graph = new GD::Graph::linespoints(2000 , 2000) ;
$graph->set(
x_label => 'Points' ,
x_label_skip => 1 ,
y_label => 'Number' ,
y_label_skip => 1 ,
title => 'Time Vs Fee') or warn $graph->error ;
$graph->plot(\@points);
open OUT,'>','FirstPracticeTest.jpeg' or die "$!";
binmode OUT;
print OUT $graph->gd->jpeg;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|