Numerical integration: Difference between revisions

m
→‎{{header|REXX}}: changed wording in the REXX section header, optimized one procedure (about 5% faster).
m (used a blank to not split the pseudocode paragraph into two parts.)
m (→‎{{header|REXX}}: changed wording in the REXX section header, optimized one procedure (about 5% faster).)
Line 4,285:
 
=={{header|REXX}}==
Note:   there was virtually no difference in accuracy between   '''numeric digits 9'''   (the default)   and   '''numeric digits 20'''.
<lang rexx>/*REXX pgm performs numerical integration using 5 different algorithms and show results.*/
numeric digits 20 /*use twenty decimal digits precision. */
Line 4,308:
/*──────────────────────────────────────────────────────────────────────────────────────*/
left_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n
do x=a by h for n; $= $ + f(x); end /*x*/
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
midpoint_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n
do x=a+h/2 by h for n; $= $ + f(x); end /*x*/
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
right_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n
do x=a+h by h for n; $= $ + f(x); end /*x*/
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
Simpson: procedure expose test; parse arg a,b,n; h= (b-a)/n; hh= h/2
$= f(a + h/2)
@= 0; do x=1 for n-1; $hx=h*x; $=$+f(a+h*xhx+h*.5hh); @= @+f(a+x*hhx); end /*x*/
 
return h * (f(a) + f(b) + 4*$ + 2*@) / 6