Anonymous user
Numerical integration/Gauss-Legendre Quadrature: Difference between revisions
Numerical integration/Gauss-Legendre Quadrature (view source)
Revision as of 21:46, 1 November 2013
, 10 years ago→version 2: re-instated the latest version for REXX version 2. -- ~~~~
Walterpachl (talk | contribs) m (→version 1: corrected time 'E' to time 'R' (reset)) |
m (→version 2: re-instated the latest version for REXX version 2. -- ~~~~) |
||
Line 1,235:
:::* about 1/6 the computing time
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
call time 'Reset'
numeric digits
numeric digits
numeric digits digs+10; times = digs%2 + 1
say 'step' center("iterative value",digs+3) ' difference ' /*show hdr*/
sep='────' copies('─' ,digs+3) '────────────'; say sep
do step=1 for times;
p1z=2; p1.1=1; p1.2=0; r.=0
/*█*/ do L=1 for p1z;
/*█*/ end /*L*/
/*█*/ do L=1 for p0z; L2=L+2; TT.L2=p0.L
/*█*/
/*█*/
end /*L*/▼
/*█*/
/*█*/
▲ p1z=p1z+1; do j=1 for p1z; p1.j= T.j ; end /*j*/
▲ end /*k*/
do
dx=f/df;
▲ r.2.!=2/((1-x*x)*df*df)
sum=0
do m=1
▲ z=bma*sum*.5
▲ say right(step,4) format(z,2,digs) format(z-true,2,4,,0)
end /*step*/
say sep; say left('',4) true " {exact}"
say '... and took' format(time('e'),,2) "seconds."
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────COS
cos: procedure; x=r2r(arg(1)); numeric fuzz min(9,digits()-9); _=1; z=1
/*──────────────────────────────────E subroutine──────────────────────────────────────*/
e: return 2.7182818284590452353602874713526624977572470936999595749669676277240766303535
/*──────────────────────────────────EXP
exp: procedure; parse arg x;
x=x-ix; z=1; _=1;
if z\==0 then z=z*e()**ix; return z
/*──────────────────────────────────PI subroutine──────────────────────────────────────*/
|