Chebyshev coefficients: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
m (→‎{{header|Sidef}}: updated code)
Line 2,161: Line 2,161:
<syntaxhighlight lang="ruby">func chebft (callback, a, b, n) {
<syntaxhighlight lang="ruby">func chebft (callback, a, b, n) {


var bma = (0.5 * b-a);
var bma = (0.5 * b-a)
var bpa = (0.5 * b+a);
var bpa = (0.5 * b+a)


var pi_n = ((0..(n-1) »+» 0.5) »*» (Number.pi / n));
var pi_n = ((^n »+» 0.5) »*» (Num.pi / n))
var f = (pi_n »cos»() »*» bma »+» bpa «call« callback);
var f = (pi_n »cos()» »*» bma »+» bpa «call« callback)
var sums = (0..(n-1) «run« {|i| f »*« ((pi_n »*» i) »cos»()) «+» });
var sums = (^n «run« {|i| f »*« ((pi_n »*» i) »cos()») «+» })


sums »*» (2/n);
sums »*» (2/n)
}
}


chebft(func(v){v.cos}, 0, 1, 10).each { |v|
for v in (chebft(func(v){v.cos}, 0, 1, 10)) {
say ("%+.10e" % v);
say ("%+.10e" % v)
}</syntaxhighlight>
}</syntaxhighlight>


Line 2,188: Line 2,188:
-1.0022591709e-11
-1.0022591709e-11
</pre>
</pre>

=={{header|Swift}}==
=={{header|Swift}}==