]> gitweb.factorcode.org Git - factor.git/blob - extra/math/numerical-integration/numerical-integration.factor
acc22fa2a2bc989e5148c1f6f21ff4b0619fc0a5
[factor.git] / extra / math / numerical-integration / numerical-integration.factor
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
4 sequences ;
5 IN: math.numerical-integration
6
7 SYMBOL: num-steps
8
9 180 num-steps set-global
10
11 : setup-simpson-range ( from to -- frange )
12     2dup swap - num-steps get / <range> ;
13
14 : generate-simpson-weights ( seq -- seq )
15     length 1 + 2/ 2 - { 2 4 } <repetition> concat
16     { 1 4 } { 1 } surround ;
17
18 : integrate-simpson ( from to quot -- x )
19     [ setup-simpson-range dup ] dip
20     map dup generate-simpson-weights
21     vdot swap [ third ] keep first - 6 / * ; inline