Chebyshev coefficients: Difference between revisions

m
→‎{{header|Perl}}: formatted output
m (→‎{{header|Raku}}: did not need .list coercion)
m (→‎{{header|Perl}}: formatted output)
Line 1,375:
{{trans|C}}
 
<lang perl>use constant PI => 3.1415926535897932 * atan2(1, 0);
 
sub chebft {
Line 1,382:
 
my @pin = map { ($_ + 0.5) * (PI/$n) } 0..$n-1;
my @f = map { $func->( cos($_) * $bma + $bpa ) } @pin;
my @c = (0) x $n;
for my $j (0 .. $n-1) {
$c[$j] += $f[$_] * cos($j * $pin[$_]) for 0..$n-1;
$c[$j] *= (2.0/$n);
}
@c;
}
 
printprintf "$_%+13.7e\n", $_ for chebft(sub{cos($_[0])}, 0, 1, 10);</lang>
 
{{out}}
<pre>+1.647169475390316471695e+00
-2.3229937e-01
-0.232299371615172
-5.3715115e-02
-0.0537151146220477
+2.4582353e-03
0.00245823526698163
+2.8211906e-04
0.000282119057433938
-7.72222915566001e7222292e-06
-5.89855645105608e8985565e-07
+1.15214274787334e1521427e-08
+6.59629917354465e5962992e-10
-1.00219943455215e0021994e-11</pre>
 
=={{header|Phix}}==
2,392

edits