TUintegTrapI TCL UTILITIES USER MANUAL TUintegTrapI
SYNOPSIS
Perform a iterated trapezoidal integration of a function
PACKAGE
TCLUTILS
NAME
TUintegTrapI
USAGE
set rV  TUintegTrapI  FunC Beg End {ConV} {MaxI} {MinI} {DoOnce}]
INPUT DEFINITIONS
FunC - Procedure which defines the function being integrated over. This is described in detail under the procedure description.
Beg - The beginning integration limit.
End - The ending integration limit.
ConV - Optional input value defaulted to 1.0e-5. This is the convergence point at which the iterations will terminate.
MaxI - Optional input value defaulted to 20. This is the maxumum number of iterations to make. If the integration converges to ConV before this value is reached the iterations will terminate early.
MinI - Optional input value defaulted to 5. This is the minimum number of iterations to make. This number of iterations are performed regardless of ConV.
DoOnce - Describes how FunC operates.
0 : Func returns one value for each time it is called.
1 : Func returns all of the required integration values in one call.
RETURN DEFINITION
Returns the value associated with the integration.
DESCRIPTION
TUintegTrapI integrations a function from Beg to End to with the convergence criteria set in ConV.
The function being integrated is described in the input procedure FunC which returns the value of the function at one or multiple values of X. The procedure has the form
Y = FunC X dX nP Step
if DoOnce is 0 and
FunC X dX nP Step Y
if DoOnce is 1. In both cases dX is the intgration step size, nP the number of steps in this interation, and Step is the current step number. If DoOnce is 0 X is the X value of the current iteration step and the computed Y value is returned through the function. In general only the X input is used internal to the procedure. If DoOnce is 1 the X is the X value for step 0 in the integration and Y is an array of the nP values, one for each of the steps in the current integration. The X values used in the function are X + I * dX where I runs from 0 to nP-1.
The integration of the function in FunC is returned through the procedure.
ERRORS
None Generated
C BACKING
Yes
EXAMPLE(S)
EXAMPLE 1:
# INTEGRATE a function

# Define function Y = (x^2 + 10)^0.5

# USE this form for returning all of the function values in an interation
#   step at once.

proc FunCM { X dX nP cS OuT } {

   upvar $OuT Y

   for { set I 0 } { $I <= $nP } { incr I } {
      set Y($I) [expr sqrt($X * $X + 10.0)]
      set X [expr $X + $dX]
   }
}

# USE this form for returning only the value at the input X

proc FunCO { X dX nP cS } {
    set Y [expr sqrt($X * $X + 10.0)]
    return $Y
}

# INTEGRATE the function using DoOnce set to 1 for three different 
#   convergence values


set V [TUintegTrapI FunCM -2.0 5.0 1.0e-4 30 5 1]
puts stderr "Convergence 1.0e-4: Returned [format "%.5f" $V]; Actual 27.70886"
set V [TUintegTrapI FunCM -2.0 5.0 1.0e-5 30 5 1]
puts stderr "Convergence 1.0e-5: Returned [format "%.5f" $V]; Actual 27.70886"
set V [TUintegTrapI FunCM -2.0 5.0 1.0e-6 30 5 1]
puts stderr "Convergence 1.0e-6: Returned [format "%.5f" $V]; Actual 27.70886"


# INTEGRATE the function using DoOnce set to 0.

set V [TUintegTrapI FunCO -2.0 5.0 1.0e-5 30 5 0]
puts stderr ""
puts stderr "Convergence 1.0e-5: Returned [format "%.5f" $V]; Actual 27.70886"

> Convergence 1.0e-4: Returned 27.71113; Actual 27.70886
> Convergence 1.0e-5: Returned 27.70900; Actual 27.70886
> Convergence 1.0e-6: Returned 27.70887; Actual 27.70886
> 
> Convergence 1.0e-5: Returned 27.70900; Actual 27.70886

      
Sept 28, 2006