Chebyshev coefficients: Difference between revisions
Content added Content deleted
(Added Algol 68) |
(Added Algol W) |
||
Line 142: | Line 142: | ||
0.00000000065963 |
0.00000000065963 |
||
-0.00000000001002 |
-0.00000000001002 |
||
</pre> |
|||
=={{header|ALGOL W}}== |
|||
{{Trans|Java}}... using nested procedures. In Algol W, procedures can't find the bounds of array parameters, so an extra parameter is reuired for the chebyshevCoef procedure. |
|||
<syntaxhighlight lang="algolw"> |
|||
begin % Chebyshev coefficients % |
|||
procedure chebyshevCoef ( real procedure func |
|||
; real value min, max |
|||
; real array coef ( * ) |
|||
; integer value N |
|||
) ; |
|||
begin |
|||
real procedure map ( real value x, min_x, max_x, min_to, max_to ) ; |
|||
( x - min_x ) / ( max_x - min_x ) * ( max_to - min_to ) + min_to; |
|||
for i := 0 until N - 1 do begin |
|||
real m, f; |
|||
m := map( cos( PI * ( i + 0.5 ) / N ), -1, 1, min, max ); |
|||
f := func( m ) * 2 / N; |
|||
for j := 0 until N - 1 do begin |
|||
coef( j ) := coef( j ) + f * cos( PI * j * ( i + 0.5 ) / N ) |
|||
end for_j |
|||
end for_i |
|||
end chebyshevCoef ; |
|||
begin |
|||
integer N; |
|||
N := 10; |
|||
begin |
|||
real array c ( 0 :: N - 1 ); |
|||
chebyshevCoef( cos, 0, 1, c, N ); |
|||
write( "Coefficients:" ); |
|||
for i := 0 until N - 1 do write( r_format := "S", r_w := 14, c( i ) ) |
|||
end |
|||
end |
|||
end. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Coefficients: |
|||
1.6471694'+00 |
|||
-2.3229937'-01 |
|||
-5.3715114'-02 |
|||
2.4582352'-03 |
|||
2.8211905'-04 |
|||
-7.7222291'-06 |
|||
-5.8985564'-07 |
|||
1.1521427'-08 |
|||
6.5963014'-10 |
|||
-1.0021983'-11 |
|||
</pre> |
</pre> |
||