From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2b8382e0387f53c5 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!aioe.org!.POSTED!not-for-mail From: "John B. Matthews" Newsgroups: comp.lang.ada Subject: Re: Eigenvalues to find roots of polynomials Date: Tue, 26 Jul 2011 23:21:49 -0400 Organization: The Wasteland Message-ID: References: <3ec148c9-a033-40a1-bc32-1aa52867478a@e35g2000yqc.googlegroups.com> <8d424bae-53cb-4418-8ec1-1fbf3ec260e3@y16g2000yqk.googlegroups.com> NNTP-Posting-Host: LQJtZWzu+iKlBROuDg+IUg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news2.google.com comp.lang.ada:21348 Date: 2011-07-26T23:21:49-04:00 List-Id: In article <8d424bae-53cb-4418-8ec1-1fbf3ec260e3@y16g2000yqk.googlegroups.com>, marius63 wrote: > And the winner is... > > > > > John B. Matthews Ada...Generic_Roots works like a charm. > It passed the simple test case, and solved my quintic problem > x^5 - 4178x + 4177 > > $ ./find_roots_mathews 1 0 0 0 -4178 4177 > Index => 0, Position => 6, Value => 4177 > Index => 1, Position => 5, Value => -4178 > Index => 2, Position => 4, Value => 0 > Index => 3, Position => 3, Value => 0 > Index => 4, Position => 2, Value => 0 > Index => 5, Position => 1, Value => 1 > Root 1 => (Re=> 1.00000000000000E+00, Im=> 0.00000000000000E+00) > Root 2 => (Re=>-2.47582467311450E-01, Im=>-8.05881611194044E+00) > Root 3 => (Re=> 7.76752669636581E+00, Im=>-1.40129846432482E-45) > Root 4 => (Re=>-2.47582467311450E-01, Im=> 8.05881611194044E+00) > Root 5 => (Re=>-8.27236176174291E+00, Im=> 0.00000000000000E+00) > > I know from previous mathematical derivation (the polynomial comes > from extracting a variable in a summation), that the solution is a > non- negative scalar different from one, so Root 3 is my number, with > the non-zero but very small value of the imaginary part certainly > only a residue of computation done inside Matthews's magic machine. > Thanks a very great lot. Source code follows. Sorry for the > mispelling, "Mathews". No problem; I'm glad you found it useful! You might also like the test program, croot.adb. For example, adding this line: Show_Result((4177.0, -4178.0, 0.0, 0.0, 0.0, 1.0)); produces the following table: Poly: 1.00x^5 + 0.00x^4 + 0.00x^3 + 0.00x^2 - 4178.00x^1 + 4177.00 Real: -8.27236176174291E+00 Comp: -2.47582467311450E-01 +- 8.05881611194044E+00i Real: 1.00000000000000E+00 Real: 7.76752669636581E+00 Largest error: = 9.09494701772928E-12 The program sorts the results to find conjugate pairs and checks values against zero using the same epsilon found in the implementation. It then evaluates the polynomial at each root, recording the largest deviation from zero. [Example omitted.] -- John B. Matthews trashgod at gmail dot com