Numerical integration/Gauss-Legendre Quadrature: Difference between revisions

m
→‎version 2: optimized the COS subroutine. -- ~~~~
m (→‎version 2: simplfied the prologue stuff. -- ~~~~)
m (→‎version 2: optimized the COS subroutine. -- ~~~~)
Line 1,277:
/*▒*/ end /*m*/
z=bmaH*sum
say right(step,4) format(z,2,digs) translate(format(z-true,2,3,4,,0),'e',"E")
end /*step*/
 
Line 1,283:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────COS subroutine──────────────────────*/
cos: procedure; x=r2r(arg(1)); numeric fuzz min(9,digits()-9); _=1; z=1; y=x*x
y=x*x; do k=2 by 2 until p==z; p=z; _=-_*y/(k*(k-1)); z=z+_; end; return z
/*──────────────────────────────────E subroutine──────────────────────────────────────*/
e: return 2.7182818284590452353602874713526624977572470936999595749669676277240766303535