TrapN Functions
in genMath.lib
Calculus Functions Function List by Category Alphabetical Function List
int Trap100(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float *I)
// pointer to store integral value
int Trap500(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float
*I) //
pointer to store integral value
int Trap512(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float
*I) //
pointer to store integral value
int Trap1000(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float
*I) //
pointer to store integral value
int Trap1024(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float
*I) //
pointer to store integral value
int Trap2048(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float
*I) //
pointer to store integral value
int Trap4096(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float
*I) //
pointer to store integral value
int Trap5000(
float
*fx, //
pointer to the function data
float a,
// start of integration interval
float b,
// end of integration interval
float
*I) //
pointer to store integral value
These
functions are 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.
These will be faster than the generic function genTrap
due to code optimizations in the explicit
routines.
In addition, larger functions can be integrated by sequential calls if
appropriate
attention is paid to the passing of fx pointer data. For example, a
function of 100
elements can be integrated by two calls to Trap100, since
I = I1 + I2
where I1 = Integral on interval [a,c] and I2
= Integral on interval [c,b]. Such sequential
calling may be faster than a single call to genTrap.
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