Numerical integration: Difference between revisions
Content added Content deleted
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: | Line 4,285: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Note: there was virtually no difference between '''numeric digits 9''' (the default) and '''numeric digits 20'''. |
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.*/ |
<lang rexx>/*REXX pgm performs numerical integration using 5 different algorithms and show results.*/ |
||
numeric digits 20 /*use twenty decimal digits precision. */ |
numeric digits 20 /*use twenty decimal digits precision. */ |
||
Line 4,308: | Line 4,308: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
left_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n |
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 |
return $*h/1 |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
midpoint_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n |
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 |
return $*h/1 |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
right_rect: procedure expose test; parse arg a,b,n; $= 0; h= (b-a)/n |
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 |
return $*h/1 |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Simpson: procedure expose test; parse arg a,b,n; h= (b-a)/n |
Simpson: procedure expose test; parse arg a,b,n; h= (b-a)/n; hh= h/2 |
||
$= f(a + h/2) |
$= f(a + h/2) |
||
@= 0; |
@= 0; do x=1 for n-1; hx=h*x; $=$+f(a+hx+hh); @=@+f(a+hx); end /*x*/ |
||
return h * (f(a) + f(b) + 4*$ + 2*@) / 6 |
return h * (f(a) + f(b) + 4*$ + 2*@) / 6 |