Numerical integration: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: Added 'Promise' for concurrency)
m (→‎{{header|Perl 6}}: corrected formatting tags)
Line 3,402: Line 3,402:
.say for integrate '*.self', 0, 6_000, 6_000_000, 18_000_000;</lang>
.say for integrate '*.self', 0, 6_000, 6_000_000, 18_000_000;</lang>
{{out}}
{{out}}
<lang>{ $_ ** 3 }
<pre>{ $_ ** 3 }
in [0..1] / 100
in [0..1] / 100
exact result: 0.25
exact result: 0.25
Line 3,436: Line 3,436:
rectangle method mid: 18000000
rectangle method mid: 18000000
composite trapezoidal rule: 18000000
composite trapezoidal rule: 18000000
quadratic simpsons rule: 18000000</lang>
quadratic simpsons rule: 18000000</pre>


Note that these integrations are done with rationals rather than floats, so should be fairly precise (though of course with so few iterations they are not terribly accurate (except when they are)). Some of the sums do overflow into <tt>Num</tt> (floating point)--currently Rakudo allows 64-bit denominators--but at least all of the interval arithmetic is exact.
Note that these integrations are done with rationals rather than floats, so should be fairly precise (though of course with so few iterations they are not terribly accurate (except when they are)). Some of the sums do overflow into <tt>Num</tt> (floating point)--currently Rakudo allows 64-bit denominators--but at least all of the interval arithmetic is exact.