#!/usr/local/bin/perl #This is a perl script for Simpson's (paraboloid) 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= 1; $n=100; $delX = ($b - $a)/$n; $z=$a; $y= ourFunction($z); $sum =$y; for($i=0; $i<$n-1; $i++) { $z= $z+$delX; $y= ourFunction($z); $j=$i+1; $odd=$j % 2; if ($odd == 1) {$mult = 4;} else {$mult = 2;} $sum=$sum+$mult*$y; } $z= $z+$delX; $y= ourFunction($z); $sum=$sum+$y; $int= $delX*$sum/3; print " \n int = $int \n "; sub ourFunction { local ($x); $x = @_[0]; #$f= sqrt(1+$x*$x); $f=10 * $x*$x * exp (-$x); print " x=$x and f= $f \n "; return $f; }