#!/usr/bin/perl -w
#==========================================================================#
#  Jeff Balsley                                                            #
#  Sun Dec 24 01:13:03 PST 2000                                            #
#                                                                          #
#==========================================================================#

print "At what x value should the integal start > \n";
chomp ( $xstart = <STDIN> );
print "At what value should the integral end > \n";
chomp ( $xstop = <STDIN> );

$accuracy = 1e-10;  

$integral = ($xstop - $xstart) * (f($xstart) + f($xstop))/2; 
# print "integal = $integral\n";
$int_diff = 1;
$n = 3;
while (abs $int_diff > $accuracy){
    $integral1 = 0;
    $x1 = $xstart;
    $x2 = $x1;
    while ($x2 < $xstop){
	$deltax = ($xstop - $xstart) / $n;
	$x2 = $x1 + $deltax;
	$value = (f($x1) + f($x2)) / 2 * $deltax;
	$integral1 = $integral1 + $value;
	$x1 = $x2;
    }
    $n = $n + 1;
    $int_diff = $integral1 - $integral;
    $integral = $integral1;
}

print "$n ";
print "The integral is $integral\n";

#===========================================================================#

sub f {
    $a = $_[0] * $_[0];
    return $a;
}



