Jump to content

Numerical integration: Difference between revisions

m
→‎{{header|REXX}}: changed the format of the output to use arrows, used a better/cleaner name for some algorithms in the output.
m (→‎{{header|REXX}}: changed the trapezium function's returned value, changed some comments.)
m (→‎{{header|REXX}}: changed the format of the output to use arrows, used a better/cleaner name for some algorithms in the output.)
Line 3,588:
say
say center('test' test,65,'─') /*display a header for the test suite. */
say ' left_rectangularleft rectangular('L", "H', 'i") = " ──► " left_rect(L, H, i)
say ' midpoint_rectangularmidpoint rectangular('L", "H', 'i") = " ──► " midpoint_rect(L, H, i)
say ' right_rectangularright rectangular('L", "H', 'i") = " ──► " right_rect(L, H, i)
say ' Simpson('L", "H', 'i") = ──► " Simpson(L, H, i)
say ' trapezium('L", "H', 'i") = ──► " trapezium(L, H, i)
end /*test*/
exit /*stick a fork in it, we're all done. */
Line 3,623:
trapezium: procedure expose test; parse arg a,b,n; h=(b-a)/n
$=0
do x=a by h for n; $=$+(f(x)+f(x+h))*.5; end /*x*/
return $*h/12 /*return the number with no trailing 0s*/</lang>
'''output'''
<pre>
─────────────────────────────test 1──────────────────────────────
left_rectangularleft rectangular(0, 1, 100) = ──► 0.245025
midpoint_rectangularmidpoint rectangular(0, 1, 100) = ──► 0.2499875
right_rectangularright rectangular(0, 1, 100) = ──► 0.255025
Simpson(0, 1, 100) = ──► 0.25
trapezium(0, 1, 100) = ──► 0.250025
 
─────────────────────────────test 2──────────────────────────────
left_rectangularleft rectangular(1, 100, 1000) = ──► 4.6549910575146761473
midpoint_rectangularmidpoint rectangular(1, 100, 1000) = ──► 4.604762548678375185
right_rectangularright rectangular(1, 100, 1000) = ──► 4.5569810575146761472
Simpson(1, 100, 1000) = ──► 4.6051703849571421725
trapezium(1, 100, 1000) = ──► 4.6059860575146761454605986057514676146
 
─────────────────────────────test 3──────────────────────────────
left_rectangularleft rectangular(0, 5000, 5000000) = ──► 12499997.5
midpoint_rectangularmidpoint rectangular(0, 5000, 5000000) = ──► 12500000
right_rectangularright rectangular(0, 5000, 5000000) = ──► 12500002.5
Simpson(0, 5000, 5000000) = ──► 12500000
trapezium(0, 5000, 5000000) = ──► 12500000
 
─────────────────────────────test 4──────────────────────────────
left_rectangularleft rectangular(0, 6000, 5000000) = ──► 17999996.4
midpoint_rectangularmidpoint rectangular(0, 6000, 5000000) = ──► 18000000
right_rectangularright rectangular(0, 6000, 5000000) = ──► 18000003.6
Simpson(0, 6000, 5000000) = ──► 18000000
trapezium(0, 6000, 5000000) = ──► 18000000
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.