AnalysisSystemForRadionucli.../fitfunc.h
2024-06-04 15:25:02 +08:00

245 lines
7.9 KiB
C++

#ifndef FITFUNC
#define FITFUNC
#include "gamma_alg_global.h"
// 来自 calFcnEval.m
namespace Fcn {
/* interpolate data points
* @syntax s = l1interpolate(x, para)
* @param x independent values at which function shall be evaluated
* @param para vector of data points in form [x1, y1, x2, y2, ...]
* @return y interpolated values */
arma::mat l1interpolate(arma::mat x, arma::colvec para);
/* l2polynomial - polynomial evaluation
*
* @syntax y = l2polynomial(x, para)
* @param x independent values at which function shall be evaluated
* @param para vector of polynomial coefficients a0, a1, ...
* @return y function values at x */
arma::mat l2polynomial(arma::mat x, arma::colvec para);
/* square root polynomial
*
* y = a0 + a1*x^(1/2) + a2*x + ...
*
* @syntax y = l3sqrtpoly(x, para)
* @param x independent values at which function shall be evaluated
* @param para polynomial coefficients [a0, a1, a2,...]
* @return y function values at x */
arma::mat l3sqrtpoly(arma::mat x, arma::colvec para);
/* square root of polynomial
*
* y = sqrt(a0 + a1*x + ... )
*
* @syntax y = l4sqrtofpoly(x, para)
* @param x independent values at which function shall be evaluated
* @param para polynomial coefficients [a0, a1, a2,...]
* @return y function values at x */
arma::mat l4sqrtofpoly(arma::mat x, arma::colvec para);
/* HT efficiency function
*
* y = A*exp(-(E1/x)^k)*(1-exp(-(E2/x)^n))
*
* @syntax y = l5hteff(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter vector [A, E1, E2, k, n]
* @return y function values at x */
arma::mat l5hteff(arma::mat x, arma::colvec para);
/* polynomial in log log scale
*
* log(y) = a0 + a1*log(x) + ...
*
* @syntax y = l6loglogpoly(x, para)
* @param x independent values at which function shall be evaluated
* @param para polynomial coefficients [a0, a1, ...]
* @return y function values at x */
arma::mat l6loglogpoly(arma::mat x, arma::colvec para);
/* polynomial of logarithm versus 1/x
*
* log(y) = a0*x + a1 + a2/x +a3/(x^2) + ...
*
* @syntax y = l7logpoly(x, para)
* @param x independent values at which function shall be evaluated
* @param para polynomial coefficients [a0, a1, a2, ...]
* @return y function values at x */
arma::mat l7logpoly(arma::mat x, arma::colvec para);
/* polynomial of logarithm versus logarithm of inverse
*
* log(y) = a0 + a1*log(c/x) + a2*log(c/x)^2 +...
*
* @syntax y = l8loginvlog(x, para)
* @param x independent values at which function shall be evaluated
* @param para polynomial coefficients and constant [a0, a1, a2, ..., c]
* @return y function values at x */
arma::mat l8loginvlog(arma::mat x, arma::colvec para);
/* inverse exponential
*
* y = 1/(a*x^(-k) + b*x^(-n))
*
* @syntax y = l9invexp(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter vector [a b k n]
* @return y function values at x */
arma::mat l9invexp(arma::mat x, arma::colvec para);
/* fixed shoulder efficiency
*
* @syntax y = l93ht2fix(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter coefficients [S, E1, k, E3, n]
* @return y vector of same size as x, containing constant entries */
arma::mat l93ht2fix(arma::mat x, arma::colvec para);
/* free shoulder efficiency
*
* @syntax y = l94ht2free((x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter coefficients [S, E1, k, b, E2, n]
* @return y vector of same size as x, containing constant entries */
arma::mat l94ht2free(arma::mat x, arma::colvec para);
/* three component efficiency model
*
* y = S * f1 * f2 * f3
* f1 = exp(-(E1/E)^k)
* f2 = 1 - exp(-b*(E-E2)^(-m)) for E > E2; 1 else
* f3 = 1 - exp(-(2*E3/(E-E3))^n) for E > E3; 1 else
*
* @syntax y = l95ht3eff(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter coefficients [S, E1, k, b, E2, m, E3, n]
* @return y vector of same size as x, containing constant entries */
arma::mat l95ht3eff(arma::mat x, arma::colvec para);
/* exponential sum
*
* y = A + E1*x^(-n)
*
* @syntax y = l96invpow(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter coefficients [A, E1, n]
* @return y vector of same size as x, containing constant entries */
arma::mat l96invpow(arma::mat x, arma::colvec para);
/* exponential sum
*
* y = a0 + a1*exp(-lam1*x) + a2*exp(-lam2*x) + ...
*
* @syntax y = l98constant(x, para)
* @param x independent values at which function shall be evaluated
* @param para the constant value
* @return y vector of same size as x, containing constant entries */
arma::mat l97expsum(arma::mat x, arma::colvec para);
/* constant
*
* @syntax y = l98constant(x, para)
* @param x independent values at which function shall be evaluated
* @param para the constant value
* @return y vector of same size as x, containing constant entries */
arma::mat l98constant(arma::mat x, arma::colvec para);
/* linear with cutoff
*
* y = k*(x - E0) if x > ECut
*
* @syntax y = l99cutlin(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter vector [ECut, E0, k]
* @return y function values at x */
arma::mat l99cutlin(arma::mat x, arma::colvec para);
/* extrapolate linear function between two data points
*
* @syntax y = lExtrapolate(xd, yd, x)
* @param xd x data point data (x0, x1)
* @param yd y data point data (y0, y1)
* @param x evaluation points
* @param y values of the linear function through (x0,y0) and (x1,y1) */
arma::mat lExtrapolate(arma::mat xd, arma::colvec yd, arma::mat x);
}
// 来自 calDerivEval.m
namespace Deriv {
/* derivative of interpolate data points
*
* @syntax s = l1interpolate(x, para)
* @param x independent values at which function shall be evaluated
* @param para vector of data points in form [x1, y1, x2, y2, ...]
* @return dy derivative of interpolated values */
arma::mat l1interpolate(arma::mat x, arma::colvec para);
/* derivative of polynomial evaluation
* @syntax dy = l2polynomial(x, para)
* @param x independent values at which function shall be evaluated
* @param para vector of polynomial coefficients a0, a1, ...
* @return dy polynomial slope values at x */
arma::mat l2polynomial(arma::mat x, arma::colvec para);
/* square root polynomial
*
* y = a0 + a1*x^(1/2) + a2*x + ...
*
* @syntax dy = l3sqrtpoly(x, para)
* @param x independent values at which function shall be evaluated
* @param para polynomial coefficients [a0, a1, a2,...]
* @return dy derivative values at x */
arma::mat l3sqrtpoly(arma::mat x, arma::colvec para);
/* derivative of exponential sum
*
* y = A + (x/E1)^(-n)
*
* @syntax dy = l96invpow(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter vector [A, E1, n]
* @return dy derivative values at x */
arma::mat l96invpow(arma::mat x, arma::colvec para);
/* derivative of exponential sum
*
* y = a0 + a1*exp(-l1*x) + ...
*
* @syntax dy = l97expsum(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter vector [a0, a1, l1, a2, l2, ...]
* @return dy derivative values at x */
arma::mat l97expsum(arma::mat x, arma::colvec para);
/* derivative of linear with cutoff
*
* y = k*(x - E0) if x > ECut
*
* dy = k if x > ECut
*
* @syntax dy = l99cutlin(x, para)
* @param x independent values at which function shall be evaluated
* @param para parameter vector [ECut, E0, k]
* @return dy slope at x */
arma::mat l99cutlin(arma::mat x, arma::colvec para);
/* approximated derivative of arbitrary calibration function
*
* @syntax dy = lAproxDeriv(x, p)
* @param x values at which derivative with respect to x shall be returned
* @param p calibration parameter vector (incuding function type)
* @return dy derivative of calibration curve with respect to x */
arma::mat lApproxDeriv(arma::mat x, arma::colvec para);
}
#endif // FITFUNC