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 = (( |
var pi_n = ((^n »+» 0.5) »*» (Num.pi / n)) |
||
var f = (pi_n |
var f = (pi_n »cos()» »*» bma »+» bpa «call« callback) |
||
var sums = ( |
var sums = (^n «run« {|i| f »*« ((pi_n »*» i) »cos()») «+» }) |
||
sums |
sums »*» (2/n) |
||
} |
} |
||
chebft(func(v){v.cos}, 0, 1, 10) |
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}}== |
||