1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.ranges math.vectors namespaces
5 IN: math.numerical-integration
9 180 num-steps set-global
11 : setup-simpson-range ( from to -- frange )
12 2dup swap - num-steps get / <range> ;
14 : generate-simpson-weights ( seq -- seq )
15 length 2 / 2 - { 2 4 } <repetition> concat
16 { 1 4 } { 1 } surround ;
18 : integrate-simpson ( from to quot -- x )
19 [ setup-simpson-range dup ] dip
20 map dup generate-simpson-weights
21 v. swap [ third ] keep first - 6 / * ; inline