' ******************************************************************
' This program computes the area under an experimental curve
' by the trapezoidal rule. The result is compared with the
' exact value.
'
' Data are generated with the function exp(-x) for x = 0..1
'
' The exact integral is:
'
' (1
' |  exp(-x) dx = 1 - exp(-1) ~ 0.6321
' )0
' ******************************************************************

#INCLUDE "fbmath.bi"

CONST N = 10

DIM AS DOUBLE X(0 TO N), Y(0 TO N)

DIM AS INTEGER I

FOR I = 0 TO N
  X(I) = 0.1 * I
  Y(I) = EXP(-X(I))
NEXT I

PRINT "     X         Y"
PRINT "--------------------"

FOR I = 0 TO N
  PRINT USING "#####.####"; X(I); Y(I)
NEXT I

PRINT "--------------------"
PRINT
PRINT "Area under curve:"
PRINT
PRINT USING "TrapInt: #####.####"; TrapInt(X(), Y())
PRINT USING "Exact  : #####.####"; 1 - EXP(-1)

SLEEP
