Hi, here is a very simple integration (no special method applied)
for testing f+ and f*.
It integrates y=x^3 from A to B. Currently A=-B (e.g. -1 to +1) thus
the result shall be zero. Still thinking on N in the loop (:-)).
Pito
-------------------------
marker -testadd
\ very simple integration to test float add, sub
\ needs float constants
\ INTEGRAL from A to B of the function Y=X^3
\ A=-B, So the result shall be 0
-1 s>f fconstant _-1
0 s>f fconstant _0
\ FROM A TO B
-1 s>f fconstant A
A _-1 f* fconstant B
300 constant N
B A f- N s>f f/ fconstant delta
fvariable INTG
fvariable X
fvariable Y
variable NLoop
: p6 _1e6 f* f>d d. ." .1e-6 " ;
: p3 _1e3 f* f>d d. ." .1e-3 " ;
: Y=X^3 fdup fdup f* f* ;
: Y=X^2 fdup f* ;
: print_INTG INTG f@ p3 ;
: INTEGRAL
A X f!
_0 INTG f!
N 1 + NLoop !
NLoop @ 0 do
X f@ Y=X^3 Y f!
\ print X, Y
cr cr X f@ ." X=" p6 cr Y f@ ." Y=" p3
Y f@ INTG f@ f+ INTG f!
X f@ delta f+ X f!
\ print
cr INTG f@ ." INTG=" p3
loop
\ print
cr cr ." RESULT=" print_INTG
;
-----------------
Ex:
.....
X=1000004 .1e-6
Y=1000 .1e-3
INTG=1 .1e-3
RESULT=1 .1e-3 ok
>
|