Numerical integration/Gauss-Legendre Quadrature: Difference between revisions

m
→‎version 2: aligned subroutine headers with subroutine code. -- ~~~~
(→‎version 2: simplied the COSine subroutine. -- ~~~~)
m (→‎version 2: aligned subroutine headers with subroutine code. -- ~~~~)
Line 1,279:
say '... and took' format(time('e'),,2) "seconds,"
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────COS subroutine──────────────────────subroutine───────────────────────────────*/
cos: procedure; x=r2r(arg(1)); numeric fuzz min(9,digits()-9); _=1; z=1; p=1; x=x*x
do k=2 by 2; _=-_*x/(k*(k-1)); z=z+_; if z=p then return z; p=z; end
/*──────────────────────────────────E subroutine────────────────────────subroutine──────────────────────────────────────*/
e: return 2.7182818284590452353602874713526624977572470936999595749669676277240766303535
/*──────────────────────────────────EXP subroutine──────────────────────subroutine────────────────────────────────────*/
exp: procedure; parse arg x; ix=x%1; if abs(x-ix)>.5 then ix=ix+sign(x); x=x-ix
z=1; _=1; w=z; do j=1; _=_*x/j; z=(z+_)/1; if z==w then leave; w=z; end
if z\==0 then z=z*e()**ix; return z
/*──────────────────────────────────PI subroutine───────────────────────subroutine──────────────────────────────────────*/
pi: return 3.1415926535897932384626433832795028841971693993751058209749445923078164062862
/*──────────────────────────────────R2R subroutine──────────────────────*/