#!/usr/bin/perl -w
# Integrate:
#    VERSION: Version 1 (13 October 2003)
#    PURPOSE: Numerical integration of given function
#             Sums ( f(x + dx) - f(x) ) dx

############## LIBRARIES AND PRAGMAS ################
  use strict;

#################### CONSTANTS ######################

  my $dx = 0.01;             # Increment. Might be played with.
  my $min_x = 0;             # Min value of x
  my $max_x = 10;            # Max value of x
  my $LF = "\n";             # Linefeed
  my $tab = "\t";            # Tab

#################### VARIABLES ######################

  my $x;                     # Substrate concentration
  my $area;                  # Area of thin triangle from x to x+dx
  my $sum = 0;               # Definite integral

################### MAIN PROGRAM ####################
# x goes from min to max
# Accumulate area of thin rectangle from x to x+dx

  for ($x=$min_x; $x < $max_x; $x = $x + $dx) {

     $area = ( f($x + $dx) + f($x) )/2 * $dx;
     $sum = $sum + $area;
  }
  print "Integral = ", $sum;

#################### SUBROUTINES ####################

#### f (x)
#    Calculates value for any function
  sub f {
     my ($x) = @_;
     my $y;
#    PUT FUNCTION HERE IN THE FORM $y =   ;
     $y = $x;
     return $y;
  }
