0

Here is the location of the source code (using Dropbox).

The problem is in the fact that it doesn't evaluate zeros properly.

For example: x^2-2x-8 should equal the zeros of {-4, 2}, but instead I get a long exponential value like -4+34534....E-25<i>i</i>.

It does work for polynomials with single roots (such as x<sup>2</sup>+4x+4, root = {-2})

Can anyone spot the problem, it's been frustrating me for weeks. This is NOT a homework assignment, this is something I work on in my free time.

Rachel
  • 100,387
  • 116
  • 269
  • 365
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
  • you might want to add code snippet,link you provide does not work for me. – Rachel May 02 '12 at 01:44
  • Try it now. I would add a snippet, but it would be several hundred lines long. – Mohit Deshpande May 02 '12 at 01:47
  • Does your code handle complex solutions to quadratic equations? From what you've posted, I think that your code is returning -4 + (3e-25 i). This is really close to -4 + (0e0 i) which is the answer you're looking for. – David Harris May 02 '12 at 02:08
  • It does handle complex solutions, but then what about the other roots? – Mohit Deshpande May 02 '12 at 10:37
  • @Mohit -- From what you've posted, I suspect that your issue is with the numerical accuracy of your calculations. This paper (http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) should give you some hints on handling this calculation properly. – David Harris May 02 '12 at 15:58
  • @DavidHarris - Thanks for the paper, it did help out some, but I may just find another method or library. – Mohit Deshpande May 02 '12 at 21:06

1 Answers1

0

I've run into problems like this before and decided to switch to a different (math-oriented) language. You could try using floats instead of doubles, which may do the trick, but would probably bear problems of their own. Or you could write a method that filters out anything smaller than 1E-10 or something along those lines. Another alternative (which may or may not be relevant here) would be to use JLink.

arshajii
  • 127,459
  • 24
  • 238
  • 287