Hacker News new | past | comments | ask | show | jobs | submit login

Also pretty easy:

  import numpy as np

  p = np.polynomial.Chebyshev.interpolate(f, degree, domain=(xmin, xmax))

  # insert your code to print out some C code
Also strongly recommend some basic familiarity with the theory. Approximating `Math.abs(x)` to even a few digits of uniform accuracy on any interval containing 0 requires tens if not hundreds of thousands of coefficients.



what does the

     # insert your code to print out some C code
mean?


For instance, maybe I want to define an array of these coefficients in C.

I could do:

    print('double coef[] = {')
    for c in p.coef:
        print(f'    {c:0.16g},')
    print('};')
and copy-paste it wherever I need.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: