Chebyshev coefficients: Difference between revisions

Content deleted Content added
Add Perl
Line 205:
8 Chebyshev coefficient is: 6.596300035120132380676859918562E-10
9 Chebyshev coefficient is: -1.002259170944625675156620531665E-11
</pre>
 
=={{header|zkl}}==
{{trans|C}}{{trans|Perl}}
<lang zkl>var [const] PI=(1.0).pi;
fcn chebft(a,b,n,func){
bma,bpa,fac := 0.5*(b - a), 0.5*(b + a), 2.0/n;
f:=n.pump(List,'wrap(k){ (PI*(0.5 + k)/n).cos():func(_*bma + bpa) });
n.pump(List,'wrap(j){
fac*n.reduce('wrap(sum,k){ sum + f[k]*(PI*j*(0.5 + k)/n).cos() },0.0);
})
}
chebft(0.0,1.0,10,fcn(x){ x.cos() }).enumerate().concat("\n").println();</lang>
{{out}}
<pre>
L(0,1.64717)
L(1,-0.232299)
L(2,-0.0537151)
L(3,0.00245824)
L(4,0.000282119)
L(5,-7.72223e-06)
L(6,-5.89856e-07)
L(7,1.15214e-08)
L(8,6.5963e-10)
L(9,-1.00219e-11)
</pre>