in reply to Simple Integration using Perl
Since a symbolic approach has been clearly shot down, I thought I'd suggest using the trapezoidal rule. Divide your interval into n even parts. Calculate the value of the function for each point that marks a boundary between parts of your interval. Use the values of these points to construct a series of trapezoids, bounded on the bottom with the x-axis. Then find the sum of the areas of the trapezoids.
A better approximation can be found by splitting the interval into uneven parts, basing your decision on the second derivative of the function. That is, you want to have more divisions in areas where the slope of the function changes a lot, and fewer divisions where the slope remains stable. The actual algorithm to implement this is left as an exercise for the reader. It's probably cheaper to just add more n when using the above approach, than to try and calculate all those derivatives, anyway.
Update: dragonchild- When you're holding a hammer, everything looks like a nail.
TGI says moo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Simple Integration using Perl
by tilly (Archbishop) on Jan 29, 2002 at 02:13 UTC | |
|
Re: Re: Simple Integration using Perl
by dragonchild (Archbishop) on Jan 29, 2002 at 00:57 UTC |