Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psPolynomial.h

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

Generated on Mon Jul 3 14:13:44 2006 for Pan-STARRS Foundation Library by  doxygen 1.4.4