Be warned, there is no method of finding roots for polynomials with orders up to a few hundred that won't have some trouble with numerical stability.

You could try Math::Polynomial::Solve. Unfortunately it will usually require you to use Math::Complex, which means that you can't do arbitrary precision arithmetic. This may be a problem if accuracy is an issue. I'm going to guess that it is.

Googling around another promising approach is outlined in http://math-blog.com/2008/03/06/polynomial-root-finding-with-the-jenkins-traub-algorithm/. That link links to a JavaScript implementation at http://www.akiti.ca/PolyRootRe.html. What is nice about that solution is that it only uses real arithmetic, so you're able to use Math::BigFloat to address precision issues.

In your situation I would be inclined to try to translate the JavaScript solution into a Perl one. (I'd prefer that over the FORTRAN because a lot of the work in structuring the program has been done for you. Plus I find JavaScript easier to read.) I'd personally start with a semi-automated translation, and fix up issues by hand until I began getting the same results. If you don't know much about parsing, this won't work for you. Instead you could translate one routine at a time, and throw data at each to verify your translation before going on. (Expect to have a few sessions where you're getting drastically different results and have no idea why...)

Once you have a Perl translation then you can play around with Math::BigFloat to find the right precision to work at. I personally would aim for finding a precision which satisfied both that the solution multiplied out gives the original polynomial to some tolerance, and that doubling the precision doesn't change the calculated roots by more than a specified tolerance.

Be warned that this is likely to be a fair amount of work. But it will be less than trying to come up with something on your own, and it will be more likely to give correct answers.


In reply to Re: Internal Rate of Return by tilly
in thread Internal Rate of Return by ig

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.