Functions

sc_math.h File Reference

Math utility functions. More...

Functions

double golden_section (double RHS(double x, void *context), double a, double b, double tol, int maxIts, void *context)
 Golden section minimization.
ml_matrix rk0 (ml_matrix RHS(ml_matrix x, double t, void *context), ml_matrix &x, double h, double t, void *context)
 0th order Runge-Kutta integration algorithm with time as a RHS input
ml_matrix rk4 (ml_matrix RHS(ml_matrix x, double t), ml_matrix &x, double h, double t)
 4th order Runge-Kutta integration algorithm with time as a RHS input
ml_matrix rk4 (ml_matrix RHS(ml_matrix x, double t, void *context), ml_matrix &x, double h, double t, void *context)
 4th order Runge-Kutta integration algorithm with time as a RHS input and a context pointer
ml_matrix rk4 (ml_matrix RHS(ml_matrix &x, ml_matrix &a), ml_matrix &x, double h, ml_matrix a)
 4th order Runge-Kutta integration algorithm with a matrix input to the RHS
double pss_rem (double x, double y)
 Remainder function.
double fix (double x)
 Round to 0.
double r2p5 (double x)
 Round to nearest 0.5.
int sct_sign (double x)
 Determine sign of number and return unitary value.
double sct_max (double a, double b)
 Find maximum of two numbers.
double unwrap (double angle)
 Unwrap radian values to (-pi,pi) interval.
ml_matrix intersect_line_ellipsoid (const ml_matrix &p, const ml_matrix &u, const ml_matrix &e)
 Find the intersection between a line and an ellipsoid.
ml_matrix p_gauss (int nMax, int mMax, double theta, ml_matrix &dp)
 Computes the Gaussian form of the Legendre functions and the first derivatives.
void s_c_harm (const ml_matrix &a, int n, ml_matrix &s, ml_matrix &c)
 Generate a series of sine and cosine harmonics.
void c_to_d_zoh (const ml_matrix &a, const ml_matrix &b, double dT, ml_matrix &aD, ml_matrix &bD)
 Compute a discrete-time linear system from a continuous system.
ml_matrix expm (const ml_matrix &a)
 Compute the matrix exponential (of a square matrix only) using a power series expansion.
double WrapPhase (double angle)
 Wrap a phase angle to keep its value between -pi and +pi.
ml_matrix WrapPhase (ml_matrix angle)
 Wrap a vector of phase angles to keep their values between -pi and +pi.
ml_matrix UnwrapPhase (ml_matrix theta)
 Unwrap a vector of angular values so they change continuously instead of wrapping.
ml_matrix diff (ml_matrix a)
 Compute the difference between successive elements of a 1-D vector.
ml_matrix delt_circ (ml_matrix x, ml_matrix y)
 Compute a delta in circular coordinates.
ml_matrix circle_fit (ml_matrix x, ml_matrix y)
 Compute a delta in circular coordinates.
double factorial (double n)
 Compute a factorial.
double interp_2d (ml_matrix a, ml_matrix x, ml_matrix y, double xK, double yK)
 2D interpolation
double newton_raphson (double f(double x, void *context), double df(double x, void *context), double x0, double tol, int nMax, void *context)
 1 dimensional root finder
double secant (double RHS(double x, void *context), double x0, double x00, double tol, int nMax, void *context)
 1 dimensional root finder
ml_matrix average_unit_vector (ml_matrix u1, ml_matrix u2)
 Average unit vector.
ml_matrix pinv (ml_matrix a)
 Pseudo inverse.
ml_matrix downhill_simplex (double RHS(const ml_matrix &x, void *context), ml_matrix &x, ml_matrix &options, void *context)
 Downhill simplex.
ml_matrix orthogonalize (ml_matrix a)
 Orthogonalize.
ml_matrix logistic (ml_matrix x)
 Logistic function.
double logistic (double x)
 Logistic function.
double interp_extrap_1d (ml_matrix a, ml_matrix x, double xK)
 1D interpolation and extrapolation
double gaussian_multivariate_density (ml_matrix y, ml_matrix y_bar, ml_matrix P)
 Gaussian Mulivariate Normal Distribution function.
ml_matrix roots_second_order (double a, double b, double c)
 Roots second order.
ml_matrix roots_second_order (const ml_matrix &p)
 Roots second order.
double trig_reduction (double a, double b, double c)
 Solve for beta: a*sin(beta)+b*cos(beta) = c.

Detailed Description


Function Documentation

double golden_section ( double   RHSdouble x, void *context,
double  a,
double  b,
double  tol,
int  maxIts,
void *  context 
)
Parameters:
RHSRight-hand side function definition
aLeft range
bRight range
tolTolerance
maxItsMaximum number of interations
*contextto data from RSH
Returns:
minimum value of x
ml_matrix rk0 ( ml_matrix   RHSml_matrix x, double t, void *context,
ml_matrix &  x,
double  h,
double  t,
void *  context 
)

0th order Runge-Kutta integration algorithm with time as a RHS input

RHS actually does the propagation

Parameters:
RHSRight-hand side function definition
xCurrent state
hIntegration time step
tCurrent time
*contextPointer to data to be passed to RHS
Returns:
Derivative of x
ml_matrix rk4 ( ml_matrix   RHSml_matrix x, double t,
ml_matrix &  x,
double  h,
double  t 
)

4th order Runge-Kutta integration algorithm with time as a RHS input

Parameters:
RHSRight-hand side function definition
xCurrent state
hIntegration time step
tCurrent time
Returns:
Derivative of x
double pss_rem ( double  x,
double  y 
)

Remainder function.

Parameters:
xNumerator
yDenominator
Returns:
Remainder from the division of y into x
double fix ( double  x )

