Anonymous user
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
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
midpoint_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
right_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
Simpson: procedure expose test; parse arg a,b,n; h= (b-a)/n; hh= h/2
$= f(a + h/2)
@= 0;
return h * (f(a) + f(b) + 4*$ + 2*@) / 6
|