genTrap
in genMath.lib

Calculus Functions           Function List by Category            Alphabetical Function List

Sample Code

int genTrap(
                        float *fx,            // pointer to the function data
                        float a,               // start of integration interval
                        float b,               // end of integration interval
                        int n,                  // number of points of fx in interval [a,b]
                        float *I)             // pointer to store integral value;

This function is used to numerically integrate a function of n points from a -> b.  The
integration is done by the Trapezoidal Rule:

I = h * [1/2 fx(0) + fx(1) + fx(2) ... + fx(n-2) + 1/2 fx(n-1)]

where h = (b-a)/n.  h is computed within the function from the passed values for a, b and n.

NOTE:   To optimize the function, the inner summation loop is unrolled by sixteen terms.
                This means n must be greater than 16!  The function will produce unpredictable
                results, and may not generate an error if the fx array has fewer than 16 elements
                with n<16. 

The library contains several functions for 'known size' function integration.  For example,
the function Trap100 will integrate a function with 100 elements using the trapezoidal rule.
These specific functions will be slightly faster due to fewer parameters passed and some
explicit optimizations within the code.

The return code is errno, defined in the C standard library (math.h).  This is an integer value
for math errors.

Sample Application:
//////////// splGS.c for genGaussSeidel Library function //////////
//                                      			 //
// As a sample, the 3-d linear system solved is:                 //
// 								 //
// 6t1 + 1t2 + 1t3 = 10.7					 //
// 1t1 + 9t2 - 2t3 =  3.6					 //
// 2t2 - 1t2 + 8t3 = 12.1					 //
//								 //
// The initial guess for t = (1,1,1) and the convergence 	 //
// tolerance is 0.00001.					 //
//								 //
///////////////////////////////////////////////////////////////////
////////////////////////// INCLUDES ///////////////////////////////
#include "stdio.h" 
#include "genMath.h" 
////////////////////////////// Main //////////////////////////////
void main()
{
} // End Main
///////////////////////// End splGS.c //////////////////////////// 
The exact solution for t is (1.5, 0.5, 1.2).
The reader may compare the exact solution to the following numerical
results.
Ouput from the test program splGS.c: 
System Solved using Gauss Seidel 
t[0] = 1.500001
t[1] = 0.500000
t[2] = 1.200000
Iterations to Converge: 7