]> gitweb.factorcode.org Git - factor.git/blob - extra/math/numerical-integration/numerical-integration.factor
Updating code for make and fry changes
[factor.git] / extra / math / numerical-integration / numerical-integration.factor
1 USING: arrays kernel sequences namespaces make math math.ranges
2 math.vectors vectors ;
3 IN: math.numerical-integration
4
5 SYMBOL: num-steps 180 num-steps set-global
6 : setup-simpson-range ( from to -- frange )
7     2dup swap - num-steps get / <range> ;
8
9 : generate-simpson-weights ( seq -- seq )
10     [
11         { 1 4 } % length 2 / 2 - { 2 4 } <repetition> concat % 1 ,
12     ] { } make ;
13
14 : integrate-simpson ( from to f -- x )
15     >r setup-simpson-range r>
16     dupd map dup generate-simpson-weights
17     v. swap [ third ] keep first - 6 / * ;
18