|
|
|
|
|
by Fredkin
623 days ago
|
|
Math.sin(x)/x (the sinc function) for 7 terms over [-3,3] gives coefficients c0...c6 that are all NaNs. Is this a bug? To work around it, I handled the x near zero case by just forcing to 1.0. if(Math.abs(x) > 1e-8 ){ Math.sin(x)/x } else { 1.0 } |
|
That wouldn't exactly be a bug. The code is undoubtedly calculating the Chebyshev coefficients by evaluating the function on something like x_j = (xmin) + (xmax - xmin)/2(1 + cos(pi[0..j-1]/(j-1)). If one of those grid points happens to be exactly 0, it will try to evaluate Math.sin(0)/0, giving the NaN.
Another workaround is to have a slightly asymmetric range, such as [-3,+3.0000001]