Numerical integration/Gauss-Legendre Quadrature: Difference between revisions

m
→‎version 2: added more optimization. -- ~~~~
m (→‎version 1: added my Prolog that was removed by GS)
m (→‎version 2: added more optimization. -- ~~~~)
Line 1,237:
Note that the function values for   '''pi'''   and   '''e'''   should have more precision than the number of digits specified.
<lang rexx>/*REXX pgm does numerical integration using Gauss-Legendre Quadrature. */
/*REXX pgm does numerical integration using Gauss-Legendre Quadrature. */
digs=40; d2=digs*2; tiny = '1E-'d2 /*equivalent to 1÷10**d2 */
numeric digits digs; pi=pi(); a=-3; b=3; bma =b-a; bpa =b+a
numeric digits d2; true = exp(b)-exp(a); bmaH=bma/2; bpaH=bpa/2
numeric digits digs+10; times = digs%2 + 1
numeric digits d2; true = exp(b) - exp(a)
numeric digits digs+10; times = digs%2 + 1
Line 1,271 ⟶ 1,274:
end /*!*/
sum=0
do m=1 for step; sum=sum+r.2.m*exp(bpa*.5bpaH+r.1.m*bma*.5bmaH)
end /*m*/
z=bmabmaH*sum*.5
say right(step,4) format(z,2,digs) translate(format(z-true,2,4,,0),'e',"E")
end /*step*/