factor/extra/math/numerical-integration/numerical-integration.factor

22 lines
612 B
Factor
Raw Normal View History

2008-10-03 03:19:03 -04:00
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2009-04-17 12:14:16 -04:00
USING: kernel math math.ranges math.vectors namespaces
sequences ;
2007-09-20 18:09:08 -04:00
IN: math.numerical-integration
2008-12-07 00:12:38 -05:00
SYMBOL: num-steps
180 num-steps set-global
2008-10-03 03:19:03 -04:00
2007-09-20 18:09:08 -04:00
: setup-simpson-range ( from to -- frange )
2dup swap - num-steps get / <range> ;
: generate-simpson-weights ( seq -- seq )
length 1 + 2/ 2 - { 2 4 } <repetition> concat
2008-12-07 00:12:38 -05:00
{ 1 4 } { 1 } surround ;
2007-09-20 18:09:08 -04:00
2009-04-17 12:14:16 -04:00
: integrate-simpson ( from to quot -- x )
[ setup-simpson-range dup ] dip
2008-10-03 03:19:03 -04:00
map dup generate-simpson-weights
2020-02-26 15:40:16 -05:00
vdot swap [ third ] keep first - 6 / * ; inline