emsr / polynomial

A C++ polynomials and related algorithms.
6 stars 3 forks source link

Polynomial is unable to evaluate at the (known accurate) roots returned by some solvers. #1

Closed emsr closed 5 years ago

emsr commented 7 years ago

Polynomial needs to scale it's coefficients. Each time the polynomial is altered this must be redone.

emsr commented 7 years ago

Input Polynomial

9 1.0 -1000092.0 +92003682.0 -3682083720.0 +83721182769.0 -1182779630508.0 +10630567354028.0 -59354216204400.0 +1.882046594592e+14 -2.594592e+14

Expected Roots

Re: +9.99999999976836e+00, Im: +0.00000000000000e+00 Re: +9.00000000007466e+00, Im: +0.00000000000000e+00 Re: +1.19999999963639e+01, Im: +0.00000000000000e+00 Re: +1.10000000013610e+01, Im: +0.00000000000000e+00 Re: +1.39999999972161e+01, Im: +0.00000000000000e+00 Re: +1.30000000045853e+01, Im: +0.00000000000000e+00 Re: +1.50000000006610e+01, Im: +0.00000000000000e+00 Re: +7.99999999996965e+00, Im: +0.00000000000000e+00 Re: +1.00000000000000e+06, Im: +0.00000000000000e+00

Output (Pretty good)

The zeros are: 8.00000000162836 10.0000000329959 8.99999998883711 12.0000000532863 10.9999999457294 12.9999999690746 14.0000000096727 (14.9999999987758,0) 1000000

Solution tests: P(8.00000000162836) = -3.1788200657624e+22 P(10.0000000329959) = -2.41221770314875e+23 P(8.99999998883711) = -9.26965247808991e+22 P(12.0000000532863) = -1.25992329308831e+24 P(10.9999999457294) = -5.72585858064654e+23 P(12.9999999690746) = -2.60158405921637e+24 P(14.0000000096727) = -5.08912565043838e+24 P((14.9999999987758,0)) = (-9.50215633384858e+24,-0) P(1000000) = -2.594590117954e+68

emsr commented 5 years ago

I had forgotten to reverse the coefficients in the Polynomialused for testing. Now I get:The zeros are: 8.00000000156914 10.0000000317527 8.99999998928141 12.0000000528519 10.9999999472538 12.9999999682327 14.0000000105266 14.9999999985317 1000000

Solution tests: P(8.00000000156914) = 7.96875 P(10.0000000317527) = 8.3125 P(8.99999998928141) = 7.46875 P(12.0000000528519) = 6.65625 P(10.9999999472538) = 7.875 P(12.9999999682327) = 8.3125 P(14.0000000105266) = 7.53125 P(14.9999999985317) = 1.96875 P(1000000) = 1.1640787172316e+38

The solution tests are much better except the last.

I may, if x is large, eval reverted polynomial with 1/x.

emsr commented 5 years ago

I am using eval of reverted poly for x> 1. I might tweak this to x > 1 + ep later.

Fixed it with S_huge = max() in JT. Aside: Used ilogb in JT scaling.