Chebyshev coefficients: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments.) |
|||
Line 989: | Line 989: | ||
numeric digits length( pi() ) - 1 /*DIGITS default is nine, but use 71. */ |
numeric digits length( pi() ) - 1 /*DIGITS default is nine, but use 71. */ |
||
parse arg a b N . /*obtain optional arguments from the CL*/ |
parse arg a b N . /*obtain optional arguments from the CL*/ |
||
if a=='' | a=="," then a= |
if a=='' | a=="," then a= 0 /*A not specified? Then use default.*/ |
||
if b=='' | b=="," then b= |
if b=='' | b=="," then b= 1 /*B " " " " " */ |
||
if N=='' | N=="," then N= |
if N=='' | N=="," then N= 10 /*N " " " " " */ |
||
fac=2 / N; |
fac= 2 / N; pin= pi / N /*calculate a couple handy─dandy values*/ |
||
Dma= (b-a) / 2 /*calculate one─half of the difference.*/ |
Dma= (b-a) / 2 /*calculate one─half of the difference.*/ |
||
Dpa= (b+a) / 2 /* " " " " sum. */ |
Dpa= (b+a) / 2 /* " " " " sum. */ |
||
do k=0 for N |
do k=0 for N; f.k= cos( cos( pin * (k + .5) ) * Dma + Dpa) |
||
f.k=cos( cos( pin * (k + .5) ) * Dma + Dpa) |
|||
end /*k*/ |
end /*k*/ |
||
do j=0 for N; z=pin * j |
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 |
do m=0 for N /* the non─negative values with ↓ */ |
||
$=$ + f.m * cos(z*(m + |
$= $ + f.m * cos(z*(m +.5)) /* the negative values. │ */ |
||
end /*m*/ /* ┌─────◄──────┘ */ |
end /*m*/ /* ┌─────◄──────┘ */ |
||
cheby.j=fac * $ |
cheby.j= fac * $ /* ↓ */ |
||
say right(j, length(N) +3) " Chebyshev coefficient is:" left('', cheby.j >= 0), |
say right(j, length(N) +3) " Chebyshev coefficient is:" left('', cheby.j >= 0), |
||
format(cheby.j, , 30) /*only show 30 decimal digits of coeff.*/ |
format(cheby.j, , 30) /*only show 30 decimal digits of coeff.*/ |
||
Line 1,011: | Line 1,010: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
cos: procedure; parse arg x; numeric digits digits()+9; x=r2r(x); a=abs(x); numeric fuzz 5 |
cos: procedure; parse arg x; numeric digits digits()+9; x=r2r(x); a=abs(x); numeric fuzz 5 |
||
if a=pi then return -1; if a=pi*.5 | a=pi*2 then return 0; pit= pi/3; z= 1 |
|||
if a=pit then return .5; if a=pit*2 then return -.5; q= x*x; _= 1 |
|||
do ?=2 by 2 until p=z; p= z; _= -_ * q/(?*(?-1)); z= z + _; end /*?*/ |
|||
return z |
return z |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Line 1,052: | Line 1,051: | ||
18 Chebyshev coefficient is: -3.976201538410589537318561880598E-27 |
18 Chebyshev coefficient is: -3.976201538410589537318561880598E-27 |
||
19 Chebyshev coefficient is: 2.859065292763079576513213370136E-29 |
19 Chebyshev coefficient is: 2.859065292763079576513213370136E-29 |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/DqRNe2A/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/M5Ye6h8ZRkmTCNzexUh3uw Scastie (remote JVM)]. |
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/DqRNe2A/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/M5Ye6h8ZRkmTCNzexUh3uw Scastie (remote JVM)]. |