25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

solver.h 1.3 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class RemezSolver
  17. {
  18. public:
  19. typedef lol::real RealFunc(lol::real const &x);
  20. RemezSolver(int order, int decimals);
  21. void Run(lol::real a, lol::real b,
  22. RealFunc *func, RealFunc *weight = nullptr);
  23. private:
  24. void Init();
  25. void FindZeroes();
  26. lol::real FindExtrema();
  27. void Step();
  28. void PrintPoly();
  29. lol::real EvalEstimate(lol::real const &x);
  30. lol::real EvalFunc(lol::real const &x);
  31. lol::real EvalWeight(lol::real const &x);
  32. private:
  33. /* User-defined parameters */
  34. RealFunc *m_func, *m_weight;
  35. int m_order, m_decimals;
  36. /* Solver state */
  37. lol::polynomial<lol::real> m_estimate;
  38. lol::array<lol::real> m_zeroes;
  39. lol::array<lol::real> m_control;
  40. lol::real m_k1, m_k2, m_epsilon;
  41. /* Statistics */
  42. float m_stats_cheby;
  43. float m_stats_func;
  44. float m_stats_weight;
  45. };