Chebyshev coefficients: Difference between revisions

Content deleted Content added
Add Julia language
m →‎{{header|REXX}}: changed a comment and some whitespace, changed comments in the REXX section header, used a template for the output sections.
Line 772:
=={{header|REXX}}==
{{trans|C}}
 
This REXX program is a translation of the   '''C'''   program plus added optimizations.
Pafnuty Lvovich Chebysheff: Chebyshev [English transliteration]
<pre>
Tschebyscheff Chebysheff [ " " ]
Pafnuty Lvovich Chebysheff: Chebyshev [English transliteration]
Chebysheff Chebyshov [ " " ]
Chebyshov Tchebychev [ " [French " ]
Tchebychev Tchebysheff [French " " ]
Tchebysheff [Tschebyschow " [German " ]
Tschebyschow Tschebyschev [German " " ]
Tschebyschev Tschebyschef [ " " ]
Tschebyschef Tschebyscheff [ " " ]
Tschebyscheff [ " " ]
</pre>
<lang rexx>/*REXX program calculates N Chebyshev coefficients for the range 0 ──► 1 (inclusive)*/
numeric digits length( pi() ) - 1 /*DIGITS default is nine, but use 71. */
parse arg a b N . /*obtain optional arguments from the CL*/
if a=='' | a=="," then a= 0 /*A not specified? Then use default.*/
if b=='' | b=="," then b= 1 /*B " " " " " */
if N=='' | N=="," then N=10 /*N " " " " " */
fac=2 / N; pin=pi / N /*calculate a couple handy─dandy values*/
Dma= (b-a) /2 2 /*calculate one─half of the difference.*/
Dpa= (b+a) /2 2 /* " " " " sum. */
do k=0 for N
f.k=cos( cos( pin * (k + .5) ) * Dma + Dpa)
end /*k*/
 
do j=0 for N; z=pin * j /*The LEFT('', ···) ──────►──────┐ */
$=0 $=0 /*clause is used to align │ */
do m=0 for N /*the non─negative values with ↓ */
$=$ + f.m * cos(z*(m + .5)) /*the negative values. │ */
end /*m*/ /* ┌────────◄──────┘ ┌─────◄──────┘ */
cheby.j=fac * $ /* */
say right(j, length(N) +3) " Chebyshev coefficient is:" left('', cheby.j >= 0),
format(cheby.j, , 30) /*displayonly show 30 decimal digits of the 71coeff. */
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 815 ⟶ 814:
/*──────────────────────────────────────────────────────────────────────────────────────*/
pi: pi=3.1415926535897932384626433832795028841971693993751058209749445923078164;return pi
r2r: return arg(1) // (pi() * 2) /*normalize radians ───► a unit circle.*/</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
'''{{out|output''' |text=&nbsp; when using the default inputs:}}
r2r: return arg(1) // (pi()*2) /*normalize radians ───► a unit circle.*/</lang>
'''output''' &nbsp; when using the default inputs:
<pre>
0 Chebyshev coefficient is: 1.647169475390313686961473816798
Line 830 ⟶ 828:
9 Chebyshev coefficient is: -1.002259170944625675156620531665E-11
</pre>
'''{{out|output''' |text=&nbsp; when using the following input of: &nbsp; &nbsp; <tt> , &nbsp; , &nbsp; 20 </tt>}}
<pre>
0 Chebyshev coefficient is: 1.647169475390313686961473816799