Anonymous user
Numerical integration: Difference between revisions
m
→{{header|REXX}}: aligned statements better, optimized the Simpson function (about 6% faster).
(→{{header|REXX}}: optimized the ƒ function (it's about 4% faster).) |
m (→{{header|REXX}}: aligned statements better, optimized the Simpson function (about 6% faster).) |
||
Line 4,307:
return 1/y /* " " reciprocal " */
/*──────────────────────────────────────────────────────────────────────────────────────*/
left_rect: procedure expose test; parse arg a,b,
do x=a by h for
end /*x*/
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
midpoint_rect: procedure expose test; parse arg a,b,
do x=a+h/2 by h for
end /*x*/
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
right_rect: procedure expose test; parse arg a,b,
do x=a+h by h for
end /*x*/
return $*h/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
Simpson: procedure expose test; parse arg a,b,
hh=
@= 0; do x=1 for
$= $ + f(hx + hh)
end /*x*/
return h * (f(a) + f(b) + 4*$ + 2*@) / 6
/*──────────────────────────────────────────────────────────────────────────────────────*/
trapezium: procedure expose test; parse arg a,b,
end /*x*/
return $*h/2</lang>
{{out|output|text= when using the default inputs:}}
|