User:VIxen/Code: Difference between revisions
DR triad finder code |
10x speedup of printIsodiffTriads by keeping it simple |
||
| Line 71: | Line 71: | ||
int printIsodiffTriads(){ | int printIsodiffTriads(){ | ||
/* Find triads in ETs that satisfy the frequency relation bottom + top == 2 * middle. | /* Find triads in ETs that satisfy the frequency relation bottom + top == 2 * middle. | ||
The root of x^{top} - 2 * x^{mid} + 1 is found by the Newton-Raphson method | The root of x^{top} - 2 * x^{mid} + 1 is found by the Newton-Raphson method. */ | ||
const int MINDEG = 12; | const int MINDEG = 12; | ||
| Line 96: | Line 95: | ||
/* mid starts a bit lower than top to omit boring triads like 0-4k-4(k+1) */ | /* mid starts a bit lower than top to omit boring triads like 0-4k-4(k+1) */ | ||
do{ /* Step of Newton-Raphson | do{ /* Step of Newton-Raphson */ | ||
pwr = pow(x, mid); | |||
pwr = x; | val = 1. - 2. * pwr; | ||
val = - | der = -2. * mid * pwr / x; | ||
der = - | pwr *= pow(x, top - mid); | ||
val += pwr; | |||
der += top * pwr / x; | |||
x -= val / der; | x -= val / der; | ||
} while (val > 1e-5); | } while (val > 1e-5); | ||