Chebyshev coefficients: Difference between revisions

(EasyLang)
Line 590:
1.0 0.54030231 0.54030231 -4.476e-13
</pre>
 
=={{header|Groovy}}==
{{trans|Java}}
<lang groovy>class ChebyshevCoefficients {
static double map(double x, double min_x, double max_x, double min_to, double max_to) {
return (x - min_x) / (max_x - min_x) * (max_to - min_to) + min_to
}
 
static void chebyshevCoef(Closure<Double> func, double min, double max, double[] coef) {
final int N = coef.length
for (int i = 0; i < N; i++) {
double m = map(Math.cos(Math.PI * (i + 0.5f) / N), -1, 1, min, max)
double f = func(m) * 2 / N
 
for (int j = 0; j < N; j++) {
coef[j] += f * Math.cos(Math.PI * j * (i + 0.5f) / N)
}
}
}
 
static void main(String[] args) {
final int N = 10
double[] c = new double[N]
double min = 0, max = 1
chebyshevCoef(Math.&cos, min, max, c)
 
println("Coefficients:")
for (double d : c) {
println(d)
}
}
}</lang>
{{out}}
<pre>Coefficients:
1.6471694753903139
-0.23229937161517178
-0.0537151146220477
0.002458235266981773
2.8211905743405485E-4
-7.722229156320592E-6
-5.898556456745974E-7
1.1521427770166959E-8
6.59630183807991E-10
-1.0021913854352249E-11</pre>
 
=={{header|J}}==
1,452

edits