#!/usr/local/bin/perl #This is a perl script for trapizoidal approximation. #Unless you konw something about perl script, you will need some help. #To run this program, save it as trapiz.pl (or as any dot-pl file). #You will change the function in ourFunction sub-program. # a is lower limit, b is upper limit and n is the number of subinterval. $a = 0; $b= 2; $n=8; $delX = ($b - $a)/$n; $z=$a; $y= ourFunction($z); $sum =$y; for($i=0; $i<$n-1; $i++) { $z= $z+$delX; $y= ourFunction($z); $sum=$sum+2*$y; } $z= $z+$delX; $y= ourFunction($z); $sum=$sum+$y; $int= .5*$delX*$sum; print " \n int = $int \n "; sub ourFunction { local ($x); $x = @_[0]; #$f= sqrt(1+$x*$x*$x); $f=1/(3**($x*$x)); print " x=$x and f= $f \n "; return $f; }