Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

60 rindas
1.3 KiB

  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. };