Changeset 2394 for trunk/src/lol/math/remez.h
 Timestamp:
 Feb 11, 2013, 4:27:49 PM (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/math/remez.h
r2183 r2394 57 57 printf("Step %i error: ", n); 58 58 newerror.print(m_decimals); 59 printf("\n"); 59 60 60 61 Step(); … … 77 78 } 78 79 79 T ChebyEval(T const &x)80 T EvalCheby(T const &x) 80 81 { 81 82 T ret = 0.0, xn = 1.0; … … 100 101 { 101 102 zeroes[i] = (T)(2 * i  ORDER) / (T)(ORDER + 1); 102 fxn[i] = Value(zeroes[i]);103 fxn[i] = EvalFunc(zeroes[i]); 103 104 } 104 105 … … 146 147 147 148 left.value = control[i]; 148 left.error = ChebyEval(left.value)  Value(left.value);149 left.error = EvalCheby(left.value)  EvalFunc(left.value); 149 150 right.value = control[i + 1]; 150 right.error = ChebyEval(right.value)  Value(right.value);151 right.error = EvalCheby(right.value)  EvalFunc(right.value); 151 152 152 153 static T limit = ldexp((T)1, 500); … … 155 156 { 156 157 mid.value = (left.value + right.value) / 2; 157 mid.error = ChebyEval(mid.value)  Value(mid.value);158 159 if ((left.error < zero && mid.error <zero)160  (left.error > zero && mid.error >zero))158 mid.error = EvalCheby(mid.value)  EvalFunc(mid.value); 159 160 if ((left.error <= zero && mid.error <= zero) 161  (left.error >= zero && mid.error >= zero)) 161 162 left = mid; 162 163 else … … 185 186 b = zeroes[i]; 186 187 187 T maxerror = 0, maxweight = 0;188 int best = 1;189 190 188 for (int round = 0; ; round++) 191 189 { 190 T maxerror = 0, maxweight = 0; 191 int best = 1; 192 192 193 T c = a, delta = (b  a) / 4; 193 194 for (int k = 0; k <= 4; k++) … … 195 196 if (round == 0  (k & 1)) 196 197 { 197 T error = ChebyEval(c)  Value(c); 198 T weight = Weight(c); 199 if (fabs(error * maxweight) >= fabs(maxerror * weight)) 198 T error = fabs(EvalCheby(c)  EvalFunc(c)); 199 T weight = fabs(Weight(c)); 200 /* if error/weight >= maxerror/maxweight */ 201 if (error * maxweight >= maxerror * weight) 200 202 { 201 203 maxerror = error; … … 218 220 b = a + delta * (best + 1); 219 221 a = a + delta * (best  1); 220 best = 2;221 222 break; 222 223 } … … 224 225 if (delta < m_epsilon) 225 226 { 226 T e = maxerror / maxweight;227 T e = fabs(maxerror / maxweight); 227 228 if (e > final) 228 229 final = e; … … 241 242 T fxn[ORDER + 2]; 242 243 for (int i = 0; i < ORDER + 2; i++) 243 fxn[i] = Value(control[i]);244 fxn[i] = EvalFunc(control[i]); 244 245 245 246 /* We build a matrix of Chebishev evaluations: row i contains the … … 335 336 } 336 337 337 printf("Polynomial estimate: \n");338 printf("Polynomial estimate: "); 338 339 for (int j = 0; j < ORDER + 1; j++) 339 340 { 340 341 if (j) 341 printf("+"); 342 printf("x**%i*", j); 342 printf(" + x**%i * ", j); 343 343 an[j].print(m_decimals); 344 344 } 345 printf("\n ");346 } 347 348 T Value(T const &x)345 printf("\n\n"); 346 } 347 348 T EvalFunc(T const &x) 349 349 { 350 350 return m_func(x * m_k2 + m_k1);
Note: See TracChangeset
for help on using the changeset viewer.