Spectral-Analysis-UPB / PyZEAL

Project dealing with the numerical calculation of zeros, poles and residues of holomorphic and meromorphic functions. It aspires to be a PYthon ZEAL (ZEros of AnaLytic functions, a Fortran90 package) successor.
https://pyzeal.readthedocs.io/en/latest/
GNU General Public License v3.0
4 stars 1 forks source link

Simple Argument Rootfinder misses roots in certain settings #12

Closed lwasmuth closed 1 year ago

lwasmuth commented 1 year ago

It appears that the Simple Argument Rootfinder sometimes misses some roots, depending on the function, search range and complexity. A minimal example is

from pyzeal.simple_argument import HoloRootFinder
import numpy as np

def f(x):
    return np.log(np.sin(x)**2+1)

if __name__ == "__main__":
    hrf = HoloRootFinder(f, epsCplx=1e-5*(1+1j))
    hrf.calcRoots((-5, 5.01), (-5, 5))
    print(hrf.res)
    hrf = HoloRootFinder(f, epsCplx=1e-5*(1+1j))
    hrf.calcRoots((-5, 5), (-5, 5))
    print(hrf.res)
    hrf = HoloRootFinder(f, epsCplx=1e-6*(1+1j))
    hrf.calcRoots((-5, 5.01), (-5, 5))
    print(hrf.res)
    hrf = HoloRootFinder(f, epsCplx=1e-6*(1+1j))
    hrf.calcRoots((-5, 5), (-5, 5))
    print(hrf.res)

log(sin(x)^2+1) should have zeroes at integer multiples of π, however, running this program returns four different results:

  1. [-3.14159671e+00+2.3159504e-07j -2.03881741e-06+2.3159504e-07j 3.14159263e+00+2.3159504e-07j]
  2. [-3.14159359e+00+2.3159504e-07j 2.31614113e-07+2.3159504e-07j]
  3. [3.1415925+2.01976567e-07j]
  4. []

All other test cases are solved correctly, so it seems to be at least related to something special about log(sin(x)^2+1).

lwasmuth commented 1 year ago

This seems to be caused by numerical inaccuracies which will not be resolved for now.