Canola
0.8.D001
|
00001 // 00002 // canola - canon canola 1614p emulator 00003 // Copyright (C) 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License, version 3, as 00007 // published by the Free Software Foundation. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License along 00015 // with this program. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef LIB_POLYFIT_H 00019 #define LIB_POLYFIT_H 00020 00025 class polyfit 00026 { 00027 public: 00031 virtual ~polyfit(); 00032 00039 polyfit(int order = 1); 00040 00050 void enter(double x, double y); 00051 00052 enum solve_t 00053 { 00054 solve_ok, 00055 solve_singular, 00056 solve_insufficient 00057 }; 00058 00064 solve_t solve(void); 00065 00075 double coefficient(int n); 00076 00086 double evaluate(double x); 00087 00092 void print(void) const; 00093 00098 bool enough_points(void) const { return matrix[0][0] >= rows; } 00099 00100 private: 00105 unsigned int rows; 00106 00111 unsigned int cols; 00112 00113 typedef long double data_t; 00114 00119 data_t *coefficients; 00120 00126 data_t **matrix; 00127 00132 static data_t epsilon; 00133 00140 data_t **mat_alloc(); 00141 00149 void mat_dump(data_t **data); 00150 00158 void mat_free(data_t **data); 00159 00163 polyfit(); 00164 00168 polyfit(const polyfit &); 00169 00173 polyfit &operator=(const polyfit &); 00174 }; 00175 00176 #endif // LIB_POLYFIT_H