You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

solver.h 1.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // LolRemez - Remez algorithm implementation
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #pragma once
  11. //
  12. // The RemezSolver class
  13. // ---------------------
  14. //
  15. #include <cstdio>
  16. template<typename NUMERIC_T> class RemezSolver
  17. {
  18. public:
  19. typedef NUMERIC_T RealFunc(NUMERIC_T const &x);
  20. inline RemezSolver()
  21. : m_order(0)
  22. {
  23. }
  24. void Run(int order, int decimals, NUMERIC_T a, NUMERIC_T b,
  25. RealFunc *func, RealFunc *weight = nullptr);
  26. NUMERIC_T EvalCheby(NUMERIC_T const &x);
  27. void Init();
  28. void FindZeroes();
  29. NUMERIC_T FindExtrema();
  30. void Step();
  31. int Cheby(int n, int k);
  32. int Comb(int n, int k);
  33. void PrintPoly();
  34. NUMERIC_T EvalFunc(NUMERIC_T const &x);
  35. NUMERIC_T Weight(NUMERIC_T const &x);
  36. private:
  37. int m_order;
  38. lol::Array<NUMERIC_T> m_coeff;
  39. lol::Array<NUMERIC_T> m_zeroes;
  40. lol::Array<NUMERIC_T> m_control;
  41. RealFunc *m_func, *m_weight;
  42. NUMERIC_T m_k1, m_k2, m_invk1, m_invk2, m_epsilon;
  43. int m_decimals;
  44. };