Jump to content

Chebyshev coefficients: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
m (→‎{{header|Sidef}}: updated code)
Line 2,161:
<syntaxhighlight lang="ruby">func chebft (callback, a, b, n) {
 
var bma = (0.5 * b-a);
var bpa = (0.5 * b+a);
 
var pi_n = ((0..(^n-1)  »+» 0.5)  »*» (NumberNum.pi / n));
var f = (pi_n  »cos»() » »*» bma  »+» bpa «call«  callback);
var sums = (0..(^n-1) «run«  {|i| f  »*«  ((pi_n  »*» i)  »cos»()») «+» });
 
sums  »*» (2/n);
}
 
for v in (chebft(func(v){v.cos}, 0, 1, 10).each) { |v|
say ("%+.10e" % v);
}</syntaxhighlight>
 
Line 2,188:
-1.0022591709e-11
</pre>
 
=={{header|Swift}}==
 
2,747

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.