Round to 0.

Parameters:
xNumber to be rounded
Returns:
Number rounded to 0
double r2p5 ( double  x )

Round to nearest 0.5.

Parameters:
xNumber to be rounded
Returns:
Number rounded to the nearest "point 5"
int sct_sign ( double  x )

Determine sign of number and return unitary value.

Parameters:
xNumber
Returns:
Unitary value, i.e. 1 or -1
double sct_max ( double  a,
double  b 
)

Find maximum of two numbers.

Parameters:
aFirst number
bSecond number
Returns:
Maximum of a and b
double unwrap ( double  angle )

Unwrap radian values to (-pi,pi) interval.

Parameters:
angleAngle in radians
Returns:
Unwrapped angle

References PI, and TWO_PI.

ml_matrix intersect_line_ellipsoid ( const ml_matrix &  p,
const ml_matrix &  u,
const ml_matrix &  e 
)

Always returns the closest point. The line is defined by a point and unit vectors.

Parameters:
p(3,1) Point
u(3,1) Unit vector
e(3,1) (a,b,c) semi-axes of ellipsoid
Returns:
Intersection point
ml_matrix p_gauss ( int  nMax,
int  mMax,
double  theta,
ml_matrix &  dp 
)

Computes the Gaussian form of the Legendre functions and the first derivatives.

Because there is no zero indexing in MATLAB, the P's are offset in the p matrix as follows:

n,m p(n+1,m+1) = P

MATLAB Form: [p, dP] = PGauss( nMax, mMax, theta )

------------------------------------------------------------------------ References: Wertz, J., Spacecraft Attitude Determination and Control, Kluwer, 1976, pp. 781.

Parameters:
nMaxmax value of first index
mMaxmax value of second index
thetainput value (usually an angle in rads)
dpMatrix for derivative outputs dp(n,m) / d(theta)
Returns:
p Gauss functions, P(n,m)
void s_c_harm ( const ml_matrix &  a,
int  n,
ml_matrix &  s,
ml_matrix &  c 
)

Generate a series of sine and cosine harmonics.

Parameters:
aColumn vector (m,1) argument, in radians
nNumber of harmonics
sVector of sine harmonics output
cVector of cosine harmonics output
void c_to_d_zoh ( const ml_matrix &  a,
const ml_matrix &  b,
double  dT,
ml_matrix &  f,
ml_matrix &  g 
)

Compute a discrete-time linear system from a continuous system.

Parameters:
aContinuous matrix
bContinuous matrix
dTTime step (sec)
fDiscrete matrix
gDiscrete matrix
ml_matrix expm ( const ml_matrix &  a )
Parameters:
aSquare matrix
Returns:
b Matrix exponential, b = exp(a)
double WrapPhase ( double  angle )

*sctlib

Parameters:
anglePhase angle [rad]
Returns:
Phase angle wrapped between -PI and PI [rad]

References PI, and TWO_PI.

ml_matrix WrapPhase ( ml_matrix  angle )

*sctlib

Parameters:
angleVector of phase angles with no limits. [rad]
Returns:
wrapped Vector of phase angles wrapped between -PI and +PI. [rad]

References PI, and TWO_PI.

ml_matrix UnwrapPhase ( ml_matrix  angle )

*sctlib

Parameters:
angleVector of angular values. [rad]
Returns:
unwrapped New vector with jumps larger than 2*PI in magnitude removed so that it changes "continuously". [rad]

References PI, and TWO_PI.

ml_matrix diff ( ml_matrix  a )

Compute the difference between successive elements of a 1-D vector.

Parameters:
a1-dimensional matrix, length N
Returns:
b 1-dimensional matrix, ith element is a(i+1)-a(i), length N-1
ml_matrix delt_circ ( ml_matrix  x,
ml_matrix  y 
)

Compute a delta in circular coordinates.

It does not check dimensions.

Parameters:
x2-dimensional matrix
y2-dimensional matrix
Returns:
z 2-dimensional matrix

References PI.

ml_matrix circle_fit ( ml_matrix  x,
ml_matrix  y 
)

Compute a delta in circular coordinates.

Parameters:
xcolumn matrix
ycolumn matrix
Returns:
s column matrix [a;b;r]
ml_matrix pinv ( ml_matrix  a )

Pseudo inverse.

Parameters:
amatrix
Returns:
orthogonal matrix
ml_matrix orthogonalize ( ml_matrix  a )

Orthogonalize.

Orthogonalize a 3x3 matrix

Parameters:
amatrix
Returns:
orthogonal matrix
ml_matrix logistic ( ml_matrix  x )
Parameters:
xinput
Returns:
1/(1+exp(-x))
double logistic ( double  x )
Parameters:
xinput
Returns:
1/(1+exp(-x))
double interp_extrap_1d ( ml_matrix  a,
ml_matrix  x,
double  xK 
)

1D interpolation and extrapolation

Parameters:
aarray of values
xcorresponding x value
xKvalue of interest
Returns:
value
double gaussian_multivariate_density ( ml_matrix  y,
ml_matrix  y_bar,
ml_matrix  P 
)

Gaussian Mulivariate Normal Distribution function.

Parameters:
yarray of parameters
y_barcorresponding means
Pcovariance matrix
Returns:
likelihood
ml_matrix roots_second_order ( double  a,
double  b,
double  c 
)

Roots second order.

Parameters:
aCoefficient
bCoefficient
cCoefficient
Returns:
roots
ml_matrix roots_second_order ( const ml_matrix &  p )

Roots second order.

Parameters:
parray of coefficients
Returns:
roots
double trig_reduction ( double  a,
double  b,
double  c 
)
Parameters:
aCoefficient
bCoefficient
cRHS
Returns:
roots