psPolynomial.h

Go to the documentation of this file.
00001 /* @file  psPolynomial.h
00002  * @brief Standard Mathematical Functions.
00003  *
00004  * This file will hold the prototypes for procedures which allocate, free,
00005  * and evaluate various polynomials.  Those polynomial structures are also
00006  * defined here.
00007  *
00008  * @author GLG, MHPCC
00009  *
00010  * @version $Revision: 1.67 $ $Name:  $
00011  * @date $Date: 2007/01/23 22:47:23 $
00012  *
00013  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00014  */
00015 
00016 #ifndef PS_POLYNOMIAL_H
00017 #define PS_POLYNOMIAL_H
00018 
00019 /// @addtogroup MathOps Mathematical Operations
00020 /// @{
00021 
00022 #include <stdio.h>
00023 #include <stdbool.h>
00024 #include <float.h>
00025 #include <math.h>
00026 
00027 #include "psVector.h"
00028 #include "psScalar.h"
00029 
00030 /** Evaluate a non-normalized Gaussian with the given mean and sigma at the
00031  *  given coordianate.
00032  *
00033  *  Note that this is not a Gaussian deviate.  The evaluated Gaussian is:
00034  *        \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
00035  *
00036  *  @return float      value on the gaussian curve given the input parameters
00037  */
00038 float psGaussian(
00039     float x,                           ///< Value at which to evaluate
00040     float mean,                        ///< Mean for the Gaussian
00041     float sigma,                       ///< Standard deviation for the Gaussian
00042     bool normal                        ///< Indicates whether result should be normalized
00043 );
00044 
00045 /** Polynomial Type.
00046  *
00047  *  Enumeration for Polynomial types.
00048  */
00049 typedef enum {
00050     PS_POLYNOMIAL_ORD,                  ///< Ordinary Polynomial
00051     PS_POLYNOMIAL_CHEB                  ///< Chebyshev Polynomial
00052 }
00053 psPolynomialType;
00054 
00055 /** One-dimensional polynomial */
00056 typedef struct
00057 {
00058     psPolynomialType type;              ///< Polynomial type
00059     unsigned int nX;                    ///< Polynomial order
00060     psF64 *coeff;                       ///< Coefficients
00061     psF64 *coeffErr;                    ///< Error in coefficients
00062     psMaskType *mask;                   ///< Coefficient mask
00063 }
00064 psPolynomial1D;
00065 
00066 /** Two-dimensional polynomial */
00067 typedef struct
00068 {
00069     psPolynomialType type;              ///< Polynomial type
00070     unsigned int nX;            ///< Polynomial order in x
00071     unsigned int nY;            ///< Polynomial order in y
00072     psF64 **coeff;                      ///< Coefficients
00073     psF64 **coeffErr;                   ///< Error in coefficients
00074     psMaskType **mask;                  ///< Coefficients mask
00075 }
00076 psPolynomial2D;
00077 
00078 /** Three-dimensional polynomial */
00079 typedef struct
00080 {
00081     psPolynomialType type;              ///< Polynomial type
00082     unsigned int nX;            ///< Polynomial order in x
00083     unsigned int nY;            ///< Polynomial order in y
00084     unsigned int nZ;            ///< Polynomial order in z
00085     psF64 ***coeff;                     ///< Coefficients
00086     psF64 ***coeffErr;                  ///< Error in coefficients
00087     psMaskType ***mask;                 ///< Coefficients mask
00088 }
00089 psPolynomial3D;
00090 
00091 /** Four-dimensional polynomial */
00092 typedef struct
00093 {
00094     psPolynomialType type;              ///< Polynomial type
00095     unsigned int nX;            ///< Polynomial order in x
00096     unsigned int nY;            ///< Polynomial order in y
00097     unsigned int nZ;            ///< Polynomial order in z
00098     unsigned int nT;            ///< Polynomial order in t
00099     psF64 ****coeff;                    ///< Coefficients
00100     psF64 ****coeffErr;                 ///< Error in coefficients
00101     psMaskType ****mask;                ///< Coefficients mask
00102 }
00103 psPolynomial4D;
00104 
00105 
00106 /** Allocates a psPolynomial1D structure with n terms
00107  *
00108  *  @return  psPolynomial1D*    new 1-D polynomial struct
00109  */
00110 psPolynomial1D* psPolynomial1DAlloc(
00111     psPolynomialType type,             ///< Polynomial Type
00112     unsigned int nX                    ///< Number of terms
00113 );
00114 
00115 /** Allocates a 2-D polynomial structure
00116  *
00117  *  @return  psPolynomial2D*    new 2-D polynomial struct
00118  */
00119 psPolynomial2D* psPolynomial2DAlloc(
00120     psPolynomialType type,             ///< Polynomial Type
00121     unsigned int nX,                   ///< Number of terms in x
00122     unsigned int nY                    ///< Number of terms in y
00123 );
00124 
00125 /** Allocates a 3-D polynomial structure
00126  *
00127  *  @return  psPolynomial3D*    new 3-D polynomial struct
00128  */
00129 psPolynomial3D* psPolynomial3DAlloc(
00130     psPolynomialType type,             ///< Polynomial Type
00131     unsigned int nX,                   ///< Number of terms in x
00132     unsigned int nY,                   ///< Number of terms in y
00133     unsigned int nZ                    ///< Number of terms in z
00134 );
00135 
00136 /** Allocates a 4-D polynomial structure
00137  *
00138  *  @return  psPolynomial4D*    new 4-D polynomial struct
00139  */
00140 psPolynomial4D* psPolynomial4DAlloc(
00141     psPolynomialType type,             ///< Polynomial Type
00142     unsigned int nX,                   ///< Number of terms in x
00143     unsigned int nY,                   ///< Number of terms in y
00144     unsigned int nZ,                   ///< Number of terms in z
00145     unsigned int nT                    ///< Number of terms in t
00146 );
00147 
00148 bool psPolynomial2DRecycle(psPolynomial2D *poly,
00149                            psPolynomialType type,
00150                            unsigned int nX,
00151                            unsigned int nY);
00152 
00153 psPolynomial2D *psPolynomial2DCopy(psPolynomial2D *out,
00154                                    psPolynomial2D *poly);
00155 
00156 /** Evaluates a 1-D polynomial at specific coordinates.
00157  *
00158  *  @return psF64    result of polynomial at given location
00159  */
00160 psF64 psPolynomial1DEval(
00161     const psPolynomial1D* poly,        ///< Coefficients for the polynomial
00162     psF64 x                            ///< location at which to evaluate
00163 );
00164 
00165 /** Evaluates a 2-D polynomial at specific coordinates.
00166  *
00167  *  @return psF64    result of polynomial at given location
00168  */
00169 psF64 psPolynomial2DEval(
00170     const psPolynomial2D* poly,        ///< Coefficients for the polynomial
00171     psF64 x,                           ///< x location at which to evaluate
00172     psF64 y                            ///< y location at which to evaluate
00173 );
00174 
00175 /** Evaluates a 3-D polynomial at specific coordinates.
00176  *
00177  *  @return psF64    result of polynomial at given location
00178  */
00179 psF64 psPolynomial3DEval(
00180     const psPolynomial3D* poly,        ///< Coefficients for the polynomial
00181     psF64 x,                           ///< x location at which to evaluate
00182     psF64 y,                           ///< y location at which to evaluate
00183     psF64 z                            ///< z location at which to evaluate
00184 );
00185 
00186 /** Evaluates a 4-D polynomial at specific coordinates.
00187  *
00188  *  @return psF64    result of polynomial at given location
00189  */
00190 psF64 psPolynomial4DEval(
00191     const psPolynomial4D* poly,        ///< Coefficients for the polynomial
00192     psF64 x,                           ///< x location at which to evaluate
00193     psF64 y,                           ///< y location at which to evaluate
00194     psF64 z,                           ///< z location at which to evaluate
00195     psF64 t                            ///< t location at which to evaluate
00196 );
00197 
00198 /** Evaluates a 1-D polynomial at specific sets of coordinates
00199  *
00200  *  @return psVector*    results of polynomials at given locations
00201  */
00202 psVector *psPolynomial1DEvalVector(
00203     const psPolynomial1D *poly,        ///< Coefficients for the polynomial
00204     const psVector *x                  ///< x locations at which to evaluate
00205 );
00206 
00207 /** Evaluates a 2-D polynomial at specific sets of coordinates
00208  *
00209  *  @return psVector*    results of polynomial at given locations
00210  */
00211 psVector *psPolynomial2DEvalVector(
00212     const psPolynomial2D *poly,        ///< Coefficients for the polynomial
00213     const psVector *x,                 ///< x locations at which to evaluate
00214     const psVector *y                  ///< y locations at which to evaluate
00215 );
00216 
00217 /** Evaluates a 3-D polynomial at specific sets of coordinates
00218  *
00219  *  @return psVector*    results of polynomial at given locations
00220  */
00221 psVector *psPolynomial3DEvalVector(
00222     const psPolynomial3D *poly,        ///< Coefficients for the polynomial
00223     const psVector *x,                 ///< x locations at which to evaluate
00224     const psVector *y,                 ///< y locations at which to evaluate
00225     const psVector *z                  ///< z locations at which to evaluate
00226 );
00227 
00228 /** Evaluates a 4-D polynomial at specific sets of coordinates
00229  *
00230  *  @return psVector*    results of polynomial at given locations
00231  */
00232 psVector *psPolynomial4DEvalVector(
00233     const psPolynomial4D *poly,        ///< Coefficients for the polynomial
00234     const psVector *x,                 ///< x locations at which to evaluate
00235     const psVector *y,                 ///< y locations at which to evaluate
00236     const psVector *z,                 ///< z locations at which to evaluate
00237     const psVector *t                  ///< t locations at which to evaluate
00238 );
00239 
00240 /** Checks the type of a particular pointer.
00241  *
00242  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00243  *
00244  *  @return bool:       True if the pointer matches a psPolynomial1D structure, false otherwise.
00245  */
00246 bool psMemCheckPolynomial1D(
00247     psPtr ptr                          ///< the pointer whose type to check
00248 );
00249 
00250 /** Checks the type of a particular pointer.
00251  *
00252  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00253  *
00254  *  @return bool:       True if the pointer matches a psPolynomial2D structure, false otherwise.
00255  */
00256 bool psMemCheckPolynomial2D(
00257     psPtr ptr                          ///< the pointer whose type to check
00258 );
00259 
00260 /** Checks the type of a particular pointer.
00261  *
00262  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00263  *
00264  *  @return bool:       True if the pointer matches a psPolynomial3D structure, false otherwise.
00265  */
00266 bool psMemCheckPolynomial3D(
00267     psPtr ptr                          ///< the pointer whose type to check
00268 );
00269 
00270 /** Checks the type of a particular pointer.
00271  *
00272  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00273  *
00274  *  @return bool:       True if the pointer matches a psPolynomial4D structure, false otherwise.
00275  */
00276 bool psMemCheckPolynomial4D(
00277     psPtr ptr                          ///< the pointer whose type to check
00278 );
00279 
00280 
00281 
00282 
00283 /** Creates the specified number of chebyshev polys.
00284  *
00285  *  @return psPolynomial1D** The chebyshev polys.
00286  *
00287  */
00288 psPolynomial1D **p_psCreateChebyshevPolys(
00289     psS32 numPolys
00290 );
00291 
00292 typedef struct
00293 {
00294     int n;                              ///< The number of Chebyshev polys.
00295     psPolynomial1D **chebyPolys;        ///< THe chebyshev polys
00296 
00297 }
00298 p_chebyPolys;
00299 
00300 
00301 /*****************************************************************************
00302     PS_POLY macros:
00303 *****************************************************************************/
00304 #define PS_ASSERT_POLY1D(NAME, RVAL) \
00305 if (false == psMemCheckPolynomial1D(NAME)) { \
00306     psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00307             "Unallowable operation: argument %s is not a psPolynomial1D struct.\n",\
00308             #NAME); \
00309     return(RVAL); \
00310 } \
00311 
00312 #define PS_ASSERT_POLY_NON_NULL(NAME, RVAL) \
00313 if ((NAME) == NULL || (NAME)->coeff == NULL) { \
00314     psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00315             "Unallowable operation: polynomial %s or its coeffs is NULL.", \
00316             #NAME); \
00317     return(RVAL); \
00318 } \
00319 
00320 #define PS_ASSERT_POLY_TYPE(NAME, TYPE, RVAL) \
00321 if ((NAME)->type != TYPE) { \
00322     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00323             "Unallowable operation: polynomial %s has wrong type.", #NAME); \
00324     return(RVAL); \
00325 } \
00326 
00327 #define PS_ASSERT_POLY_VALID_TYPE(TYPE, RVAL) \
00328 if ((TYPE != PS_POLYNOMIAL_ORD) && \
00329         (TYPE != PS_POLYNOMIAL_CHEB)) { \
00330     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00331             "Unallowable operation: invalid type %d for polynomial", TYPE); \
00332     return(RVAL); \
00333 } \
00334 
00335 #define PS_POLY_PRINT_1D(NAME) \
00336 printf("Poly %s: (nX) is (%d)\n", #NAME, NAME->nX);\
00337 for (psS32 i = 0 ; i < NAME->nX+1 ; i++) {\
00338     printf("%s->coeff[%d] is %f\n", #NAME, i, NAME->coeff[i]); \
00339 }\
00340 
00341 #define PS_POLY_PRINT_2D(NAME) \
00342 printf("Poly %s: (nX, nY) is (%d, %d)\n", #NAME, NAME->nX, NAME->nY);\
00343 for (psS32 i = 0 ; i < NAME->nX+1 ; i++) {\
00344     for (psS32 j = 0 ; j < NAME->nY+1 ; j++) {\
00345         printf("%s->coeff[%d][%d] is %f\n", #NAME, i, j, NAME->coeff[i][j]); \
00346     }\
00347 }\
00348 
00349 /// @}
00350 #endif // #ifndef PS_POLYNOMIAL_H

Generated on Fri Feb 2 22:24:35 2007 for pslib by  doxygen 1.5.1