00001 /** @file psFunctions.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 Someone at IfA 00012 * @author GLG, MHPCC 00013 * 00014 * @version $Revision: 1.1.1.1 $ $Name: $ 00015 * @date $Date: 2005/06/15 21:08:12 $ 00016 * 00017 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00018 */ 00019 00020 #ifndef PS_FUNCTIONS_H 00021 #define PS_FUNCTIONS_H 00022 00023 #include <stdio.h> 00024 #include <stdbool.h> 00025 #include <float.h> 00026 #include <math.h> 00027 00028 #include "psVector.h" 00029 #include "psScalar.h" 00030 00031 /** \addtogroup Stats 00032 * \{ 00033 */ 00034 00035 /** Evaluate a non-normalized Gaussian with the given mean and sigma at the 00036 * given coordianate. 00037 * 00038 * Note that this is not a Gaussian deviate. The evaluated Gaussian is: 00039 * \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f] 00040 * 00041 * @return psF32 value on the gaussian curve given the input parameters 00042 */ 00043 psF32 psGaussian( 00044 psF32 x, ///< Value at which to evaluate 00045 psF32 mean, ///< Mean for the Gaussian 00046 psF32 stddev, ///< Standard deviation for the Gaussian 00047 psBool normal ///< Indicates whether result should be normalized 00048 ); 00049 00050 /** Produce a vector of random numbers from a Gaussian distribution with 00051 * the specified mean and sigma 00052 * 00053 * @return psVector* vector of random numbers 00054 * 00055 */ 00056 psVector* p_psGaussianDev( 00057 psF32 mean, ///< The mean of the Gaussian 00058 psF32 sigma, ///< The sigma of the Gaussian 00059 psS32 Npts ///< The size of the vector 00060 ); 00061 00062 /** Polynomial Type. 00063 * 00064 * Enumeration for Polynomial types. 00065 */ 00066 typedef enum { 00067 PS_POLYNOMIAL_ORD, ///< Ordinary Polynomial 00068 PS_POLYNOMIAL_CHEB ///< Chebyshev Polynomial 00069 } psPolynomialType; 00070 00071 /** One-dimensional polynomial */ 00072 typedef struct 00073 { 00074 psPolynomialType type; ///< Polynomial type 00075 psS32 n; ///< Number of terms 00076 psF32 *coeff; ///< Coefficients 00077 psF32 *coeffErr; ///< Error in coefficients 00078 psU8 *mask; ///< Coefficient mask 00079 } 00080 psPolynomial1D; 00081 00082 /** Two-dimensional polynomial */ 00083 typedef struct 00084 { 00085 psPolynomialType type; ///< Polynomial type 00086 psS32 nX; ///< Number of terms in x 00087 psS32 nY; ///< Number of terms in y 00088 psF32 **coeff; ///< Coefficients 00089 psF32 **coeffErr; ///< Error in coefficients 00090 psU8 **mask; ///< Coefficients mask 00091 } 00092 psPolynomial2D; 00093 00094 /** Three-dimensional polynomial */ 00095 typedef struct 00096 { 00097 psPolynomialType type; ///< Polynomial type 00098 psS32 nX; ///< Number of terms in x 00099 psS32 nY; ///< Number of terms in y 00100 psS32 nZ; ///< Number of terms in z 00101 psF32 ***coeff; ///< Coefficients 00102 psF32 ***coeffErr; ///< Error in coefficients 00103 psU8 ***mask; ///< Coefficients mask 00104 } 00105 psPolynomial3D; 00106 00107 /** Four-dimensional polynomial */ 00108 typedef struct 00109 { 00110 psPolynomialType type; ///< Polynomial type 00111 psS32 nW; ///< Number of terms in w 00112 psS32 nX; ///< Number of terms in x 00113 psS32 nY; ///< Number of terms in y 00114 psS32 nZ; ///< Number of terms in z 00115 psF32 ****coeff; ///< Coefficients 00116 psF32 ****coeffErr; ///< Error in coefficients 00117 psU8 ****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 psS32 n, ///< Number of terms 00128 psPolynomialType type ///< Polynomial Type 00129 ); 00130 00131 /** Allocates a 2-D polynomial structure 00132 * 00133 * @return psPolynomial2D* new 2-D polynomial struct 00134 */ 00135 psPolynomial2D* psPolynomial2DAlloc( 00136 psS32 nX, ///< Number of terms in x 00137 psS32 nY, ///< Number of terms in y 00138 psPolynomialType type ///< Polynomial Type 00139 ); 00140 00141 /** Allocates a 3-D polynomial structure 00142 * 00143 * @return psPolynomial3D* new 3-D polynomial struct 00144 */ 00145 psPolynomial3D* psPolynomial3DAlloc( 00146 psS32 nX, ///< Number of terms in x 00147 psS32 nY, ///< Number of terms in y 00148 psS32 nZ, ///< Number of terms in z 00149 psPolynomialType type ///< Polynomial Type 00150 ); 00151 00152 /** Allocates a 4-D polynomial structure 00153 * 00154 * @return psPolynomial4D* new 4-D polynomial struct 00155 */ 00156 psPolynomial4D* psPolynomial4DAlloc( 00157 psS32 nW, ///< Number of terms in w 00158 psS32 nX, ///< Number of terms in x 00159 psS32 nY, ///< Number of terms in y 00160 psS32 nZ, ///< Number of terms in z 00161 psPolynomialType type ///< Polynomial Type 00162 ); 00163 00164 /** Evaluates a 1-D polynomial at specific coordinates. 00165 * 00166 * @return psF32 result of polynomial at given location 00167 */ 00168 psF32 psPolynomial1DEval( 00169 const psPolynomial1D* myPoly, ///< Coefficients for the polynomial 00170 psF32 x ///< location at which to evaluate 00171 ); 00172 00173 /** Evaluates a 2-D polynomial at specific coordinates. 00174 * 00175 * @return psF32 result of polynomial at given location 00176 */ 00177 psF32 psPolynomial2DEval( 00178 const psPolynomial2D* myPoly, ///< Coefficients for the polynomial 00179 psF32 x, ///< x location at which to evaluate 00180 psF32 y ///< y location at which to evaluate 00181 ); 00182 00183 /** Evaluates a 3-D polynomial at specific coordinates. 00184 * 00185 * @return psF32 result of polynomial at given location 00186 */ 00187 psF32 psPolynomial3DEval( 00188 const psPolynomial3D* myPoly, ///< Coefficients for the polynomial 00189 psF32 x, ///< x location at which to evaluate 00190 psF32 y, ///< y location at which to evaluate 00191 psF32 z ///< z location at which to evaluate 00192 ); 00193 00194 /** Evaluates a 4-D polynomial at specific coordinates. 00195 * 00196 * @return psF32 result of polynomial at given location 00197 */ 00198 psF32 psPolynomial4DEval( 00199 const psPolynomial4D* myPoly, ///< Coefficients for the polynomial 00200 psF32 w, ///< w location at which to evaluate 00201 psF32 x, ///< x location at which to evaluate 00202 psF32 y, ///< y location at which to evaluate 00203 psF32 z ///< z 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 *myPoly, ///< 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 *myPoly, ///< 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 *myPoly, ///< 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 *myPoly, ///< Coefficients for the polynomial 00242 const psVector *w, ///< w locations at which to evaluate 00243 const psVector *x, ///< x locations at which to evaluate 00244 const psVector *y, ///< y locations at which to evaluate 00245 const psVector *z ///< z locations at which to evaluate 00246 ); 00247 00248 /*****************************************************************************/ 00249 00250 /* Double-precision polynomials, mainly for use in astrometry */ 00251 00252 /** Double-precision one-dimensional polynomial */ 00253 typedef struct 00254 { 00255 psPolynomialType type; ///< Polynomial type 00256 psS32 n; ///< Number of terms 00257 psF64 *coeff; ///< Coefficients 00258 psF64 *coeffErr; ///< Error in coefficients 00259 psU8 *mask; ///< Coefficient mask 00260 } 00261 psDPolynomial1D; 00262 00263 /** Double-precision two-dimensional polynomial */ 00264 typedef struct 00265 { 00266 psPolynomialType type; ///< Polynomial type 00267 psS32 nX; ///< Number of terms in x 00268 psS32 nY; ///< Number of terms in y 00269 psF64 **coeff; ///< Coefficients 00270 psF64 **coeffErr; ///< Error in coefficients 00271 psU8 **mask; ///< Coefficients mask 00272 } 00273 psDPolynomial2D; 00274 00275 /** Double-precision three-dimensional polynomial */ 00276 typedef struct 00277 { 00278 psPolynomialType type; ///< Polynomial type 00279 psS32 nX; ///< Number of terms in x 00280 psS32 nY; ///< Number of terms in y 00281 psS32 nZ; ///< Number of terms in z 00282 psF64 ***coeff; ///< Coefficients 00283 psF64 ***coeffErr; ///< Error in coefficients 00284 psU8 ***mask; ///< Coefficient mask 00285 } 00286 psDPolynomial3D; 00287 00288 /** Double-precision four-dimensional polynomial */ 00289 typedef struct 00290 { 00291 psPolynomialType type; ///< Polynomial type 00292 psS32 nW; ///< Number of terms in w 00293 psS32 nX; ///< Number of terms in x 00294 psS32 nY; ///< Number of terms in y 00295 psS32 nZ; ///< Number of terms in z 00296 psF64 ****coeff; ///< Coefficients 00297 psF64 ****coeffErr; ///< Error in coefficients 00298 psU8 ****mask; ///< Coefficients mask 00299 } 00300 psDPolynomial4D; 00301 00302 /** Allocates a double-precision 1-D polynomial structure with n terms 00303 * 00304 * @return psPolynomial1D* new double-precision 1-D polynomial struct 00305 */ 00306 psDPolynomial1D* psDPolynomial1DAlloc( 00307 psS32 n, ///< Number of terms 00308 psPolynomialType type ///< Polynomial Type 00309 ); 00310 00311 /** Allocates a double-precision 2-D polynomial structure 00312 * 00313 * @return psPolynomial2D* new double-precision 2-D polynomial struct 00314 */ 00315 psDPolynomial2D* psDPolynomial2DAlloc( 00316 psS32 nX, ///< Number of terms in x 00317 psS32 nY, ///< Number of terms in y 00318 psPolynomialType type ///< Polynomial Type 00319 ); 00320 00321 /** Allocates a double-precision 3-D polynomial structure 00322 * 00323 * @return psPolynomial3D* new double-precision 3-D polynomial struct 00324 */ 00325 psDPolynomial3D* psDPolynomial3DAlloc( 00326 psS32 nX, ///< Number of terms in x 00327 psS32 nY, ///< Number of terms in y 00328 psS32 nZ, ///< Number of terms in z 00329 psPolynomialType type ///< Polynomial Type 00330 ); 00331 00332 /** Allocates a double-precision 4-D polynomial structure 00333 * 00334 * @return psPolynomial4D* new double-precision 4-D polynomial struct 00335 */ 00336 psDPolynomial4D* psDPolynomial4DAlloc( 00337 psS32 nW, ///< Number of terms in w 00338 psS32 nX, ///< Number of terms in x 00339 psS32 nY, ///< Number of terms in y 00340 psS32 nZ, ///< Number of terms in z 00341 psPolynomialType type ///< Polynomial Type 00342 ); 00343 00344 /** Evaluates a double-precision 1-D polynomial at specific coordinates. 00345 * 00346 * @return psF32 result of polynomial at given location 00347 */ 00348 psF64 psDPolynomial1DEval( 00349 const psDPolynomial1D* myPoly, ///< Coefficients for the polynomial 00350 psF64 x ///< Value at which to evaluate 00351 ); 00352 00353 /** Evaluates a double-precision 2-D polynomial at specific coordinates. 00354 * 00355 * @return psF32 result of polynomial at given location 00356 */ 00357 psF64 psDPolynomial2DEval( 00358 const psDPolynomial2D* myPoly, ///< Coefficients for the polynomial 00359 psF64 x, ///< Value x at which to evaluate 00360 psF64 y ///< Value y at which to evaluate 00361 ); 00362 00363 /** Evaluates a double-precision 3-D polynomial at specific coordinates. 00364 * 00365 * @return psF32 result of polynomial at given location 00366 */ 00367 psF64 psDPolynomial3DEval( 00368 const psDPolynomial3D* myPoly, ///< Coefficients for the polynomial 00369 psF64 x, ///< Value x at which to evaluate 00370 psF64 y, ///< Value y at which to evaluate 00371 psF64 z ///< Value z at which to evaluate 00372 ); 00373 00374 /** Evaluates a double-precision 4-D polynomial at specific coordinates. 00375 * 00376 * @return psF32 result of polynomial at given location 00377 */ 00378 psF64 psDPolynomial4DEval( 00379 const psDPolynomial4D* myPoly, ///< Coefficients for the polynomial 00380 psF64 w, ///< Value w at which to evaluate 00381 psF64 x, ///< Value x at which to evaluate 00382 psF64 y, ///< Value y at which to evaluate 00383 psF64 z ///< Value z at which to evaluate 00384 ); 00385 00386 /** Evaluates a double-precision 1-D polynomial at specific sets of coordinates. 00387 * 00388 * @return psVector* results of polynomial at given locations 00389 */ 00390 psVector *psDPolynomial1DEvalVector( 00391 const psDPolynomial1D *myPoly, ///< Coefficients for the polynomial 00392 const psVector *x ///< x locations at which to evaluate 00393 ); 00394 00395 /** Evaluates a double-precision 2-D polynomial at specific sets of coordinates. 00396 * 00397 * @return psVector* results of polynomial at given locations 00398 */ 00399 psVector *psDPolynomial2DEvalVector( 00400 const psDPolynomial2D *myPoly, ///< Coefficients for the polynomial 00401 const psVector *x, ///< x locations at which to evaluate 00402 const psVector *y ///< y locations at which to evaluate 00403 ); 00404 00405 /** Evaluates a double-precision 3-D polynomial at specific sets of coordinates. 00406 * 00407 * @return psVector* results of polynomial at given locations 00408 */ 00409 psVector *psDPolynomial3DEvalVector( 00410 const psDPolynomial3D *myPoly, ///< Coefficients for the polynomial 00411 const psVector *x, ///< x locations at which to evaluate 00412 const psVector *y, ///< y locations at which to evaluate 00413 const psVector *z ///< z locations at which to evaluate 00414 ); 00415 00416 /** Evaluates a double-precision 4-D polynomial at specific sets of coordinates. 00417 * 00418 * @return psVector* results of polynomial at given locations 00419 */ 00420 psVector *psDPolynomial4DEvalVector( 00421 const psDPolynomial4D *myPoly, ///< Coefficients for the polynomial 00422 const psVector *w, ///< w locations at which to evaluate 00423 const psVector *x, ///< x locations at which to evaluate 00424 const psVector *y, ///< y locations at which to evaluate 00425 const psVector *z ///< z locations at which to evaluate 00426 ); 00427 00428 /** One-Dimensional Spline */ 00429 typedef struct 00430 { 00431 psS32 n; ///< The number of spline polynomials 00432 psPolynomial1D **spline; ///< An array of n pointers to the spline polynomials 00433 psF32 *p_psDeriv2; ///< For cubic splines, the second derivative at each domain point. Size is n+1. 00434 psF32 *domains; ///< The boundaries between each spline piece. Size is n+1. 00435 psVector *knots; ///< The boundaries between each spline piece. Size is n+1. 00436 } 00437 psSpline1D; 00438 00439 /** Allocates a psSpline1D structure 00440 * 00441 * Allocator for psSpline1D where the bounds are implicitly specified through specifying 00442 * min and max values along with the number of splines. 00443 * 00444 * @return psSpline1D* new 1-D spline struct 00445 */ 00446 psSpline1D *psSpline1DAlloc(psS32 n, ///< Number of spline polynomials 00447 psS32 order, ///< Order of spline polynomials 00448 psF32 min, ///< Lower boundary value of spline polynomials 00449 psF32 max); ///< Upper boundary value of spline polynomials 00450 00451 /** Allocates a psSpline1D structure 00452 * 00453 * Allocator for psSpline1D where the bounds are explicitly specified. 00454 * 00455 * @return psSpline1D* new 1-D spline struct 00456 */ 00457 psSpline1D *psSpline1DAllocGeneric(const psVector *bounds, ///< Bounds for spline polynomials 00458 psS32 order); ///< Order of spline polynomials 00459 00460 /** Evaluates 1-D spline polynomials at a specific coordinate. 00461 * 00462 * @return psF32 result of spline polynomials evaluated at given location 00463 */ 00464 psF32 psSpline1DEval( 00465 const psSpline1D *spline, ///< Coefficients for spline polynomials 00466 psF32 x ///< location at which to evaluate 00467 ); 00468 00469 /** Evaluates 1-D spline polynomials at a set of specific coordinates. 00470 * 00471 * @return psVector* results of spline polynomials evaluated at given locations 00472 */ 00473 psVector *psSpline1DEvalVector( 00474 const psSpline1D *spline, ///< Coefficients of spline polynomials 00475 const psVector *x ///< locations at which to evaluate 00476 ); 00477 00478 /** Performs a binary disection on a given vector. 00479 * Searches through an array of data for a specified value. 00480 * 00481 * @return psS32 corresponding index number of specified value 00482 */ 00483 psS32 p_psVectorBinDisect(psVector *bins, ///< Array of non-decreasing values 00484 psScalar *x); ///< Target value to find 00485 00486 /** Interpolates a series of data points for evaluation at a specific coordinate. Uses a 00487 * Lagrange interpolation method. 00488 * 00489 * @return psScalar* Lagrange interpolation value at given location 00490 */ 00491 psScalar *p_psVectorInterpolate(psVector *domain, ///< Domain (x coords) for interpolation 00492 psVector *range, ///< Range (y coords) for interpolation 00493 psS32 order, ///< Order of interpolation function 00494 psScalar *x); ///< Location at which to evaluate 00495 00496 #if 0 00497 psF32 p_psNRSpline1DEval(psSpline1D *spline, 00498 const psVector* x, 00499 const psVector* y, 00500 psF32 X); 00501 #endif // #if 0 00502 00503 /** \} */ // End of MathGroup Functions 00504 00505 #endif // #ifndef PS_FUNCTIONS_H 00506
1.4.1