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


In reply to Re: Simple Integration using Perl by TGI
in thread Simple Integration using Perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.