Jump to content

Chebyshev coefficients: Difference between revisions

m
→‎{{header|Raku}}: more Unicode, fewer sigils
(Chebyshev coefficients en BASIC256)
m (→‎{{header|Raku}}: more Unicode, fewer sigils)
Line 1,614:
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2015.12}}
{{trans|C}}
 
{{trans|C}}
<lang perl6>sub chebft ( Code $func, Real $\a, Real $\b, Int $\n ) {
 
my $\bma = 0.5½ *× ( $b - $a );
my $\bpa = 0.5½ *× ( $b + $a );
 
my @pi_npi-n = ( (^$n).list »+» 0.5½ ) »*×» ( pi π/ $n );
my @f = ( @pi_n».cos »*×» $bma »+» $bpa )».&$func;
my @sums = (^n).map: { [+] @f »*׫ ( @pi_npi-n »*×» $_ )».cos }, ^$n;
 
return @sums »*×» ( 2 / $n );
}
 
say .fmtchebft('%+13.7e') for chebft &cos, 0, 1, 10)».fmt: '%+13.7e';</lang>
 
{{out}}
<pre>+1.6471695e+00
+1.6471695e+00
-2.3229937e-01
-5.3715115e-02
Line 1,642 ⟶ 1,640:
+1.1521427e-08
+6.5962992e-10
-1.0021994e-11</pre>
</pre>
 
=={{header|REXX}}==
2,392

edits

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