PSS Math Module
MATLAB toolboxes for aerospace analysis
Math Functions

The math module functions. View the published Math Demos. More...

Directories

directory AStar
 Optimal path planning using A* algorithm.
 
directory Analysis
 Numerical analysis functions.
 
directory Demos
 Math Demos.
 
directory Analysis
 Analysis demos.
 
directory AStar
 AStar demos.
 
directory FDIR
 FDIR demos.
 
directory Probability
 Probability demos.
 
directory FDIR
 Detection filters including a nonlinear spring example.
 
directory Geometry
 Geometric routines.
 
directory Integration
 Custom numerical integration routines.
 
directory Linear
 Linear Algebra.
 
directory MathUtils
 Generic math utilities.
 
directory Probability
 Probability including Markov, Gaussian routines.
 
directory Solvers
 Solvers and root finding.
 
directory Trigonometry
 Trigonometry.
 

Functions

function Armijo (in x, in s, in beta, in sigma, in d, in f, in g)
 Use the Armijo rule to compute a stepsize, alpha: More...
 
function AutoCorr (in x, in n)
 Generates the autocorrelation function for the input sequence. More...
 
function Binomial (in y, in n)
 The binomial expansion of (x + y)^n. More...
 
function CFract (in a, in b, in tol)
 Computes the value of a continued fraction of the form. More...
 
function CHarm (in a, in n)
 Generate a series of cosine harmonics of the arguments. More...
 
function CHarmD (in a, in n)
 Generate a series of cosine harmonics of the arguments. More...
 
function DLyapG (in a, in q)
 Find the solution for the Lyapunov equation apa' - p + q = 0. More...
 
function FitPair (in x, in y, in xF)
 Given xF, find yF that best fits xF given the pair (x,y) More...
 
function FourierSeries (in y, in t, in n)
 Generates the Fourier series coefficients of a signal. More...
 
function Heavisde (in x)
 Heavside function. More...
 
function HypgF1 (in alpha, in gamma, in x, in tol, in nMax)
 Computes the value of the hypergeometric function. More...
 
function HypgFr (in alpha, in beta, in gamma, in x, in tol, in nMax)
 Computes the value of the ratio of hypergeometric functions. More...
 
function HypgMr (in beta, in gamma, in x, in tol, in nMax)
 Computes the value of the confluent hypergeometric ratio. More...
 
function Interp1D (in y1, in y2, in x1, in x2, in x)
 Performs a linear interpolation: More...
 
function InterpolateCircle (in x1, in x2, in f)
 Interpolates between x1 and x2 when x1 and x2 lie in a circle. More...
 
function IntExpR (in a, in x, in xC)
 One dimensional interpolation and extrapolation on the rows of a. More...
 
function IntExp (in a, in x, in xC, in y, in yC)
 One or two dimensional interpolation and extrapolation. More...
 
function Jacobian (in funFcn, in xOP, in tOP, in varargin)
 This function computes the Jacobian matrix for a right hand-side. More...
 
function JacobianODE (in funFcn, in tOP, in xOP, in d)
 This function computes the Jacobian matrix for a right hand-side. More...
 
function JCart2Sp (in c)
 Converts cartesian to spherical coordinates. More...
 
function JSp2Cart (in s)
 Jacobian for converting from spherical to cartesian coordinates. More...
 
function LogBaseN (in n, in x)
 log of base n. More...
 
function Logistic (in x)
 Logistic function. More...
 
function LyapG (in a, in q)
 Solve the general Lyapunov equation ap + pa' + q = 0. More...
 
function MakeDistribution (in x, in f, in N)
 Generate a list of random variables with some specified distribution. More...
 
function NewStats (in oldS, in oldM, in count, in x)
 Calculates the new standard deviation and average. More...
 
function NewtonsMethod (in f, in grad, in hess, in x, in stopData, in stepSizeData)
 Solve an optimization problem with Newton's method. More...
 
function OptimalTrajectory (in x0, in xF, in t, in uMax, in f, in maxIter)
 Optimal trajectory using simplex. More...
 
function Pade (in n, in m, in T)
 Create a Padé approximant of exp(sT) More...
 
function PAL (in nMax, in mMax, in x)
 Generates the Associated Legendre Functions of the first kind. More...
 
function PDAL (in nMax, in mMax, in x, in xD)
 Generates Associated Legendre Functions of the first kind and derivatives. More...
 
function PGauss (in nMax, in mMax, in theta)
 Computes the Gaussian form of the Legendre functions. More...
 
function SCHarm (in a, in n)
 Generate a series of sine and cosine harmonics of the arguments. More...
 
function SCHarmD (in a, in n)
 Generate a series of sine and cosine harmonics of the arguments. More...
 
function SCSeries (in t, in nSin, in nCos, in wo, in y)
 Compute a series a + sum(bn sin(n wo t)) + sum(cn cos(n wo t)) More...
 
function SHarm (in a, in n)
 Generate a series of sine harmonics of the arguments. More...
 
function SHarmD (in a, in n)
 Generate a series of sine harmonics of the arguments. More...
 
function Simplex (in c, in a, in b, in maxValue, in maxIter, in slack, in relax, in nhardcon, in nsofteq)
 Uses the simplex method to minimize the cost when solving the problem. More...
 
function Simplex2 (in a, in c, in x, in s, in g, in gU, in BInv, in maxValue, in maxIter)
 Computes the solution to the simplex problem with an optional maximum constraint. More...
 
function Simplex (in c, in a, in b)
 Uses the simplex method to minimize the cost when solving the problem. More...
 
function SimplexScaling (in a, in b, in nslack)
 Simplex slack variable scaling. More...
 
function SphJacobian (in x)
 Spherical coordinates Jacobian. More...
 
function SubPoly (in a, in b)
 Subtract two polynomials so that c = a - b. More...
 
function WaveletMorlet (in t, in f, in w, in xEnv)
 Performs a wavelet transform using a Morlet Wavelet. More...
 
function WorstFirstAssignment (in mat)
 Reorder columns to minimize the diagonal sum with a worst-first policy. More...
 
function AStarSearch (in startNode, in goalNode, in d)
 Finds the optimal path using A*. More...
 
function DeltaAngleForNewRADec (in v1, in rA1, in dec1, in rA2, in dec2)
 Compute the angle change needed to change a trajectory so that it. More...
 
function GenerateGrid (in n, in r, in stayout, in type)
 Generate a grid on a sphere. More...
 
function GlobeGrid (in n)
 Generate right ascensions and declinations for a global grid. More...
 
function GridPathCost (in startLoc, in goalLoc, in d)
 Finds the cost for going from startNode to nextNode. More...
 
function GridSuccessorNodes (in node, in parent, in d)
 Finds successor nodes in a square grid. More...
 
function GridTraverseCost (in startNode, in nextNode, in d)
 Finds the cost of going from one node to another in a square grid. More...
 
function ManeuverCost (in startNode, in nextNode, in d)
 Finds the cost for going from startNode to nextNode. More...
 
function ManeuverCost3D (in startNode, in nextNode, in d)
 Finds the cost for going from startNode to nextNode in 3D. More...
 
function ManeuverSuccessorNodes (in node, in parent, in d)
 Finds successor nodes. More...
 
function ManeuverSuccessorNodes3D (in node, in parent, in d)
 Finds successor nodes in 3D. More...
 
function SphericalGrid (in n)
 Generate a grid on a sphere that is evenly spaced. More...
 
function TransformGridCoordinates (in p, in q, in n)
 Transforms between 2D and 1D coordinates. More...
 
function BuildLinearDF (in a, in b, in states, in inputs, in lambda, in dT)
 Create a detection filter for a fully measured system. More...
 
function DCMotorDetectionFilter (in y, in v, in dT, in xDF, in alpha, in beta, in tau)
 Implements a DC motor detection filter. More...
 
function DCMotorFailures (in failure, in t, in dT, in c, in d, in tFail, in pFail)
 Triggers a failure at time tFail. More...
 
function DCMotorParitySpace (in y, in v, in dT, in plant, in q)
 Computes the residuals for two DC motors. More...
 
function DetectionFilter (in d, in m, in u, in x, in xS)
 Implement a detection filter for a fully measured system. More...
 
function DetectionFilterBuild (in g, in lambda)
 Algorithm to compute detection filter gains. More...
 
function DetectionFilterBuilder (in action, in modifier)
 GUI to build detection filters. More...
 
function DetectionFilterSimulation (in d, in gP, in u, in failure, in xDF, in xP)
 Simulate a detection filter using a state space model. More...
 
function DetectionFilterUnnormalized (in d, in m, in u, in x)
 Create a unnormalized detection filter for a fully measured system. More...
 
function DualDCMotors (in x, in t, in d)
 Simulates two DC motors. More...
 
function NonlinearEstimator (in yEst, in yMeas, in t, in d)
 Implements an online approximator for a spring mass damper system. More...
 
function NonlinearSpring (in x, in t, in d)
 Right-hand-side of a nonlinear spring dynamics model. More...
 
function NonlinearSpringFault (in x, in t, in d)
 Nonlinear spring fault. More...
 
function NormalizeMatrix (in g, in xRange, in yRange, in uRange)
 Normalizes a state space system for use with a detection filter. More...
 
function OnlineApproximator (in y, in theta, in d)
 Implements an online approximator, f( y, theta ). More...
 
function ProbabilityOfFailure (in lambda, in t)
 Computes the probability of failure. More...
 
function RadialBasisFunction (in y, in c, in sigma)
 Implements a radial basis function for online estimators. More...
 
function TMatrix (in g)
 Compute a transformation matrix from a statespace. More...
 
function AngleSepFromRotation (in axis, in u1, in u2, in phi)
 Compute angular separation between 2 vectors by rotating about an axis. More...
 
function BilinearInterpolation (in x, in y, in z, in xi, in yi)
 Apply bilinear interpolation on 4 data points. More...
 
function FindValidAngleRange (in axis, in u1, in u2, in minSep)
 Find valid range of rotation angles that satisfy separation constraints. More...
 
function FitEllipse (in x, in y, in solnMethod)
 Fit an ellipse. More...
 
function InsideAngleRange (in theta, in range)
 Determine whether an angle is inside an angular range. More...
 
function IntersectLineAndCone (in p, in u, in alpha)
 Compute the intersection of a line and a cone. More...
 
function IntersectLineAndEllipsoid (in p, in u, in e)
 Compute the intersection of a line and ellipsoid. More...
 
function MergeAngleRange (in range1, in range2)
 Merge two angular ranges. More...
 
function Perpendicular (in a)
 Finds perpendicular vectors to a such that Dot(b,a) = 0. More...
 
function PointInGridInTriangle (in v, in n, in m)
 Determine whether points p are in triangle v. More...
 
function PointInPolygon (in p, in v)
 Determine whether points p are in polygon v. More...
 
function PointInTriangle (in v, in p)
 Determine whether points p are in triangle v. More...
 
function SegmentIntersection (in x1, in y1, in x2, in y2, in x3, in y3, in x4, in y4)
 Compute whether and where two 2D line segments intersect. More...
 
function SurfaceAreaEllipsoid (in a, in b, in c)
 Compute the surface area of an ellipsoid. More...
 
function UnitVectorAverage (in u1, in u2)
 Average unit vector. More...
 
function Euler (in Fun, in x, in h, in t, in varargin)
 EULER Euler's method for numerical integration. More...
 
function FracDI (in y, in alpha, in n, in h)
 Fractional order derivative or integral. More...
 
function RK2 (in Fun, in x, in h, in t, in varargin)
 Second order Runge-Kutta. More...
 
function RK4 (in Fun, in x, in h, in t, in varargin)
 Fourth order Runge-Kutta. More...
 
function RK45 (in Fun, in x, in h, in hMax, in hMin, in tol, in t, in varargin)
 Fourth/fifth order Runge-Kutta. More...
 
function RK4TI (in rhs, in x, in h, in a)
 Fourth order Runge-Kutta integration. More...
 
function TwoDSimpsonIntegration (in integrand, in a, in b, in c, in d, in nX, in nY, in varargin)
 Uses 2D Simpson's Rule to integrate an area. More...
 
function BlockDiagonal (in m0, in n)
 Generate a block diagonal matrix. More...
 
function ColCompR (in a, in neps)
 Computes the right column compression of a matrix. More...
 
function ComplexToReal (in c)
 Convert a matrix from complex to real. More...
 
function Cross (in w, in y)
 Vector cross product for multicolum arrays. More...
 
function DelLZ (in v)
 Deletes leading zeros from a vector. More...
 
function Dot (in w, in y)
 Dot product with support for arrays. More...
 
function DUnit (in r, in v)
 Derivative of the unit vector for r. More...
 
function DupVect (in x, in n)
 Duplicate vector n times. More...
 
function Factorl (in n)
 Computes the factorial matrix for a matrix. More...
 
function GenSub (in a, in b)
 Subtract two matrices where NaN - NaN or inf - inf == 0. More...
 
function GJInv (in a)
 Matrix inverse using Gauss-Jordan elimination with partial pivoting. More...
 
function Inv3x3 (in a)
 Inverse of a 3x3 matrix. More...
 
function InvP (in bInvOld, in v, in k)
 The product form of the inverse. More...
 
function IsSing (in a)
 Outputs 0 if the matrix is singular. More...
 
function IsZero (in a)
 Set = 0 if the matrix is all zeros. More...
 
function LeastSq (in e, in y, in x, in w)
 Weighted least squares curve fit. More...
 
function Mag (in u)
 Magnitude of a set of vectors. More...
 
function Orthogonalize (in m)
 Orthogonalize a matrix. More...
 
function Product (in v)
 Computes product of the terms in a vector. More...
 
function RowCompU (in a, in neps)
 Computes the upper row compression of a matrix. More...
 
function Sep (in s, in x)
 Separate a matrix or vector based on the criteria entered in s. More...
 
function Skew (in v)
 Converts a vector into a skew symmetric matrix. More...
 
function SkewSq (in v, in u)
 Computes the product of two skew symmetric matrices derive from vectors. More...
 
function SkewSymm (in v)
 Converts a vector into a skew symmetric matrix. More...
 
function SumC (in x)
 Always sums by column even if x is a single row. More...
 
function SumV (in x)
 Sum a set of vectors in a 3-by-n matrix. More...
 
function SXV (in s, in v)
 Multiplies a scalar times a vector. More...
 
function Unit (in v)
 Unitize vectors by column. More...
 
function DeltaEig (in a, in e)
 Computes the delta eigenvalues for a given a small perturbation of a, e. More...
 
function FindIfInBetween (in x, in a)
 Determines if x is in between odd-even pairs. More...
 
function FloatToTwosComplement (in f, in n, in bigEndian)
 Converts a float to two's complement array. More...
 
function FTrunc (in x, in d)
 Simulates floating point truncation to -ƒ. More...
 
function Odd (in x)
 1 if the value is odd More...
 
function R2P5 (in y)
 Rounds towards zero to the nearest 1/2. More...
 
function Ramp (in t, in t0, in v0, in vF, in vDotMax)
 Generate a ramp signal at t0 from value v0 to vF in time interval t. More...
 
function Ramps (in t, in dT, in varargin)
 Generates ramps for any number of inputs. More...
 
function RoundN (in x, in n)
 Round to n decimal places. More...
 
function TriangleWave (in x)
 Generates a triangle wave. More...
 
function TwosComplementToFloat (in b, in bigEndian)
 Converts a two's complement array to float. More...
 
function BinomialTheorem (in n, in k, in p)
 Computes the binomial theorem. More...
 
function CableTensionExample (in x, in time, in t0)
 Cable tension example. More...
 
function Combinations (in r, in n)
 The number of combinations of r articles in n samples. More...
 
function ConfidenceInterval (in x, in f, in sigma)
 Computes the confidence interval. More...
 
function CovarianceRHS (in t, in p, in d)
 Generates the covariance derivative. More...
 
function CRand (in c)
 Covariance matrix transformation. More...
 
function EMarkov (in r, in tau)
 Find the correlation time and the mean squared value for a Markov sequence. More...
 
function ErrorCombination (in fun, in x, in e, in d)
 Combine errors given a function. More...
 
function GaussianCPDF (in x, in mu, in sigma, in tol)
 Cumulative probability density function for a Gaussian. More...
 
function GaussianPDF (in x, in mu, in sigma)
 Compute the probability density function for a Gaussian distribution. More...
 
function GaussianRSG (in a, in b, in N)
 Gaussian Random Sequence Generator Using the Box-Mueller Transform. More...
 
function Markov (in sigma, in tCorr, in n, in tSamp)
 Generate random output from a Gauss-Markov process. More...
 
function NormalDistribution (in x, in mu, in sigma)
 Matrix normal or Gaussian distribution. More...
 
function Random (in seed, in n, in m)
 Compute a random nxm matrix. More...
 
function RandP (in lambda, in n, in m)
 Generate a Poission random matrix. More...
 
function RandPM (in n, in varargin)
 Generates uniform random matrices between -1 and +1. More...
 
function RandPN (in lambda, in n, in m)
 Generate a Poission random matrix using a normal approximation. More...
 
function RMarkov (in sigma, in tCorr, in tau)
 Generates the autocorrelation function for a Markov Process. More...
 
function SignTest (in x1, in x2)
 Compare the relative accuracy of two signals. More...
 
function SMarkov (in sigma, in tCorr, in w)
 Generates the spectral function for a Markov Process. More...
 
function BisectionZero (in f, in x0, in xLim, in xTol, in nmax)
 Use bisection method to find the zero crossing of a function. More...
 
function LEPDS (in a, in b)
 Solves the problem ax = b when a is positive definite symmetric. More...
 
function LSSVD (in a, in b, in tol)
 Solves ax = b using the singular value decomposition. More...
 
function ModNewt (in f, in fD, in fDD, in x, in epsilon, in nMax, in varargin)
 Finds the solution to f(x) = 0 given derivative information. More...
 
function NewtRaph (in f, in fD, in x, in epsilon, in nMax, in varargin)
 Newton Raphson root finding method. More...
 
function NLEqSolver (in fun, in x, in opt, in d)
 Solves a set of equations for zero using Newton's method. More...
 
function NLEqSolverWrapper (in fun, in x, in opt, in d, in xRange)
 Wraps the Newton's method solver by trying several values. More...
 
function Secant (in f, in x0, in x00, in tol, in nMax, in varargin)
 Finds the solution to f(x) = 0 without derivatives. More...
 
function ACosD (in x)
 Inverse cosine with output in degrees. More...
 
function ACot2 (in x, in y)
 Inverse cotangent. More...
 
function ACot2D (in x, in y)
 Inverse cotangent -180 deg < z < 180 deg. More...
 
function ACotD (in x)
 Inverse cotangent with output in degrees. More...
 
function ACscD (in x)
 Cosecant with output in degrees. More...
 
function ASecD (in x)
 Cosecant. More...
 
function ASinD (in x)
 Inverse sine with output in degrees. More...
 
function ATan2D (in x, in y)
 Inverse tangent -180 < z < 180. More...
 
function ATanD (in x)
 Inverse tangent with output in degrees. More...
 
function CosD (in x)
 Cosine with input in degrees. More...
 
function CosX (in x)
 Computes the value of the cosine function. More...
 
function CotD (in x)
 Cotangent. More...
 
function CscD (in x)
 Cosecant with input in degrees. More...
 
function DeltCirc (in x, in y)
 Find the angle between x and y. More...
 
function LinearSinCosToQuadCos (in a, in b, in c)
 Compute quadratic coefficients on cos(x) from linear eqn. More...
 
function SecD (in x)
 Secant. More...
 
function SinD (in a)
 Sine with input in degrees. More...
 
function SinX (in x)
 Computes the value of the sine function given the argument in degrees. More...
 
function SolveLinearSinCos (in a, in b, in c)
 Algebraically solve x for equation: a*sin(x) + b*cos(x) + c = 0. More...
 
function TanD (in a)
 Tangent with input in degrees. More...
 
function TrigReduction (in a, in b, in c)
 Solve a*sin(beta) + b*cos(beta) = c. More...
 
function UnwrapPhase (in theta)
 Unwrap a vector of angular values to change continuously. More...
 
function VerSin (in x, in xMax)
 Produces a smoothly varying function from 0 to xMax. More...
 
function WrapPhase (in angle)
 Wrap a phase angle (or vector of angles) to keep it between -pi and +pi. More...
 

Detailed Description

The math module functions. View the published Math Demos.

Function Documentation

◆ ACosD()

function ACosD ( in  x)

Inverse cosine with output in degrees.

Since version 1.

Form

z = ACosD( x )


Inputs

x                  Argument (deg)

Outputs

z                  acos(x) (deg)

◆ ACot2()

function ACot2 ( in  x,
in  y 
)

Inverse cotangent.


Form

z = ACot2( x, y )


Inputs

x                  Argument
y                  Argument

Outputs

z                  Cotangent

◆ ACot2D()

function ACot2D ( in  x,
in  y 
)

Inverse cotangent -180 deg < z < 180 deg.

Since version 1.

Form

z = ACot2D( x, y )


Inputs

x                  Argument (deg)
y                  Denominator

Outputs

z                  Cotangent (deg)

◆ ACotD()

function ACotD ( in  x)

Inverse cotangent with output in degrees.

-90 deg <= s <= 90 deg

Since version 1.

Form

z = ACotD( x )


Inputs

x                  Argument (deg)

Outputs

z                  inverse tangent(a)

◆ ACscD()

function ACscD ( in  x)

Cosecant with output in degrees.

Since version 1.

Form

z = ACscD( x )


Inputs

x                  Argument (deg)

Outputs

z                  inverse cosecant(x) (deg)

◆ AngleSepFromRotation()

function AngleSepFromRotation ( in  axis,
in  u1,
in  u2,
in  phi 
)

Compute angular separation between 2 vectors by rotating about an axis.

Type AngleSepFromRotation for a demo.


Form

[sep,minSep,maxSep] = AngleSepFromRotation( axis, u1, u2, phi )


Inputs

axis        (3,1)     Axis of rotation
u1          (3,N)     Vector u1. This vector rotates. 
u2          (3,N)     Vector u2. This vector is fixed.
phi         (1,N)     Rotation angle about axis (rad)

Outputs

sep         (1,N)     Separation angle. Equivalent to:
u1R = QForm( AU2Q(phi,axis) )
sep = acos( Dot(u1R,u2) ) 
minSep      (1,N)     Minimum possible separation for any rotation (rad)
maxSep      (1,N)     Maimum possible separation for any rotation (rad)
phiMin      (1,N)     Rotation angle for minimum separation (rad)
phiMax      (1,N)     Rotation angle for maximum separation (rad)

◆ Armijo()

function Armijo ( in  x,
in  s,
in  beta,
in  sigma,
in  d,
in  f,
in  g 
)

Use the Armijo rule to compute a stepsize, alpha:

alpha = s * beta ^ m        (beta < 1)


where "s" is the initial stepsize (usually 1), and "m" is the first 
nonnegative integer (0,1,2,...) such that:


f(x+alpha*d) - f(x) <= sigma * alpha * g(x)' * d


where f(x) is the cost function, g(x) is the gradient of f(x), x is the 
current state, and d is the current direction of the optimization iteration.


Create a function handle like this:
    f = @(x) x(1)^2 + 3*(x(2)-2)^3

Form

[alpha,xnew,m] = Armijo( x, s, beta, sigma, d, f, g )


Inputs

x          Initial state
s          Maximum stepsize
beta       Reduction factor 
sigma      Scale factor
d          Direction
f          Function handle for cost function
g          Function handle for gradient of cost function

Outputs

alpha      Stepsize
xnew       New state
m          Number of iterations

See also: NewtonsMethod.m


◆ ASecD()

function ASecD ( in  x)

Cosecant.

Since version 1.

Form

z = ASecD( x )


Inputs

x                  Argument (deg)

Outputs

z                  inverse secant(x) (deg)

◆ ASinD()

function ASinD ( in  x)

Inverse sine with output in degrees.

Since version 1.

Form

z = ASinD( x )


Inputs

x                  Argument (deg)

Outputs

z                  asin(x) (deg)

◆ AStarSearch()

function AStarSearch ( in  startNode,
in  goalNode,
in  d 
)

Finds the optimal path using A*.

This function requires that you supply three functions


cost  = PathCostFunction( startNode, goalNode, d.myData )
cost  = TraverseCostFunction( node, newNode, d.myData )
nodes = SuccessorNodes( node, parentNode, d.myData )


Locations are denoted by an index. You use it in your functions
to compute the costs.

Form

path = AStarSearch( startNode, goalNode, d )


Inputs

startNode (1,1) Id of start location
goalNode  (1,1) Id of goal location
d         (1,1) Data structure
.traverseCostFunction     (1,:) Name of traverse cost function
.pathCostEstimateFunction (1,:) Name of path cost function
.successorNodesFunction   (1,:) Name of path cost function
.myData                   (1,1) Data structure with your data
.nodes                    (1,:) List of nodes

Outputs

path      (1,:)  List of nodes in path 

Reference: Stout, W. Bryan, "The Basics of A* for Path Planning," Game Programming Gems, DeLoura, M. editor. Charles River Media, pp. 254-263,


◆ ATan2D()

function ATan2D ( in  x,
in  y 
)

Inverse tangent -180 < z < 180.


Form

z = ATan2D( x, y )


Inputs

x                  Numerator
y                  denominator

Outputs

z                  inverse tangent (deg)

◆ ATanD()

function ATanD ( in  x)

Inverse tangent with output in degrees.

-90 < s < 90


Form

z = ATanD( x )


Inputs

x                  Argument (deg)

Outputs

s                  inverse tangent(a)

◆ AutoCorr()

function AutoCorr ( in  x,
in  n 
)

Generates the autocorrelation function for the input sequence.


Form

r = AutoCorr( x, n )


Inputs

x                   Input sequence
n                   1st n samples to be used. If omitted use half.

Outputs

r                   Autocorrelation

Reference: Brown R.G. and P.Y.C. Hwang (1992). Introduction to Random Signals and Applied Kalman Filtering. John Wiley & Sons, New York. 114.


◆ BilinearInterpolation()

function BilinearInterpolation ( in  x,
in  y,
in  z,
in  xi,
in  yi 
)

Apply bilinear interpolation on 4 data points.

Type BilinearInterpolation for a demo.


Since version 2014.1

Form

zi = BilinearInterpolation( x, y, z, xi, yi );


Inputs

x   (1,2) Values
y   (1,2) Values
z   (2,2) Values
xi  (1,:) Inputs
yi  (1,:) Inputs

Outputs

zi  (:,:) Interpolated values

◆ Binomial()

function Binomial ( in  y,
in  n 
)

The binomial expansion of (x + y)^n.

The coefficients are for [x^n x^(n-1) ... x^0]


Form

a = Binomial( y, n )


Inputs

y                  Argument
n                  Power

Outputs

a                  Coefficients [n n-1 n-2 ... 0]

References: Spiegel, M. R., Mathematical Handbook, McGraw-Hill,

1968, p. 3.


◆ BinomialTheorem()

function BinomialTheorem ( in  n,
in  k,
in  p 
)

Computes the binomial theorem.

Computes the probability of k
occurences in n tries given the probability p.

Form

pK = BinomialTheorem( n, k, p )


Inputs

n               (1,1)    Number of samples
k               (1,1)    Number of occurences
p               (1,1)    Probability

Outputs

pK              (1,1)    Probability

◆ BisectionZero()

function BisectionZero ( in  f,
in  x0,
in  xLim,
in  xTol,
in  nmax 
)

Use bisection method to find the zero crossing of a function.

The limits are evaluated before the algorithm begins. If both values
either less than or greater than zero, the function returns an
appropriate message and n will be 0.


Since version 10.

Form

[x,n] = BisectionZero( f, x0, xLim, xTol, nmax )


Inputs

f         (1,1)   Function handle
x0        (1,1)   Initial guess for x
xLim      (1,2)   Limits for x: [min,max]
xTol      (1,1)   Tolerance for exit
nmax      (1,1)   Maximum iterations

Outputs

x         (1,1)   Value of x for f(x) = 0
n         (1,1)   Number of iterations (number of function evaluations)
msg       (1,:)   Message if boundary failure

◆ BlockDiagonal()

function BlockDiagonal ( in  m0,
in  n 
)

Generate a block diagonal matrix.

Puts m0 along the diagonal.


Form

m = BlockDiagonal( m0, n )


Inputs

m0  (m,m)     Matrix
n   (1,1)    Number of blocks

Outputs

m   (n*m,n*m)   Block diagonal matrix

◆ BuildLinearDF()

function BuildLinearDF ( in  a,
in  b,
in  states,
in  inputs,
in  lambda,
in  dT 
)

Create a detection filter for a fully measured system.

The filter is of the form:

y[k]   = c*x[k]
x[k+1] = a*x[k] + D*(y[k] - c*x[k]) + b*u[k]

c is the identity matrix in this case.


Form

[d, a, b] = BuildLinearDF( a, b, states, inputs, lambda, dT )


Inputs

a                   (n,n)  Continuous plant matrix
b                   (n,m)  Continuous input matrix
states              {n}    Cell array of state names
inputs              {m}    Cell array of input names
lambda              (1,1)  Inverse time constant

Outputs

d                   (:)   Detection filter
.g   plant
.d   gain matrix
.t   transformation matrix
a                   (n,n) Discrete plant matrix
b                   (n,m) Discrete Input matrix

◆ CableTensionExample()

function CableTensionExample ( in  x,
in  time,
in  t0 
)

Cable tension example.


Form

t = CableTensionExample( x, time, t0 )


Inputs

x               (1,3)   Nominal state [weight/unit length; length;sag]
time            (1,1)   Not used
t0              (1,1)   Base tension

Outputs

t               (1,1)   Tension

◆ CFract()

function CFract ( in  a,
in  b,
in  tol 
)

Computes the value of a continued fraction of the form.

a0

b0 - a1


b1 - a2

b2 - a3

b3

The maximum accuracy depends on the size of a and b. tol is only used for early termination of the series.


Form

x = CFract( a, b, tol )


Inputs

a                     a array
b                     b array
tol                   Error tolerance

Outputs

x                     value of fraction

References: Battin, R. H., An Introduction to the Mathematics and Methods of Astrodynamics, AIAA, 1987, pp. 67-68.


◆ CHarm()

function CHarm ( in  a,
in  n 
)

Generate a series of cosine harmonics of the arguments.


Form

c = CHarm( a, n )


Inputs

a                  Argument (rad)
n                  Number of harmonics

Outputs

c                  Vector of harmonics

◆ CHarmD()

function CHarmD ( in  a,
in  n 
)

Generate a series of cosine harmonics of the arguments.


Form

c = CHarmD( a, n )


Inputs

a                  Column vector (m,1) argument (deg)
n                  Number of harmonics

Outputs

c                  Vector of harmonics

◆ ColCompR()

function ColCompR ( in  a,
in  neps 
)

Computes the right column compression of a matrix.

Compresses the

matrix a so that


comp(a) = [ 0 c ]


c is of full column rank, i.e. the columns are linearly independent.
Zero columns are determined by the singular values.


Since version 1.

Form

[c, v, ac] = ColCompR( a, neps )



Inputs

a                   Matrix
neps                Multiple of machine epsilon to be used
as the tolerance for a zero column

Outputs

c                   Right column compression of a
v                   ac = a*v
ac                  a compressed

References: Maciejowski, J.M., Multivariable Feedback Design, Addison- Wesley, 1989, pp. 366.


◆ Combinations()

function Combinations ( in  r,
in  n 
)

The number of combinations of r articles in n samples.


Form

c = Combinations( r, n )


Inputs

r               (1,1)    Number of articles
n               (1,1)    Number of samples

Outputs

c               (1,1)    Combinations

◆ ComplexToReal()

function ComplexToReal ( in  c)

Convert a matrix from complex to real.

c is assumed to have columns of complex conjugates next to each other.


Form

[r, t] = ComplexToReal( c )


Inputs

c              (n,m)       Square complex matrix

Outputs

r              (n,m)       Square real matrix
t              (m,m)       Transformation matrix.

Reference: Andry, A. N., Jr., Shapiro, E.Y. and J.C. Chung, "Eigenstructure Assignment for Linear Systems," IEEE Transactions on Aerospace and Electronic Systems, Vol. AES-19, No. 5. September 1983.


◆ ConfidenceInterval()

function ConfidenceInterval ( in  x,
in  f,
in  sigma 
)

Computes the confidence interval.

The probability that the value of a random variable will fall
within the specified interval f.

Form

c = ConfidenceInterval( x, f, sigma )


Inputs

x               (1,:)    Samples
f               (1,1)    Fraction
sigma           (1,1)    Known standard deviation

Outputs

c               (1,1)    Confidence

Reference: de Silva, C. W. "Control Sensors and Actuators," Prentice-Hall, 1989, pp. 64-66.


◆ CosD()

function CosD ( in  x)

Cosine with input in degrees.

Since version 1.

Form

z = CosD( x )


Inputs

x                  Argument (deg)

Outputs

z                  Cos(x)

◆ CosX()

function CosX ( in  x)

Computes the value of the cosine function.

Given the argument in degrees.


Since version 1.

Form

z = CosX( x )


Inputs

x           Angle (deg)

Outputs

z           Cos(x)

◆ CotD()

function CotD ( in  x)

Cotangent.

Since version 1.

Form

z = CotD( x )


Inputs

x                  Argument (deg)

Outputs

z                  cotangent

◆ CovarianceRHS()

function CovarianceRHS ( in  t,
in  p,
in  d 
)

Generates the covariance derivative.

The covariance matrix is entered as a column. The columns of the matrix are stacked on each other. All off-diagonal terms are propagated.

noiseFunction( action, tag, d, t )
fFun( t, x, flag, fData )

Form

pDot = CovarianceRHS( t, p, d )


Inputs

t       (1,1)   Time
p       (:,1)   Covariance matrix
d           (.)     Data structure
.x                State vector
.fFun             RHS of the state equations
.q                Noise matrix
.noiseFunction    Noise matrix function
.fData            Data to pass to fFun
.qData            Data to pass to qFun
.dF               fFun is df/dt
.noiseModelOn     1 if noise model is on
.noiseFunctionTag Tag to noise function interface
.k                Which elements of x to use

Outputs

pDot   (:,1)   Covariance matrix derivative

References: Gelb, A. Ed., Applied Optimal Estimation, MIT Press. p.188. Table 6.1-1. Also, pp. 190-191.


◆ CRand()

function CRand ( in  c)

Covariance matrix transformation.

Given a covariance matrix, c, finds a transformation matrix that transforms a vector of normal random numbers each with a standard deviation of 1 into a vector modeled by the covariance matrix. If x is the vector of normal random numbers

y = ax

such that

E(xx') = I

then y is a vector of random numbers such that

E(yy') = c

Uses the Cholesky decomposition of c. c must be positive definite.


Form

a = CRand( c )


Inputs

c              Covariance matrix

Outputs

a              Transformation matrix

◆ Cross()

function Cross ( in  w,
in  y 
)

Vector cross product for multicolum arrays.

The number of columns of w and y can be:

  • Both > 1 and equal
  • One can have one column and the other any number of columns

Form

wxy = Cross( w, y )


Inputs

w                 (3)    Vector
y                 (3)    Vector

Outputs

wxy               (3)    Vector cross product of w and y

◆ CscD()

function CscD ( in  x)

Cosecant with input in degrees.

Since version 1.

Form

z = CscD( x )


Inputs

x                  Argument (deg)

Outputs

z                  Cosecant(x)

◆ DCMotorDetectionFilter()

function DCMotorDetectionFilter ( in  y,
in  v,
in  dT,
in  xDF,
in  alpha,
in  beta,
in  tau 
)

Implements a DC motor detection filter.

Uses Euler integration.

Since version 9.

Form

[r, xDF] = DCMotorDetectionFilter( y, v, dT, xDF, alpha, beta, tau )


Inputs

y              (2,1)  Measurement vector [theta;omega]
v              (1,:)  Motor input voltage
dT             (1,1)  Time step (sec)
xDF            (2,1)  State estimate [theta;omega]
alpha          (1,1)  Motor input constant
beta           (1,1)  Motor rate constant
tau            (1,1)  Filter time constant

Outputs

r              (2,1)  Residuals [theta;omega]
xDF            (2,1)  State estimate [theta;omega]

◆ DCMotorFailures()

function DCMotorFailures ( in  failure,
in  t,
in  dT,
in  c,
in  d,
in  tFail,
in  pFail 
)

Triggers a failure at time tFail.

Sets the failed parameter to pFail.


Form

[c, d] = DCMotorFailures( failure, t, dT, c, d, tFail, pFail )


Inputs

failure        (1,:)  Failure type
t              (1,1)  Time
dT             (1,1)  Time step (sec)
c              (5,4)  State output matrix
d              (1,1)  Motor structure
.beta  (2,1) Rate feedback
.alpha (2,1) Input voltage scaling
tFail          (1,1)  Time of failure
pFail          (1,1)  Set the failed parameter to this value

Outputs

c              (5,4)  State output matrix
d              (1,1)  Motor structure

◆ DCMotorParitySpace()

function DCMotorParitySpace ( in  y,
in  v,
in  dT,
in  plant,
in  q 
)

Computes the residuals for two DC motors.

Since version 9.

Form

[r, q] = DCMotorParitySpace( y, v, dT, plant, q )


Inputs

y              (2,1)  Measurements
v              (2,1)  Stochastic unknown disturbances
dT             (1,1)  Time step (sec)
plant          (1,1)  Plant model data structure
.a  (n,n) Plant
.b  (n,m) Input matrix
q              (1,1)  Data structure for measurements and inputs
.yS (4,1) Measurements
.uS (2,1) Inputs

Outputs

r            (2,1)  Residual
q            (1,1)  Data structure for measurements and inputs
.yS (4,1) Measurements
.uS (2,1) Inputs

◆ DelLZ()

function DelLZ ( in  v)

Deletes leading zeros from a vector.

Since version 1.

Form

v = DelLZ( v )


Inputs

v                          Vector

Outputs

v                          Vector

◆ DeltaAngleForNewRADec()

function DeltaAngleForNewRADec ( in  v1,
in  rA1,
in  dec1,
in  rA2,
in  dec2 
)

Compute the angle change needed to change a trajectory so that it.

passes through the second right ascension and declination.


Type DeltaAngleForNewRADec for demo.

Form

DeltaAngleForNewRADec;
deltaAngle = DeltaAngleForNewRADec( v1, rA1, dec1, rA2, dec2 )


Inputs

v1         (3,1)   Current velocity vector
rA1        (1,1)   Current right ascension (rad)
dec1       (1,1)   Current declination (rad)
rA2        (1,1)   New right ascension (rad)
dec2       (1,1)   New declination

Outputs

deltaAngle (1,1)   Velocity vector angle change (rad)

◆ DeltaEig()

function DeltaEig ( in  a,
in  e 
)

Computes the delta eigenvalues for a given a small perturbation of a, e.


Form

tag = GetNewTag( name )


Inputs

a           (n,n)  Matrix
e           (n,n)  Perturbation

Outputs

deltaS      (1,:)  Delta Eigenvalues

◆ DeltCirc()

function DeltCirc ( in  x,
in  y 
)

Find the angle between x and y.

This function is for subtracting numbers on a circle.


Handle all input angles so that the solution is never greater
than 2*pi.


For example, DeltCirc( 2*pi, pi/6 )

Form

z = DeltCirc( x, y )


Inputs

x                  Angle
y                  Angle

Outputs

z                  Delta angle

◆ DetectionFilter()

function DetectionFilter ( in  d,
in  m,
in  u,
in  x,
in  xS 
)

Implement a detection filter for a fully measured system.

The filter is of the form


y[k]   = c*x[k]
x[k+1] = a*x[k] + D*(m[k] - c*x[k]) + b*u[k]


r[k] = m[k] - c*x[k]


The initial state must be normalized.


Since version 9.

Form

[r, x] = DetectionFilter( d, m, u, x, xS )


Inputs

d                   (:)    Detection filter
.g      plant
.d      gain matrix
.uMin   input minimum
.uRange input range
.yMin   output minimum
.yRange output range
.xMin   state minimum
.xRange state range
m                    Measurements
u                    Inputs
x                    State
xS                   Static state

Outputs

r                    Residuals
x                    State
xS                   Static state

References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control of Turbofan Engines." MIT 1981.


◆ DetectionFilterBuild()

function DetectionFilterBuild ( in  g,
in  lambda 
)

Algorithm to compute detection filter gains.

Create a detection filter for a fully measured system.
The filter is of the form:


y[k]   = c*x[k]
x[k+1] = a*x[k] + D*(y[k] - c*x[k]) + b*u[k]


Since version 9.

Form

d = DetectionFilterBuild( g, lambda )


Inputs

g                   (:)    State space system
lambda        (1,1)  Inverse time constant

Outputs

d                   (:)    Detection filter
.g    plant
.d   gain matrix
.t   transformation matrix

References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control of Turbofan Engines." MIT 1981.


◆ DetectionFilterBuilder()

function DetectionFilterBuilder ( in  action,
in  modifier 
)

GUI to build detection filters.

See also ReduceOrderPlugIn, NormalizePlugIn, ComputeGainsPlugIn, and
SimulatePlugIn


DetectionFilterBuilder is the same as DetectionFilterBuilder('create
gui')


Since version 9.


Inputs

action      (1,:) action to be taken
modifier    (:,:) data corresponding to the action

Outputs

d                 Detection filter data structure

◆ DetectionFilterSimulation()

function DetectionFilterSimulation ( in  d,
in  gP,
in  u,
in  failure,
in  xDF,
in  xP 
)

Simulate a detection filter using a state space model.

The failure vector can be used to fail actuators an sensors. Failures can 
be a bias (which can be zero) and/or noise. All fields in failure are 
optional. If you only enter the k... fields, then the failure will be a 
zero. The bias and noise arrays must be the same size as the k... arrays.


Since version 9.

Form

[r, xDF, xP] = DetectionFilterSimulation( d, gP, u, failure, xDF, xP )


Inputs

d                   (:)    Detection filter
.g      plant
.d      gain matrix
.uMin   input minimum
.uRange input range
.yMin   output minimum
.yRange output range
.xMin   state minimum
.xRange state range
.xS     static valud
gP                   Plant
u                    Inputs
failure              Failure data structure
.kSensorFailed   (1,:)
.sensorBias      (1,:)
.sensorNoise     (1,:)
.kActuatorFailed (1,:)
.actuatorBias    (1,:)
.actuatorNoise   (1,:)
xDF                  State of the detection filter
xP                   State of the plant

Outputs

r                    Residuals
xDF                  State of the detection filter
xP                   State of the plant

References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control of Turbofan Engines." MIT 1981.


◆ DetectionFilterUnnormalized()

function DetectionFilterUnnormalized ( in  d,
in  m,
in  u,
in  x 
)

Create a unnormalized detection filter for a fully measured system.

The filter is of the form


y[k]   = c*x[k]
x[k+1] = a*x[k] + D*(m[k] - c*x[k]) + b*u[k]


r[k] = m[k] - c*x[k]


This filter is unnormalized.


Since version 9.

Form

[r, x] = DetectionFilterUnnormalized( d, m, u, x )


Inputs

d                   (:)    Detection filter
.g      plant
.d      gain matrix
m                    Measurements
u                    Inputs
x                    State

Outputs

r                    Residuals
x                    State

References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control of Turbofan Engines." MIT 1981.


◆ DLyapG()

function DLyapG ( in  a,
in  q 
)

Find the solution for the Lyapunov equation apa' - p + q = 0.

This is the form for discrete systems.


Form

[p, err] = DLyapG( a, q)


Inputs

a                   Matrix
q                   Matrix

Outputs

p                   Solution
err                 Norm of the error

◆ Dot()

function Dot ( in  w,
in  y 
)

Dot product with support for arrays.

The number of columns of w and y can be:
  • Both > 1 and equal
  • One can have one column and the other any number of columns
Since version 1.

Form

d = Dot ( w, y )


Inputs

w                 (:,:)  Vector
y                 (:,:)  Vector

Outputs

d                 (1,:)   Dot product of w and y

◆ DualDCMotors()

function DualDCMotors ( in  x,
in  t,
in  d 
)

Simulates two DC motors.

Since version 9.

Form

xDot = DualDCMotors( x, t, d )


Inputs

x              (4,1)  State vector [theta;omega;theta;omega]
t              (1,1)  Time
d              (1,1)  Motor structure
.beta  (2,1) Rate feedback
.alpha (2,1) Input voltage scaling
.v     (2,1) Input voltage (V)

Outputs

xDot           (4,1)  State vector derivative [theta;omega;theta;omega]

◆ DUnit()

function DUnit ( in  r,
in  v 
)

Derivative of the unit vector for r.

Since version 2.

Form

u = DUnit( r, v )


Inputs

r             (3,:)   Vectors
v             (3,:)   Vector derivatives

Outputs

u             (3,:)   Unit vector derivatives

◆ DupVect()

function DupVect ( in  x,
in  n 
)

Duplicate vector n times.

Create a matrix with n rows or columns each of which equals the row or column vector x. When duplicating a scalar note that For example,

DupVect(3,5) = [3 3 3 3 3]'

Form

y = DupVect( x, n )


Inputs

x                  Vector to be duplicated

Outputs

y                  Matrix with n rows or n columns of x

◆ EMarkov()

function EMarkov ( in  r,
in  tau 
)

Find the correlation time and the mean squared value for a Markov sequence.

The sequence must start with tau = 0. The fit always matches perfectly at
tau = 0 (which gives the mean squared error). A least squares fit is used
to compute the correlation time. This function will set negative values
of r equal to the smallest positive value of r.


Since version 1.

Form

[mSV, tCorr] = EMarkov( r, tau )


Inputs

r            (n)    Sequence
tau          (n)    Time shifts

Outputs

mSV          (1,1)  Mean squared value
tCorr        (1,1)  Correlation time constant

◆ ErrorCombination()

function ErrorCombination ( in  fun,
in  x,
in  e,
in  d 
)

Combine errors given a function.

The error vector e corresponds to
the state vector x. y = fun(x,d). Example 2.15 from the reference is
given.

Form

[eAbs, eSRSS, absA] = ErrorCombination( fun, x, e, d )


Inputs

fun             (1,:)    y = f(x);
x               (:,1)    Nominal measurement
e               (:,1)    Error on each measurement
d               (1,1)    Data structure to pass to fun

Outputs

eAbs            (1,1)    Absolute error
eSRSS           (1,1)    Square root of the sum of the squares
absA            (:,1)    df/dxx

◆ Euler()

function Euler ( in  Fun,
in  x,
in  h,
in  t,
in  varargin 
)

EULER Euler's method for numerical integration.

Accepts up to 10 optional arguments that are passed through to Fun:

Fun(x,{t,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10})

Form

x = Euler( Fun, x, h, t, varargin )


Inputs

Fun                Function    Fun(x,{t,...})
x                  State (column vector)
h                  Independent variable step
t                  Current time
varargin           Optional arguments

Outputs

x                  Updated state

◆ Factorl()

function Factorl ( in  n)

Computes the factorial matrix for a matrix.

Since version 1.

Form

s = Factorl( n )


Inputs

n           (:,:)  Integer

Outputs

s           (:,:)  n!

◆ FindIfInBetween()

function FindIfInBetween ( in  x,
in  a 
)

Determines if x is in between odd-even pairs.

a is a sequence [100 200 300 400 900 1200]

k is 1 if x is between a pair j, j+1 where j is odd such as 1 and 2 or 3 and 4.

Type FindIfInBetween for a demo.


Form

k = FindIfInBetween( x, a )


Inputs

x       (1,1)   Value
a       (1,2*n) Even length array

Outputs

k       (1,1)   1 if x is between indices j and j + 1 where j is odd

◆ FindValidAngleRange()

function FindValidAngleRange ( in  axis,
in  u1,
in  u2,
in  minSep 
)

Find valid range of rotation angles that satisfy separation constraints.

If we rotate "u1" about the "axis" vector by "phi", it becomes "u1R".


The constraint is to keep the rotated "u1R" vector away from the "u2"
vector by a specified angle "minSep":
acos( Dot( u1R, u2 ) ) >= minSep


The "angles" output is the range of "phi" angles that satisfy the
constraint. If empty, then no rotation will satisfy the constraint.


If this function is called with u1, u2, minSep having multiple columns,
then it calls itself recursively, merging the new angle range output
with the previous merge each time.


Type FindValidAngleRange for a demo.

Form

angles = FindValidAngleRange( axis, u1, u2, minSep );


Inputs

axis       (3,1)    Axis of rotation
u1         (3,N)    Vector u1. Constraint is:
acos( Dot(u1,u2) ) >= minSep
u2         (3,N)    Vector u2.
minSep     (1,N)    Keep angle between u1 and u2 greater than minSep.

Outputs

angles     (1,2)    Range of valid rotation angles. If empty, the
constraint cannot be satisfied for any rotation.

◆ FitEllipse()

function FitEllipse ( in  x,
in  y,
in  solnMethod 
)

Fit an ellipse.

The coefficients are:


a(1)*x^2 + a(2)*x*y + a(3)*y^2 + a(4)*x + a(5)* y + a(6) = 0;


Type FitEllipse for a demo.


Since version 2014.1

Form

[a, err] = FitEllipse( x, y )


Inputs

x              (:,1)  x values
y              (:,1)  y values
solnMethod     (1,1)  Solution method. 1=constrained, 2=unconstrained
Default is 1, constrained. Calls "eig".

Outputs

a              (6,1)  Coefficients
err            (1,1)  Fit error

Reference: Fitzgibbon, A. Pilu, M. and Fisher, R. B., "Direct Least Squares Fitting of Ellipses,"Pattern Analysis and Machine Intelligence, Vol. 21, No. 5, May 1999.


◆ FitPair()

function FitPair ( in  x,
in  y,
in  xF 
)

Given xF, find yF that best fits xF given the pair (x,y)

xF may repeat in x. Does a linear interpolation for yF.

For a demo type FitPair.


Form

yF = FitPair( x, y, xF )


Inputs

x               (1,:) x values
y               (1,:) y values
xF              (1,1) Value to be fit

Outputs

yF              (1,n) Corresponding y values

◆ FloatToTwosComplement()

function FloatToTwosComplement ( in  f,
in  n,
in  bigEndian 
)

Converts a float to two's complement array.

For example:

[1 1 1 0 0 1 0 1] = FloatToTwosComplement( -27, 8, 1 )
[0 0 0 1 1 1 0 0] = FloatToTwosComplement(  28, 8, 1 )

Type FloatToTwosComplement for a demo.


Form

b = FloatToTwosComplement( f, n, bigEndian )


Inputs

f                       Float
n                       Bits per word
bigEndian               1 == big endian [msb...lsb] else
[lsb...msb]

Outputs

b                       Binary array

◆ FourierSeries()

function FourierSeries ( in  y,
in  t,
in  n 
)

Generates the Fourier series coefficients of a signal.

Generates the Fourier Series sine and cosine coefficients of a signal using the MATLAB function FFT. Returns the coefficients for a user specified number of harmonics with the largest magnitudes.


Form

[x, w, h] = FourierSeries( y, t, n )


Inputs

y   (k,:)    The signal whose coefficients are to be found.  if y
                         is a matrix each row contains a separate signal. k is 
                         number of signals to be analyzed

t   (1,:)    Time
n   (1,:)    Number of harmonic terms to return

Outputs

x   (2h+1,k) [constant;sine terms;cosine terms]

  w   (k,n)    Frequncies of harmonics  


h                      The number of sine/cosine terms returned.  The length
                         of x will thus be 2*h+1


NOTE
----
  The harmonics are found by finding the peaks in the magnitude, m, of 
  the transform. Using the function FindPeaks.  
                m = sqrt(a.^2 + b.^2)
                a   cosine coefficients
                b   sine coefficients


note: if the signal is very rough, peaks which are not true harmonics will be
found.  The effects of this should be minimized since the peaks are sorted
    by magnitude.

  The number of sine/cosine terms returned varies according to the following:
     - when n is not specified, 
                 h = N/2        where N is the length of the signal
     - when n < number of harmonics found
                 h = n
     - when N/2 > n > number of harmonics found
                 h = number of harmonics found

- when multiple signals are being analyzed, the number of harmonics is
       determined by the signal with the most peaks and the other signals
       will simply return zeroes as place holders.


FOR EXAMPLE:  
    If y contains two signals of length 100, where signal1 is found to
    have 4 harmonics and signal2 is found to have 8 harmonics  h will be 
    as follows:
         n <= 4, h = n
       4 < n <= 8, h = n  but in case of signal1 places > 4 will be zero

8 < n < 50, h = 8  but in case of signal1 places > 4 will be zero
         n >=50, h = 50 full set of coefficients is returned    

◆ FracDI()

function FracDI ( in  y,
in  alpha,
in  n,
in  h 
)

Fractional order derivative or integral.

Implements a fractional order derivative or integral. Integrals are done if alpha < 0

Type FracDI to take integrals and derivatives of a sine function


Form

u = FracDI(y,alpha,n,h)


Inputs

y     (1,:) Input sequence - newest to oldest
alpha (1,1) -1 <= alpha <= 1 Negative are integrals
n     (1,1) Maximum number of terms
h     (1,1) Step size

Outputs

u     (1,1) Output

Reference: Roberto Garrappa, "A Grunwald–Letnikov scheme for fractional operators of Havriliak–Negami type." Recent Advances in Applied Mathematics, Modelling and Simulation, 34, 70-76, 2014


◆ FTrunc()

function FTrunc ( in  x,
in  d 
)

Simulates floating point truncation to -ƒ.

Since version 1.

Form

y = FTrunc( x, d )



Inputs

x                  Input
d                  Number of digits

Outputs

y                  Truncated output

◆ GaussianCPDF()

function GaussianCPDF ( in  x,
in  mu,
in  sigma,
in  tol 
)

Cumulative probability density function for a Gaussian.

Compute the cumulative probability density function for a Gaussian distribution. That is it computes the probability that X is between x(1,:) and x(2,:). If x is entered as a 1-by-n array then it will compute the probabilty that X is between +x(1,:) and -x(1,:)


Form

f = GaussianCPDF( x, mu, sigma, tol )


Inputs

x               (2,:)    Limits
mu              (1,1)    Mean
sigma           (1,1)    Standard deviation
tol             (1,1)    Integration tolerance

Outputs

f               (1,:)    Value

◆ GaussianPDF()

function GaussianPDF ( in  x,
in  mu,
in  sigma 
)

Compute the probability density function for a Gaussian distribution.


Form

f = GaussianPDF( x, mu, sigma )


Inputs

x               (1,:)    Value
mu              (1,1)    Mean
sigma           (1,1)    Standard deviation

Outputs

f               (1,:)    Value

◆ GaussianRSG()

function GaussianRSG ( in  a,
in  b,
in  N 
)

Gaussian Random Sequence Generator Using the Box-Mueller Transform.

Since version 8.

Form

out = GaussianRSG(a,b,N)


Inputs

a                  Mean [Default = 0] (1,1)
b                  Standard Deviation [Default = 1] (1,1)
N                  Length of desired sequence [Default = 1] (1,1)

Outputs

out                Output Sequence (N,1)

◆ GenerateGrid()

function GenerateGrid ( in  n,
in  r,
in  stayout,
in  type 
)

Generate a grid on a sphere.

There can be more than one sphere

The grid is evenly spaced in right ascension and elevation. You can select either a spherical grid (with one point at the pole) or a even distributed grid.

Type GenerateGrid for demo.


Form

GenerateGrid;
[rA, dec, a, kDec, kR, r, nPL] = GenerateGrid( n, r, stayout, type )


Inputs

n          (1,1)   Number of increments of declination
r          (1,:)   Radius of sphere(s)
stayout    (:)     Stayout zones
.rOffset  (3,1) Origin
.u        (3,1) Centerline
.angle    (1,1) Cone angle
type       (1,:)   'globe' or 'spherical'

Outputs

rA         (1,:)   Right ascension
dec        (1,:)   Declination
a          (1,:)   1 if active 0 if inactive
kDec       (1,n)   The first element in rA and dec for each
new declination.
kR         (1,:)   The first element of each new radius
r          (1,:)   Radii of grid points
nPL        (1,:)   Nodes per level

◆ GenSub()

function GenSub ( in  a,
in  b 
)

Subtract two matrices where NaN - NaN or inf - inf == 0.

Since version 2.

Form

c = GenSub( a, b )


Inputs

a             (n,n)  Matrix
b             (n,n)  Matrix

Outputs

c             (n,n) Difference

◆ GJInv()

function GJInv ( in  a)

Matrix inverse using Gauss-Jordan elimination with partial pivoting.

Since version 2.

Form

b = GJInv( a )


Inputs

a             (n,n)  Matrix

Outputs

b             (n,n)  Inverse

References: Strang, G.S., "Linear Algebra and its Applications Third Edition"

Harcourt, Brace and Jovanovich, 1988, pp. 42-58.


◆ GlobeGrid()

function GlobeGrid ( in  n)

Generate right ascensions and declinations for a global grid.

Type GlobeGrid for demo.

Form

[rA, dec, kDec] = GlobeGrid( n )


Inputs

n          (1,1)   Number of right ascensions

Outputs

rA         (1,m)   Right ascension (deg)
dec        (1,m)   Declination (deg)
kDec       (1,n)   The first element in rA and dec for each
new declination.

◆ GridPathCost()

function GridPathCost ( in  startLoc,
in  goalLoc,
in  d 
)

Finds the cost for going from startNode to nextNode.

Assumes a square grid.

Form

cost = GridPathCost( startLoc, goalLoc, d )


Inputs

startNode (1,1) Id of start location
goalNode  (1,1) Id of next location
d         (1,1) Data structure
.n      (1,1) Number of nodes

Outputs

cost      (1,:)  List of nodes in path 

◆ GridSuccessorNodes()

function GridSuccessorNodes ( in  node,
in  parent,
in  d 
)

Finds successor nodes in a square grid.


Form

successorNodes = GridSuccessorNodes( node, parent, d )


Inputs

startNode     (1,1) Id of start location
goalNode      (1,1) Id of next location
d             (1,1) Data structure
.n      (1,1) Number of nodes

Outputs

successorNodes (1,:)  List of nodes in path 

◆ GridTraverseCost()

function GridTraverseCost ( in  startNode,
in  nextNode,
in  d 
)

Finds the cost of going from one node to another in a square grid.

Diagonal moves are permitted.

Form

cost = GridTraverseCost( startNode, nextNode, d )


Inputs

startNode (1,1) Id of start location
nextNode  (1,1) Id of next location
d         (1,1) Data structure
.n      (1,1) Number of nodes

Outputs

cost      (1,:)  List of nodes in path 

◆ Heavisde()

function Heavisde ( in  x)

Heavside function.

H = 1 x „ 0, otherwise = 0


Form

H = Heavisde( x )


Inputs

x                     Input

Outputs

H                       Heaviside function

◆ HypgF1()

function HypgF1 ( in  alpha,
in  gamma,
in  x,
in  tol,
in  nMax 
)

Computes the value of the hypergeometric function.

F(alpha,1;gamma,x)

Examples are: arctanh(x)/x = F(1/2,1;3/2; x^2) = HypgF1(1/2,3/2, x^2) log(1+x) /x = F( 1,1; 2;-x ) = HypgF1( 1, 2, -x) arctan(x) /x = F(1/2,1;3/2;-x^2) = HypgF1(1/2,3/2,-x^2)


Form

[F, n] = HypgF1( alpha, gamma, x )
[F, n] = HypgF1( alpha, gamma, x, tol )
[F, n] = HypgF1( alpha, gamma, x, tol, nMax )


Inputs

alpha                 Argument
gamma                 Argument
x                     Argument
tol                   Tolerance (default 1.e-8);
nMax                  Maximum number of iterations

Outputs

F                     Value of fraction
n                     Number of iterations

References: Battin, R. H., An Introduction to the Mathematics and Methods of Astrodynamics, AIAA, 1987, pp. 34-68.


◆ HypgFr()

function HypgFr ( in  alpha,
in  beta,
in  gamma,
in  x,
in  tol,
in  nMax 
)

Computes the value of the ratio of hypergeometric functions.

F(alpha,beta+1;gamma+1,x)

F(alpha,beta;gamma,x)

HypgFr(alpha,0,gamma,x) = HypgF1(alpha,gamma+1,x)


Form

[F, n] = HypgFr( alpha, beta, gamma, x )
[F, n] = HypgFr( alpha, beta, gamma, x, tol )
[F, n] = HypgFr( alpha, beta, gamma, x, tol, nMax )


Inputs

alpha                 Argument
beta                  Argument
gamma                 Argument
x                     Argument
tol                   Tolerance
nMax                  Maximum number of iterations

Outputs

F                     Value of fraction
n                     Number of iterations

References: Battin, R. H., An Introduction to the Mathematics and Methods of Astrodynamics, AIAA, 1987, pp. 34-68.


◆ HypgMr()

function HypgMr ( in  beta,
in  gamma,
in  x,
in  tol,
in  nMax 
)

Computes the value of the confluent hypergeometric ratio.

M(beta+1,gamma+1,x)

M(beta,gamma,x)


Form

[F, n] = HypgMr( beta, gamma, x )
[F, n] = HypgMr( beta, gamma, x,tol )
[F, n] = HypgMr( beta, gamma, x, tol, nMax )


Inputs

beta                  Argument
gamma                 Argument
x                     Argument
tol                   Tolerance
nMax                  Maximum number of iterations

Outputs

F                     Value of fraction
n                     Number of iterations

References: Battin, R. H., An Introduction to the Mathematics and Methods of Astrodynamics, AIAA, 1987, pp. 34-68.


◆ InsideAngleRange()

function InsideAngleRange ( in  theta,
in  range 
)

Determine whether an angle is inside an angular range.

Type InsideAngleRange for a demo.

Since version 11.

Form

in = InsideAngleRange( theta, range );


Inputs

theta     (1,:)   Angle(s) to check (rad)
range     (1,2)   Angular range (rad)

Outputs

in        (1,:)   Logical flag. 1 if inside range, 0 if not.

◆ Interp1D()

function Interp1D ( in  y1,
in  y2,
in  x1,
in  x2,
in  x 
)

Performs a linear interpolation:

y = (y2-y1)*(x-x1)/(x2-x1) + y1


Form

y = Interp1D( y1, y2, x1, x2, x )


Inputs

y1                 First value
y2                 Second value
x1                 First value
x2                 Second value
x                  Input

Outputs

y                  Interpolated value

◆ InterpolateCircle()

function InterpolateCircle ( in  x1,
in  x2,
in  f 
)

Interpolates between x1 and x2 when x1 and x2 lie in a circle.

When

f = 0 x = x1, when f = 1 x = x2.


Form

x = InterpolateCircle( x1, x2, f )


Inputs

x1            (:,1)    First quantity
x2            (:,1)    Second quantity
f             (1,:)    0 to 1

Outputs

x             (:,1)    Solution

◆ IntersectLineAndCone()

function IntersectLineAndCone ( in  p,
in  u,
in  alpha 
)

Compute the intersection of a line and a cone.

The line is defined by a point and unit vectors.


Form

[y, i] = IntersectLineAndCone( p, u, alpha )


Inputs

p              (3,:)  Points
u              (3,:)  Unit vectors
alpha          (1,1)  alpha

Outputs

y              (6,:) Intersection points
i              (1,:) 1 = intersected

◆ IntersectLineAndEllipsoid()

function IntersectLineAndEllipsoid ( in  p,
in  u,
in  e 
)

Compute the intersection of a line and ellipsoid.

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

Form

[y, i] = IntersectLineAndEllipsoid( p, u, e )


Inputs

p              (3,:)  Points
u              (3,:)  Unit vectors
e              (3,1)  [a; b; c]

Outputs

y              (3,:) Intersection points
i              (1,:) 1 = intersected

◆ IntExp()

function IntExp ( in  a,
in  x,
in  xC,
in  y,
in  yC 
)

One or two dimensional interpolation and extrapolation.

If no outputs are given it will plot the interpolated/extrapolated values on the same plot as the matrix a. x and y are assumed to be in order of minimum to maximum.


Form

c = IntExp( a, x, xC, y, yC )


Inputs

a                      One or two dimensional matrix
x                      Column values
xC                     Points at which a is to be computed
y                      Rows
yC                     Points at which a is to be computed

Outputs

c                      Extrapolated/interpolated values

◆ IntExpR()

function IntExpR ( in  a,
in  x,
in  xC 
)

One dimensional interpolation and extrapolation on the rows of a.


Form

c = IntExpR( a, x, xC )


Inputs

a                      Two dimensional matrix
x                      Column values
xC                     Points at which a is to be computed

Outputs

c                      Extrapolated/interpolated values

◆ Inv3x3()

function Inv3x3 ( in  a)

Inverse of a 3x3 matrix.

Since version 1.

Form

ainv = Inv3x3( a )


Inputs

a        (3,3)    A matrix

Outputs

ainv     (3,3)    The inverse of a

◆ InvP()

function InvP ( in  bInvOld,
in  v,
in  k 
)

The product form of the inverse.

[ 1     v1]-1
inv(Bnew) = [    1  v2]  inv(Bold)
[       v3] 


v = inv(Bold)y where y is the new column k of B

Form

bInv = InvP( bInvOld, v, k )


Inputs

bInvOld       (n,n)    Old inverse
v             (n,1)    Vector = inv(Bold)*y where y is a new column of B
k                      Column index of v

Outputs

bInv          (n,n)    New inverse

◆ IsSing()

function IsSing ( in  a)

Outputs 0 if the matrix is singular.

Since version 1.

yes = IsSing( a )



Inputs

a            Matrix

Outputs

yes          0 if matrix is singular

◆ IsZero()

function IsZero ( in  a)

Set = 0 if the matrix is all zeros.

Since version 1.

yes = IsZero( a )



Inputs

a                         Matrix

Outputs

yes                       0 if matrix is zero

◆ Jacobian()

function Jacobian ( in  funFcn,
in  xOP,
in  tOP,
in  varargin 
)

This function computes the Jacobian matrix for a right hand-side.

The central difference approximation good to O(h^2) is used. For any function f(x,t) it will compute the f0 and a matrices.

f(x,t) ~= f(xOP,tOP) + a(xOP,tOP) x + ...

funFcn is input as a character string 'xxxxx' and must be of the form xdot = xxxxx ( x, t, {p1,p2,p3,p4,p5,p6,p7,p8,p9,p10}) which is the same form used in RK2 and RK4. tOP is optional. If not needed pass [].


Form

[a, fOP] = Jacobian( funFcn, xOP, tOP, varargin )


Inputs

funFcn                'function name' or handle
xOP            (n,1)  State at the operating point
tOP                   Time
varargin              Optional arguments

Outputs

a              (n,n)  Jacobian matrix of first partials       
fOP            (n,1)  f(xOP,tOP) at the operating point

◆ JacobianODE()

function JacobianODE ( in  funFcn,
in  tOP,
in  xOP,
in  d 
)

This function computes the Jacobian matrix for a right hand-side.

The central difference approximation good to O(h^2) is used. For any function f(x,t) it will compute the f0 and a matrices where dx/dt = ax + f0.

f(x,t) ~= f(xOP,tOP) + a(xOP,tOP) x + ...

funFcn is input as a character string 'xxxxx' and must be of the form xdot = xxxxx ( t, x, flag, d ) which is the same form used in ode113.


Form

[a, fOP] = JacobianODE( funFcn, tOP, xOP, d )


Inputs

funFcn         (1,:)  T'function name'
tOP            (1,1)  Time
xOP            (n,1)  State at the operating point
d                     Optional data structure

Outputs

a              (n,n)  Jacobian matrix of first partials       
fOP            (n,1)  f(xOP,tOP) at the operating point

◆ JCart2Sp()

function JCart2Sp ( in  c)

Converts cartesian to spherical coordinates.

Spherical coordinates are defined as[r,theta,phi] where phi is the angle from the +z axis and theta is the angle from +x in the xy-plane.

x = r*cos(theta)*sin(phi)
y = r*sin(theta)*sin(phi)
z = r*cos(phi)


Since version 1.

Form

jC = JCart2Sp( c )


Inputs

c               (3,1)  Cartesian coordinates [x, y, z]

Outputs

jC              (3,3)  Jacobian from cartesian to spherical [r, theta, phi]
Phi is zero in the xy plane
[     r/x     r/y     r/z ]
[ theta/x theta/y theta/z ]
[   phi/x   phi/y   phi/z ]

◆ JSp2Cart()

function JSp2Cart ( in  s)

Jacobian for converting from spherical to cartesian coordinates.

Computes the Jacobian for converting from spherical to cartesian coordinates. Spherical coordinates are defined as [r,theta,phi] where phi is the angle from the +z axis and theta is the angle from +x in the xy-plane.

x = r*cos(theta)*sin(phi)
y = r*sin(theta)*sin(phi)
z = r*cos(phi)

Form

jC = JSp2Cart( s )


Inputs

s               (3,1)  Spherical coordinates [r,theta,phi]

Outputs

jC            (3,3)  Jacobian from spherical to cartesian
[ x/r x/theta x/phi ]
[ y/r y/theta y/phi ]
[ z/r z/theta z/phi ]

◆ LeastSq()

function LeastSq ( in  e,
in  y,
in  x,
in  w 
)

Weighted least squares curve fit.

Find a weighted least squares curve fit to the overdetermined set of equations

y = ax 

where

a = [x.^e(1), x.^e(2)...] and x are column vectors

where y and x are inputs and y = f(x).

Type LeastSq for an example of overfitting


Form

[c, err] = LeastSq( e, y, x, w )
[c, err] = LeastSq( e, y, x )


Inputs

e                  Array of exponents
y                  Left hand side
x                  Right hand side
w                  Weights

Outputs

c                  Coefficients

◆ LEPDS()

function LEPDS ( in  a,
in  b 
)

Solves the problem ax = b when a is positive definite symmetric.

Since version 1.

Form

[x, err] = LEPDS( a, b )


Inputs

a           (n,n)   Positive definite matrix
b           (n,1)   Right hand side

Outputs

x           (n,1)   Solution
err                 Error

Reference: Golub, G.H., Van Loan C.F. (1983). Matrix Computations.

The John Hopkins University Press Baltimore, MD. 82-85.


◆ LinearSinCosToQuadCos()

function LinearSinCosToQuadCos ( in  a,
in  b,
in  c 
)

Compute quadratic coefficients on cos(x) from linear eqn.

A*sin(x)+B*cos(x)+C=0

Type LinearSinCosToQuadCos for a demo.


Form

p = LinearSinCosToQuadCos( a, b, c )


Inputs

a         (1,1)   Coefficient on sin(x)
b         (1,1)   Coefficient on cos(x)
c         (1,1)   Linear term

Outputs

p         (1,3)   Polynomial coefficients. Quadratic of cos(x)

◆ LogBaseN()

function LogBaseN ( in  n,
in  x 
)

log of base n.

The demo solves the problem log base 4 of 2.


Form

y = LogBaseN(n,x)


Inputs

n     (1,1)      Base
x     (1,:)      Number

Outputs

y     (1,:)      log base n of x

◆ Logistic()

function Logistic ( in  x)

Logistic function.

f = 1/(1+exp(-x));


Form

f = Logistic( x )


Inputs

x           (1,:) Input

Outputs

f           (1,:) Logistic function

◆ LSSVD()

function LSSVD ( in  a,
in  b,
in  tol 
)

Solves ax = b using the singular value decomposition.

Since version 1.

Form

[x, r, cn, rank] = LSSVD( a, b, tol )


Inputs

a                  A matrix
b                  Right-hand-side
tol                Tolerance on the minimum singular value

Outputs

x                  State
r                  Residual Ax - b
cn                 Condition number
rank               Rank of the matrix

References: Forsythe, G.E., M.A. Malcolm, C.B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1977, pp. 192-213.


◆ LyapG()

function LyapG ( in  a,
in  q 
)

Solve the general Lyapunov equation ap + pa' + q = 0.


Form

[p, err] = LyapG( a, q )



Inputs

a                   Matrix
q                   Matrix

Outputs

p                   Solution
err                 Norm of the error

◆ Mag()

function Mag ( in  u)

Magnitude of a set of vectors.

Given a 3-by-n matrix where each column represents a vector, return a row vector of the magnitudes of each column.


Form

m = Mag( u )


Inputs

u            (:,:)  Vectors

Outputs

m            (:)   Corresponding magnitudes

◆ MakeDistribution()

function MakeDistribution ( in  x,
in  f,
in  N 
)

Generate a list of random variables with some specified distribution.


Form

xOuts = MakeDistribution(x,f,N)


Inputs

x             (1,:)  Vector of distribution function independent
variable values, the x in f(x)
f             (1,:)  Vector of distribution function values evaluated
at x, the f in f(x)
N             (1,1)  How many variables to generate with that f(x)?

Outputs

xOuts         (1,N)  Vector of random values, x, with probability
distribution f(x)

Copyright (c) 2020 Princeton Satellite Systems, Inc. All rights reserved.


Since version 2020


◆ ManeuverCost()

function ManeuverCost ( in  startNode,
in  nextNode,
in  d 
)

Finds the cost for going from startNode to nextNode.


Form

cost = ManeuverCost( startNode, nextNode, d )


Inputs

startNode (1,1) Id of start location
goalNode  (1,1) Id of next location
d         (1,1) Data structure
.rA     (1,:) Node right ascension
.dec    (1,:) Node declination
.v      (3,:) Velocity

Outputs

cost      (1,:)  List of nodes in path 

◆ ManeuverCost3D()

function ManeuverCost3D ( in  startNode,
in  nextNode,
in  d 
)

Finds the cost for going from startNode to nextNode in 3D.


Form

cost = ManeuverCost3D( startNode, nextNode, d )


Inputs

startNode (1,1) Id of start location
nextNode  (1,1) Id of next location
d         (1,1) Data structure
.rA     (1,:) Node right ascension
.dec    (1,:) Node declination
.r      (1,:) Radius

Outputs

cost      (1,1)  Cost to traverse the distance

◆ ManeuverSuccessorNodes()

function ManeuverSuccessorNodes ( in  node,
in  parent,
in  d 
)

Finds successor nodes.


Form

successorNodes = ManeuverSuccessorNodes( node, parent, d )


Inputs

node           (1,1) Id of current node
parent         (1,1) Last node traversed
d              (1,1) Data structure
.a      (1,:) 1 if  node is not blocked
.kDec   (1,:) List of start location of new dec
.rA     (1,:) Node right ascension

Outputs

successorNodes (1,:)  List of nodes in path 

◆ ManeuverSuccessorNodes3D()

function ManeuverSuccessorNodes3D ( in  node,
in  parent,
in  d 
)

Finds successor nodes in 3D.


Form

successorNodes = ManeuverSuccessorNodes3D( node, parent, d )


Inputs

node           (1,1) Id of current node
parent         (1,1) Last node traversed
d              (1,1) Data structure
.a      (1,:) 1 if  node is not blocked
.kDec   (1,:) List of start location of new dec
.rA     (1,:) Node right ascension
.r      (1,:) Radius of node
.kR     (1,:) List of start locations of new r

Outputs

successorNodes (1,:)  List of nodes in path 

◆ Markov()

function Markov ( in  sigma,
in  tCorr,
in  n,
in  tSamp 
)

Generate random output from a Gauss-Markov process.

The autocorrelation function for a Gauss-Markov process is

sigma^2*exp(-abs(tau)/tCorr)

Form

[x, tau] = Markov( sigma, tCorr, n, tSamp )


Inputs

sigma        (:)    Square root of mean squared value
tCorr        (:)    Correlation time constant
n            (1,1)  Number of samples
tSamp        (1,1)  Sampling period

Outputs

x          (:,n)    Output
tau          (n)    Time shifts

Reference: Brown R.G. and P.Y.C. Hwang (1992). Introduction to Random

Signals and Applied Kalman Filtering. John Wiley & Sons, New York. 134.


◆ MergeAngleRange()

function MergeAngleRange ( in  range1,
in  range2 
)

Merge two angular ranges.

Returns the intersection.

Type MergeAngleRange for a demo


Form

range = MergeAngleRange( range1, range2 )


Inputs

range1    (1,2)   First angular range (rad)
range2    (1,2)   Next angular range (rad)

Outputs

range     (1,2)   Merged range (rad)

◆ ModNewt()

function ModNewt ( in  f,
in  fD,
in  fDD,
in  x,
in  epsilon,
in  nMax,
in  varargin 
)

Finds the solution to f(x) = 0 given derivative information.

Uses df(x)/dx when only one root is possible. If there are multiple
roots, x should be in the vicinity of the desired root.


Since version 1.

Form

[x, n] = ModNewt( f, fD, fDD, x, epsilon, nMax, varargin )


Inputs

f                     String name of f(x),      i.e. 'f'
fD                    String name of df(x)/dx   i.e. 'dfdx'
fDD                   String name of d2f(x)/dx2 i.e. 'd2fdx2'
x                     Initial guess
epsilon               Tolerance
nMax                  Max number of iterations (can be inf)
varargin              Optional arguments

Outputs

x                     Result
n                     Number of iterations

References: Hornbeck, R., Numerical Methods, Quantum, 1975, pp. 69-70.


◆ NewStats()

function NewStats ( in  oldS,
in  oldM,
in  count,
in  x 
)

Calculates the new standard deviation and average.


Form

[s, m]  = NewStats( oldS, oldM, count, x )


Inputs

oldS      (:,:)  Old standard deviation of the data set
oldM      (:,:)  Old average of the data set
count     (1,1)  Number of elements in data set (including x)
x         (:,:)  New element that has been added to the data


-------
Outputs
-------


s         (:,:)  New standard deviation
m         (:,:)  New average

◆ NewtonsMethod()

function NewtonsMethod ( in  f,
in  grad,
in  hess,
in  x,
in  stopData,
in  stepSizeData 
)

Solve an optimization problem with Newton's method.

Requires the objective value, gradient vector, and hessian matrix to be defined with function handles.


Form

[xopt,nSteps,cpuTime,iterate,objValue] = ...
NewtonsMethod(f,grad,hess,x,stopData,stepSizeData);


See also:  Armijo.m, NLEqSolver.m


Inputs

f             @(x)   Function handle for cost function
grad          @(x)   Function handle for gradient of cost function
hess          @(x)   Function handle for hessian of cost function
x             (n,1)  Initial state
stopData      .      Data structure with fields:
.fun     Function handle with arguments "f(x), grad(x)"
returning true if stop conditions met, else false.
.maxIter Maximum number of iterations.
.gTol    Gradient norm tolerance. Stop when norm of gradient
vector is below this threshold.
stepSizeData  .rule    Name of the stepsize rule. 3 choices:
- Constant  (define s)
- Armijo    (define s, sigma, beta)
.s       Scalar stepsize.
.sigma   Scale factor for Armijo rule
.beta    Scale factor for Armijo rule

Outputs

xopt          (n,1)       Optimal solution
nSteps        (1,1)       Number of iteration steps computed
cpuTime       (1,1)       Total time to execute, in seconds
iterate       (1,nSteps)  History of iterate
objValue      (1,nSteps)  History of objective value

◆ NewtRaph()

function NewtRaph ( in  f,
in  fD,
in  x,
in  epsilon,
in  nMax,
in  varargin 
)

Newton Raphson root finding method.

Finds the solution to f(x) = 0 given df(x)/dx when only one root is possible. If there are multiple roots, x should be in the vicinity of the desired root. Accepts up to 10 optional arguments that are passed through to f and fD.


Form

[x, n] = NewtRaph( f, fD, x, epsilon, nMax, varargin )


Inputs

f                     String name of f(x),    i.e. 'f'
fD                    String name of df(x)/dx i.e. 'dfdx'
x                     Initial guess
epsilon               Tolerance
nMax                  Max number of iterations (can be inf)
varargin              Optional arguments

Outputs

x                     Result
n                     Number of iterations

References: Hornbeck, R., Numerical Methods, Quantum, 1975, pp. 66-67.


◆ NLEqSolver()

function NLEqSolver ( in  fun,
in  x,
in  opt,
in  d 
)

Solves a set of equations for zero using Newton's method.

The function must be of the form


fun( x, d )


where d is a data structure with parameters

Form

[x, err, n] = NLEqSolver( fun, x, opt, d )


Inputs

fun           (1,:)   String with the function name
x             (:,1)   The initial solution guess
opt           (1,1)   The options for the solver  
.nMax (1,1) Maximum number of iterations
.tol  (1,1) Tolerance on error
.dX   (1,1) Perturbation for the Jacobian
d             (1,1)   Data structure passed to fun

Outputs

x             (:,1)   The solution
err           (:,1)   The errors
n             (1,1)   Number of iterations

◆ NLEqSolverWrapper()

function NLEqSolverWrapper ( in  fun,
in  x,
in  opt,
in  d,
in  xRange 
)

Wraps the Newton's method solver by trying several values.

The function must be of the form


fun( x, d )


where d is a data structure with parameters

Form

[x, err, n] = NLEQSolver( fun, x, opt, d )


Inputs

fun           (1,:)   String with the function name
x             (:,1)   The initial solution guess
opt           (1,1)   The options for the solver  
.nMax (1,1) Maximum number of iterations
.tol  (1,1) Tolerance on error
.dX   (1,1) Perturbation for the Jacobian
.verb (1,1) If this field is entered it
will print info if the number
of iterations is exceeded.
d             (1,1)   Data structure passed to fun
xRange        (:,2)   Range of values for x

Outputs

x             (:,1)   The solution
err           (:,1)   The errors
itsTotal      (1,1)   Number of iterations

◆ NonlinearEstimator()

function NonlinearEstimator ( in  yEst,
in  yMeas,
in  t,
in  d 
)

Implements an online approximator for a spring mass damper system.

Uses radial basis functions. This is an example of the use of
online approximators for fault detection. Calls OnlineApproximator.


Since version 9.

Form

yEst = NonlinearEstimator( yEst, yMeas, t, d )  


Inputs

yEst    (:,1)  [state;theta]
yMeas   (2,1)  Measured state
t       (1,1)  Time
d       (1,1)  Input data structure
.plant (1,1)
.k0 (1,1) Spring stiffness
.c0 (1,1) Damping
.m  (1,1) Mass
.est   (1,1) 
.k  (1,1) Spring stiffness
.c  (1,1) Damping
.oA    (1,1)
.sigma    (1,1) Standard deviation
.c        (q,1) Centers
.thetaMax (1,1) Maximum parameter
.gamma    (1,1) Lyapunov gain

Outputs

yEst    (:,1)  [state;theta]

References: Demetriou, M. A. and M. M. Polycarpou. "Incipient Fault Diagnosis of Dynamical Systems Using Online Approximators." IEEE Trans. Automatic Control, Vol. 43, No. 11, Nov. 1998, pp. 1612-1616.


◆ NonlinearSpring()

function NonlinearSpring ( in  x,
in  t,
in  d 
)

Right-hand-side of a nonlinear spring dynamics model.

Since version 9.

Form

dX = NonlinearSpring( x, t, d )


Inputs

x       (4,1)  State
t   (1,1)  Time
d   (1,1)  Input data structure

Outputs

dX  (4,1)  State derivative

References: Demetriou, M. A. and M. M. Polycarpou. "Incipient Fault Diagnosis of Dynamical Systems Using Online Approximators." IEEE Trans. Automatic Control, Vol. 43, No. 11, Nov. 1998, pp. 1612-1616.


◆ NonlinearSpringFault()

function NonlinearSpringFault ( in  x,
in  t,
in  d 
)

Nonlinear spring fault.

Generates a cubic spring force that grows
with the function (1 - exp(d.a*dT)) where dT is the time since the
fault. Prior to the fault, the force is zero.


Since version 9.

Form

f = NonlinearSpringFault( x, t, d )


Inputs

x       (2,1)  State
t       (1,1)  Time
d       (1,1)  Input data structure

Outputs

f       (1,1)  Force due to fault

References: Demetriou, M. A. and M. M. Polycarpou. "Incipient Fault Diagnosis of Dynamical Systems Using Online Approximators." IEEE Trans. Automatic Control, Vol. 43, No. 11, Nov. 1998, pp. 1612-1616.


◆ NormalDistribution()

function NormalDistribution ( in  x,
in  mu,
in  sigma 
)

Matrix normal or Gaussian distribution.

Type NormalDistribution for a demo.


Since version 11.

Form

n = NormalDistribution( x, m, sigma )


Inputs

x       (n,1)  Value
mu      (n,1)  Mean (can be (1,1)
sigma   (n,n)  Standard deviation

Outputs

p       (n,1) Normal distribution 

◆ NormalizeMatrix()

function NormalizeMatrix ( in  g,
in  xRange,
in  yRange,
in  uRange 
)

Normalizes a state space system for use with a detection filter.

Since version 9.

Form

g = NormalizeMatrix( g, xRange, yRange, uRange )


Inputs

g                   (:)    State space system
xRange              (:,1)  Range of x
yRange              (:,1)  Range of y
uRange              (:,1)  Range of u

Outputs

g                   (:)    State space system

References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control of Turbofan Engines." MIT 1981. p. 211.


◆ Odd()

function Odd ( in  x)

1 if the value is odd

Since version 1.

Form

n = Odd( x )


Inputs

x         argument

Outputs

n         1 if odd, 0 if even

◆ OnlineApproximator()

function OnlineApproximator ( in  y,
in  theta,
in  d 
)

Implements an online approximator, f( y, theta ).

Uses radial basis functions.


Since version 9.

Form

[f, z] = OnlineApproximator( y, theta, d )  


Inputs

y       (1,1)  State
theta   (q,1)  Parameters
d       (1,1)  Input data structure
.sigma (1,1) Standard deviation
.c     (q,1) Centers

Outputs

f       (1,1)  Output
z       (q,1)  Partials of f

References: Demetriou, M. A. and M. M. Polycarpou. "Incipient Fault Diagnosis of Dynamical Systems Using Online Approximators." IEEE Trans. Automatic Control, Vol. 43, No. 11, Nov. 1998, pp. 1612-1616.


◆ OptimalTrajectory()

function OptimalTrajectory ( in  x0,
in  xF,
in  t,
in  uMax,
in  f,
in  maxIter 
)

Optimal trajectory using simplex.

Computes the control for an optimal trajectory using simplex for a fixed end time and state.

Type OptimalTrajectory for a demo.


Form

[err, u, x] = OptimalTrajectory( x0, xF, tF, uMax, f, maxIter )


Inputs

x0             (:)    Initial state
xF             (:)    Final state
t              (1,:)  Times
uMax           (:,1)  Maximum control
f              (:)    Continuous time system
.a   (n,n)   State transition matrix
.b   (n,m)   Control input matrix
maxIter        (1,1)  Maximum number of iterations for simplex

Outputs

err            (1,1)  Error
u              (:)    Control
x              (:,:)  State

◆ Orthogonalize()

function Orthogonalize ( in  m)

Orthogonalize a matrix.

m = m/sqrtm(m'*m);


so that m'*m = eye(3)

Form

m = Orthogonalize( m )


Inputs

m               (3,3)  Matrix

Outputs

m               (3,3)  Orthogonal atrix

Raible, E. (1990) Graphics Gems.


◆ Pade()

function Pade ( in  n,
in  m,
in  T 
)

Create a Padé approximant of exp(sT)


Form

[num, den] = Pade( n, m, T )


Inputs

n                   Numerator degree ( 0+ )
m                   Denominator degree ( 1+ )
T                   Exponential coefficient

Outputs

num                 Numerator
den                 Denominator polynomial

References: Moler, C. and C. Van Loan, "Nineteen Dubious Ways to Compute the Exponential of a Matrix," Numerical Linear Algebra Techniques for Systems and Control," IEEE, p.655.


◆ PAL()

function PAL ( in  nMax,
in  mMax,
in  x 
)

Generates the Associated Legendre Functions of the first kind.

The first index is n and the second is m Input is limited to -1 ž x ž 1

m The output matrix is P(n,m) == P or P

n nm P(0,0) P(1,0) P(1,1) P(2,0) P(2,1) P(2,2) P(3,0) P(3,1) P(3,2) P(3,3) P(4,0) P(4,1) P(4,2) P(4,3) P(4,4)

P(nMax,mMax)


Form

p = PAL ( nMax, mMax, x )


Inputs

nMax               Max value of first index
mMax               Max value of second index
x                  Argument

Outputs

p                  Associated Legendre functions

◆ PDAL()

function PDAL ( in  nMax,
in  mMax,
in  x,
in  xD 
)

Generates Associated Legendre Functions of the first kind and derivatives.

The first index is n and the second is m Input is limited to -1?x?1


Form

[p, pD] = PDAL( nMax, mMax, x, xD )


Inputs

nMax               Max value of first index
mMax               Max value of second index
x                  Argument
xD                 Derivative of the argument

Outputs

p                  associated Legendre functions
pD                 derivative of the associated Legendre functions

References: Spiegel, M.,R., Mathematical Handbook, McGraw-Hill pp 146-150


◆ Perpendicular()

function Perpendicular ( in  a)

Finds perpendicular vectors to a such that Dot(b,a) = 0.

Type Perpendicular for a demo.

Form

b = Perpendicular( a )


Inputs

a                   (3,:)    Input

Outputs

b                   (3,:)    Perpendicular

◆ PGauss()

function PGauss ( in  nMax,
in  mMax,
in  theta 
)

Computes the Gaussian form of the Legendre functions.

Will also compute the first derivatives, if requested.

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


Form

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


Inputs

nMax               max value of first index
mMax               max value of second index
theta              input value (usually an angle in rads)

Outputs ----— n,m

p                  Gauss functions, P
n,m
dP                 dP/d(theta)      

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


◆ PointInGridInTriangle()

function PointInGridInTriangle ( in  v,
in  n,
in  m 
)

Determine whether points p are in triangle v.

Type PointInTriangle for a demo.


If no outputs are specified it will draw the triangle and the points.


Since version 11.

Form

t = PointInGridInTriangle( v, n, m )


Inputs

v             (2,3) Vertices of the triangle
n             (1,1) Rows
m             (1,1) Columns

Outputs

t             (1,:) Coordinates

Reference: http://www.blackpawn.com/texts/pointinpoly/default.html


◆ PointInPolygon()

function PointInPolygon ( in  p,
in  v 
)

Determine whether points p are in polygon v.

The polygon is formed by edges
v(:,1) -> v(:,2) -> ... v(:,end) -> v(:,1)


Type PointInPolygon for a demo.


If no outputs are specified it will draw the polygon and the points.

Form

r = PointInPolygon( p, v )


Inputs

p             (2,n) Points
v             (2,m) Vertices of polygon

Outputs

r             (1,n) 1 = yes

Reference: W. Randolf Franklin http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html


◆ PointInTriangle()

function PointInTriangle ( in  v,
in  p 
)

Determine whether points p are in triangle v.

Type PointInTriangle for a demo.


If no outputs are specified it will draw the triangle and the points.


Since version 11.

Form

r = PointInPolygon( p, v )


Inputs

v             (2,3) Vertices of the triangle
p             (2,:) Points

Outputs

r             (1,:) 1 = yes

Reference: http://www.blackpawn.com/texts/pointinpoly/default.html


◆ ProbabilityOfFailure()

function ProbabilityOfFailure ( in  lambda,
in  t 
)

Computes the probability of failure.

Failure rate is in failures/unit time using the time units for t.

Type ProbabilityOfFailure for a demo.


Form

p = ProbabilityOfFailure( lambda, t )


Inputs

lambda         (1,1)  Failure rate    (1/unit time)
t              (1,:)  Time            (unit time)

Outputs

p              (1,:)  Probability of failure

Reference: Vesely, W, "Fault Tree Analysis with Aerospace Applications," Aug. 2002 p. 85


◆ Product()

function Product ( in  v)

Computes product of the terms in a vector.

If a matrix it computes products of the terms in each row and
returns a column vector.


Since version 1.

Form

p = Product( v )


Inputs

v                  Vector

Outputs

p                  Product

◆ R2P5()

function R2P5 ( in  y)

Rounds towards zero to the nearest 1/2.


Form

x = R2P5( y )


Inputs

y           Number

Outputs

x           Rounded number

◆ RadialBasisFunction()

function RadialBasisFunction ( in  y,
in  c,
in  sigma 
)

Implements a radial basis function for online estimators.

Type RadialBasisFunction for a demo.


Since version 9.

Form

f = RadialBasisFunction( y, c, sigma )      


Inputs

y       (:,:)  Input
c       (q,1)  Center
sigma   (1,1)  Standard deviation

Outputs

f       (1,:)  Output

References: Orr, M. J. L. "Introduction to Radial Basis Function Networks."

Centre for Congitive Science, University of Edinburgh, www.anc.ed.ac.uk/~mjo/papers/intro.ps.


◆ Ramp()

function Ramp ( in  t,
in  t0,
in  v0,
in  vF,
in  vDotMax 
)

Generate a ramp signal at t0 from value v0 to vF in time interval t.


Form

v = Ramp( t, t0, v0, vF, vDotMax )


Inputs

t           (1,:)  Time vector
t0           (1)   Time at which to begin ramp
v0           (1)   Initial value
vF           (1)   Final value
vDotMax      (1)   slope of ramp

Outputs

v           (1,:)  Ramp signal

◆ Ramps()

function Ramps ( in  t,
in  dT,
in  varargin 
)

Generates ramps for any number of inputs.

Since version 10.

For example:
t = [0 10 100];
v = [0 20  30];
h = [10 4  33];


[tS,vS,hS] = Ramps(t,0.1,v,h)

Form

[tS, varargout] = Ramps( t, dT, varargin )


Inputs

t              (1,:)  Transition times
dT             (1,1)  Time step
varargin       {:}    Any number of input variables

Outputs

tS             (1,p)  Times for each step
varargout      {:}    Ramps corresponding to varargin's
m              (1,:)  Mass of tank
v              (1,:)  Volume

◆ Random()

function Random ( in  seed,
in  n,
in  m 
)

Compute a random nxm matrix.

Since version 1.

Form

[r, seed] = Random( seed, n, m )


Inputs

seed       (1,1)   Seed
n          (1,1)   Rows
m          (1,1)   Columns

Outputs

r          (n,m)   Random matrix
seed               Seed

◆ RandP()

function RandP ( in  lambda,
in  n,
in  m 
)

Generate a Poission random matrix.

Type RandP for a demo.


Form

q = RandP( lambda, n, m )


Inputs

lambda    (1,1) Coefficient
n         (1,1) Rows
m         (1,1) Columns

Outputs

q         (n,m) Random matrix

Reference: Knuth


◆ RandPM()

function RandPM ( in  n,
in  varargin 
)

Generates uniform random matrices between -1 and +1.

Since version 2.

Form

x = RandPM( n, m, p, ... )


Inputs

n          (1,1)    Dimension or array of dimensions
varargin

Outputs

x          (n,m)    Random matrix

◆ RandPN()

function RandPN ( in  lambda,
in  n,
in  m 
)

Generate a Poission random matrix using a normal approximation.

lambda should be >= 5 for this to work.

This routine forces the results to be positive since the Poisson distribution is always > 0.

Type RandPN for a demo.


Form

q = RandPN( lambda, n, m )


Inputs

lambda    (1,1) Coefficient
n         (1,1) Rows
m         (1,1) Columns

Outputs

q         (n,m) Random matrix

◆ RK2()

function RK2 ( in  Fun,
in  x,
in  h,
in  t,
in  varargin 
)

Second order Runge-Kutta.

Called function is of the form:

Fun(x,{t,p1,p2,...})

Accepts optional arguments that are passed through to Fun. Time is also optional.


Form

x = RK2( Fun, x, h, t, varargin )


Inputs

Fun                Function    Fun(x,{t,...})
x                  State (column vector)
h                  Independent variable step
t                  Current time
varargin           Optional arguments

Outputs

x                  Updated state

◆ RK4()

function RK4 ( in  Fun,
in  x,
in  h,
in  t,
in  varargin 
)

Fourth order Runge-Kutta.

Called function is of the form:

Fun(x,t,varargin)

Accepts optional arguments that are passed through to Fun. Time is also optional. This version is streamlined and designed to take advantage of MATLAB's function handles feature (MATLAB versions 6 and up only). Passing a string function name (version 5) will also work but is slower.


Form

x = RK4( Fun, x, h, t, varargin )


Inputs

Fun                Function    Fun(x,{t,...})
x                  State (column vector)
h                  Independent variable step
t                  Current time
p1...              Optional arguments

Outputs

x                  Updated state

◆ RK45()

function RK45 ( in  Fun,
in  x,
in  h,
in  hMax,
in  hMin,
in  tol,
in  t,
in  varargin 
)

Fourth/fifth order Runge-Kutta.

Called function is of the form:


Fun(x,t,p1,p2,...)


Accepts optional arguments that are passed through to Fun.
Time is also optional.


This function will integrate Fun from the current t to t + hMax.


Since version 1.

Form

[x, hLast] = RK45( Fun, x, h, hMax, hMin, tol, t, varargin )


Inputs

Fun                Function    Fun(x,t,p1,p2...)
x                  State (column vector)
h                  Independent variable step
hMax               Maximum step size
hMin               Minimum step size
tol                Tolerance on error, default 1.e-6
t                  Current time
varargin           Optional arguments

Outputs

x                  Updated state
hLast              Independent variable step

Reference: Cash, J.R., A. H. Karp, "A Variable Order Runge-Kutta Method for Initial Value Problems with Rapidly Varying Right-Hand Sides," ACM Trans. on Math. Soft., Vol. 16, No.3, Sept. 1990, pp 201-222.


◆ RK4TI()

function RK4TI ( in  rhs,
in  x,
in  h,
in  a 
)

Fourth order Runge-Kutta integration.

RHS is time-independent (TI).

The right-hand-side function "rhs" computes the state derivative. 
"rhs" is a function handle with 2 inputs, evaluated as:


rhs(x,a)

Form

x = RK4TI( rhs, x, h, a )


Inputs

rhs        (:)     Right-hand side function handle
x         (N,1)    State (column vector)
h          (1)     Independent variable step
a          (:)     Input provided to rhs function

Outputs

x         (N,1)    Updated state

◆ RMarkov()

function RMarkov ( in  sigma,
in  tCorr,
in  tau 
)

Generates the autocorrelation function for a Markov Process.

Since version 1.

Form

r = RMarkov( sigma, tCorr, tau )


Inputs

sigma        (m)    Square root of mean squared value
tCorr        (m)    Correlation time constant
tau          (n)    Time shifts for which it is to be computed

Outputs

r          (m,n)    Output

◆ RoundN()

function RoundN ( in  x,
in  n 
)

Round to n decimal places.

Since version 1.

Form

z = RoundN( x, n )


Inputs

x                  Argument
n                  Number of decimal places

Outputs

z                  Rouned

◆ RowCompU()

function RowCompU ( in  a,
in  neps 
)

Computes the upper row compression of a matrix.

Compresses the matrix a so that

comp(a) = [ r ]
[ 0 ]

r is of full row rank, i.e. the rows are linearly independent. Zero rows are determined by the singular values.


Form

[r, uh, ac] = RowCompU( a, neps )



Inputs

a                   Matrix
neps                Multiple of machine epsilon to be used
as the tolerance for a zero row

Outputs

r                   Upper row compression of a
uh                  ac = uh*a
ac                  a compressed

References: Maciejowski, J.M., Multivariable Feedback Design, Addison- Wesley, 1989, pp. 366.


◆ SCHarm()

function SCHarm ( in  a,
in  n 
)

Generate a series of sine and cosine harmonics of the arguments.


Form

[s, c] = SCHarm( a, n )


Inputs

a                  column vector (m,1) argument (rad)
n                  number of harmonics

Outputs

s                  vector of sine harmonics
c                  vector of cosine harmonics

◆ SCHarmD()

function SCHarmD ( in  a,
in  n 
)

Generate a series of sine and cosine harmonics of the arguments.


Form

[s, c] = SCHarmD( a, n )


Inputs

a                  Column vector (m,1) argument (deg)
n                  Number of harmonics

Outputs

s                  Vector of sine harmonics
c                  Vector of cosine harmonics

◆ SCSeries()

function SCSeries ( in  t,
in  nSin,
in  nCos,
in  wo,
in  y 
)

Compute a series a + sum(bn sin(n wo t)) + sum(cn cos(n wo t))


Form

x = SCSeries( t, nSin, nCos, wo, y )


Inputs

t                  Points at which data taken
nSin               Number of sine terms
nCos               Number of cosine terms
wo                 Fundamental frequency
y                  Data

Outputs

x                  [constant;sine terms;cosine terms]

◆ Secant()

function Secant ( in  f,
in  x0,
in  x00,
in  tol,
in  nMax,
in  varargin 
)

Finds the solution to f(x) = 0 without derivatives.

If there are multiple roots, x
should be in the vicinity of the desired root. Requires two
initial guesses for the root.


Since version 1.

Form

[x, n] = Secant( f, x0, x00, tol, nMax, varargin )


Inputs

f             (1,:)   String name of f(x),  i.e. 'f'
x0            (1,1)   Initial guess
x00           (1,1)   Guess prior to the initial guess
tol           (1,1)   Tolerance
nMax          (1,1)   Max number of iterations
varargin              Optional arguments

Outputs

x             (1,1)   Result
n             (1,1)   Number of iterations

References: Hornbeck, R., Numerical Methods, Quantum, 1975, pp. 70-71.


◆ SecD()

function SecD ( in  x)

Secant.

Since version 1.

Form

z = SecD( x )


Inputs

x                  Argument (deg)

Outputs

z                  Sec(a)

◆ SegmentIntersection()

function SegmentIntersection ( in  x1,
in  y1,
in  x2,
in  y2,
in  x3,
in  y3,
in  x4,
in  y4 
)

Compute whether and where two 2D line segments intersect.

Since version 2014.1

Form

[int,xi,yi,s,t] = SegmentIntersection( x1, y1, x2, y2, x3, y3, x4, y4 )


Inputs

x1      (1,1)   First x-coordinate of first line segment
y1      (1,1)   First y-coordinate of first line segment
x2      (1,1)   Second x-coordinate of first line segment
y2      (1,1)   Second y-coordinate of first line segment
x3      (1,1)   First x-coordinate of second line segment
y3      (1,1)   First y-coordinate of second line segment
x4      (1,1)   Second x-coordinate of second line segment
y4      (1,1)   Second y-coordinate of second line segment

Outputs

int     (1,1)   Flag to indicate whether the two segments intersect
xi      (1,1)   x-coordinate of intersection
yi      (1,1)   y-coordinate of intersection
s       (1,1)   Percent distance along x to intersection
t       (1,1)   Percent distance along y to intersection

◆ Sep()

function Sep ( in  s,
in  x 
)

Separate a matrix or vector based on the criteria entered in s.

For example [i,j] = Sep('2*fix(x/2) ~= x',x) will place odd numbers
in i and evennumbers in j


Since version 1.

Form

[i, j] = Sep( s, x )


Inputs

Criteria           s
x                  matrix to be separated

Outputs

i                  Indexes of true results
j                  Indexes of false results

◆ SHarm()

function SHarm ( in  a,
in  n 
)

Generate a series of sine harmonics of the arguments.


Form

s = SHarm( a, n )


Inputs

a                  argument (rad)
n                  number of harmonics

Outputs

s                  vector of harmonics

◆ SHarmD()

function SHarmD ( in  a,
in  n 
)

Generate a series of sine harmonics of the arguments.


Form

s = SHarmD( a, n )


Inputs

a                  Column vector (m,1) argument (deg)
n                  Number of harmonics

Outputs

s                  Vector of harmonics

◆ SignTest()

function SignTest ( in  x1,
in  x2 
)

Compare the relative accuracy of two signals.

The demo is for the case
in which there are 7 positive signs out of 10 cases.

Form

[s, nPos] = SignTest( x1, x2 )


Inputs

x1              (1,:)    Sample set 1
x2              (1,:)    Sample set 2

Outputs

s               (1,1)    Confidence that they are identical
nPos            (1,1)    Number of positive signes

◆ Simplex() [1/2]

function Simplex ( in  c,
in  a,
in  b 
)

Uses the simplex method to minimize the cost when solving the problem.

au = b and the cost is cu.

Form

x = Simplex( c, a, b )


Inputs

c             (1,n)    Cost vector
a             (3,n)    Constraint matrix
b             (3,1)    Right-hand-side

Outputs

x             (n,1)    Solution

◆ Simplex() [2/2]

function Simplex ( in  c,
in  a,
in  b,
in  maxValue,
in  maxIter,
in  slack,
in  relax,
in  nhardcon,
in  nsofteq 
)

Uses the simplex method to minimize the cost when solving the problem.

au = b and the cost is cu. Constraints should be stacked in the following order: hard, soft equality, soft inequality.

Type Simplex for a demo.


Form

[u, f, rc] = Simplex( c, a, b, maxValue, maxIter, slack, relax,
nhardcon, nsofteq )


Inputs

c             (1,n) Cost vector
a             (m,n) Constraint matrix
b             (m,1) Right-hand-side
maxValue      (1,1) Maximum constraint on u
maxIter       (1,1) Maximum number of iterations
slack         (1,1) Optional. Set to 1 for a*u <= b    
Set to 0 for a*u  = b    (default)
relax         (1,1) Optional. Set to 1 to relax infeasible constraint
Set to 0 for hard constraints (dflt)
nhardcon      (1,1) Number of hard constraints (used if relax = 1)
nsofteq       (1,1) Number of soft equality constraints (if relax=1)

Outputs

u             (n,1) Solution
f             (1,1) Feasible solution = 1, No feasible solution = 0
rc            (:,l) Vector denoting which constraints were relaxed

◆ Simplex2()

function Simplex2 ( in  a,
in  c,
in  x,
in  s,
in  g,
in  gU,
in  BInv,
in  maxValue,
in  maxIter 
)

Computes the solution to the simplex problem with an optional maximum constraint.


Form

[x,s,g,gU,BInv] = Simplex2(a,c,x,s,g,gU,BInv,maxValue,maxIter)


Inputs

a                      Constraint matrix
c                      Cost vector  
x                      State vector
s                      Index to the constraint matrix
g                      Index to non-basic columns of the constraint matrix 
gU                     Index to non-basic columns of the constraint matrix that are at their upper bound
BInv                   Inverse of basic columns   
maxValue               Maximum constraint on x*
maxIter                Maximum number of iterations*
* optional

Outputs

x                      State vector
s                      Index to the constraint matrix
g                      Index to non-basic columns of the constraint matrix 
gU                     Index to non-basic columns of the constraint matrix that are at their upper bound
BInv                   Inverse of basic columns 
soln                   Flag for solution found within maxIter

◆ SimplexScaling()

function SimplexScaling ( in  a,
in  b,
in  nslack 
)

Simplex slack variable scaling.

Scales the multipliers of the slack variables in the 'a' matrix for numerical stability in the simplex solver. Note: the solution to the scaled simplex problem will produce the correct vector of parameters, but the values of the slack varibles will not be consistent with the original problem. If needed, the slack variables can be recreated with 'anorm'. The matrix 'a' should be constructed such that the slack variables are located at the end of the parameter vector 'x'.


Form

[a_new,anorm,b_new] = SimplexScaling(a,b,nslack)


Inputs

a             (m,n)      Constraint matrix to be sent to Simplex.m
b             (m,1)      Constraint vector to be sent to Simplex.m
nslack        (1,1)      Number of slack variables in used in a

Outputs

a_new         (m,n)      Scaled constraint matrix
anorm         (m,1)      Vector of the norms of each row in 'a'
b_new         (m,1)      Scaled constraint vector

◆ SinD()

function SinD ( in  a)

Sine with input in degrees.

Since version 1.

Form

s = SinD ( a )


Inputs

a                Argument (deg)

Outputs

s                Sine(a)

◆ SinX()

function SinX ( in  x)

Computes the value of the sine function given the argument in degrees.

Since version 1.

Form

s = SinX( x )


Inputs

x            Angle (deg)

Outputs

s            sin(x)

◆ Skew()

function Skew ( in  v)

Converts a vector into a skew symmetric matrix.


Form

s = Skew( v )


Inputs

v                  Vector

Outputs

s                  Skew symmetric matrix

◆ SkewSq()

function SkewSq ( in  v,
in  u 
)

Computes the product of two skew symmetric matrices derive from vectors.

If only one matrix is entered it will compute the square.


Since version 2.

Form

s = SkewSq( v, u )


Input

v               (3,1) Vector
u               (3,1) Vector

Output

s               (3,3) Square of the skew matrix

◆ SkewSymm()

function SkewSymm ( in  v)

Converts a vector into a skew symmetric matrix.

Since version 1.

Form

s = SkewSymm( v )


Inputs

v                  Vector

Outputs

s                  Skew symmetric matrix

◆ SMarkov()

function SMarkov ( in  sigma,
in  tCorr,
in  w 
)

Generates the spectral function for a Markov Process.

Since version 1.

Form

s = SMarkov( sigma, tCorr, w )


Inputs

sigma        (m)    Square root of mean squared value
tCorr        (m)    Correlation time constant
w            (n)    Frequencies (rad)

Outputs

s          (m,n)    Spectral density

◆ SolveLinearSinCos()

function SolveLinearSinCos ( in  a,
in  b,
in  c 
)

Algebraically solve x for equation: a*sin(x) + b*cos(x) + c = 0.

Type SolveLinearSinCos for a demo


Since version 11.

Form

x = SolveLinearSinCos( a, b, c );


Inputs

a         (1,1)   Coefficient on sin(x)
b         (1,1)   Coefficient on cos(x)
c         (1,1)   Linear term

Outputs

x         (1,2)   Solution to:  a*sin(x) + b*cos(x) + c = 0

◆ SphericalGrid()

function SphericalGrid ( in  n)

Generate a grid on a sphere that is evenly spaced.

in right ascension and elevation.

Type SphericalGrid for demo.

Form

[rA, dec, kDec] = SphericalGrid( n )


Inputs

n          (1,1)   Number of right ascensions

Outputs

rA         (1,m)   Right ascension (deg)
dec        (1,m)   Declination  (deg)
kDec       (1,n)   The first element in rA and dec for each
new declination.

◆ SphJacobian()

function SphJacobian ( in  x)

Spherical coordinates Jacobian.

This function is the application to the chain rule to a function U in spherical coordinates U( r, phi, theta ) such that

[dU/dx;dU/dy;dU/dZ] = c*[dU/dr;dU/dphi;dU/dtheta]


Form

c = SphJacobian( x )


Inputs

r            (3,1)   Vector

Outputs

c            (3,3)   Jacobian

◆ SubPoly()

function SubPoly ( in  a,
in  b 
)

Subtract two polynomials so that c = a - b.


Form

c = SubPoly ( a, b )


Inputs

a                   Polynomial
b                   Polynomial

Outputs

c                   Sum of the inputs

◆ SumC()

function SumC ( in  x)

Always sums by column even if x is a single row.

Since version 2.

Form

z = SumC( x )


Inputs

x             (:,:) Vectors

Outputs

z             (1,:) Column sum

◆ SumV()

function SumV ( in  x)

Sum a set of vectors in a 3-by-n matrix.

Since version 1.

Form

z = SumV( x )


Inputs

x             (3,n) Vectors

Outputs

z             (3,1) Row sum

◆ SurfaceAreaEllipsoid()

function SurfaceAreaEllipsoid ( in  a,
in  b,
in  c 
)

Compute the surface area of an ellipsoid.

In the general case this is a numeric solution. This handles special cases when any two or three semi-major axes are equal.

Type SurfaceAreaEllipsoid for a demo. This is nearly a sphere where a = 1 + 2*eps, b = 1 + eps, c = 1 where eps is the machine epsilon which on a MacBook Air is 2.2204e-16.


Form

s = SurfaceAreaEllipsoid( a, b, c )


Inputs

a           (1,1)   Semi-major axis
b           (1,1)   Semi-major axis
c           (1,1)   Semi-major axis

Outputs

s           (1,1)   Surface area

Reference: http://en.wikipedia.org/wiki/Ellipsoid


◆ SXV()

function SXV ( in  s,
in  v 
)

Multiplies a scalar times a vector.

Each column in the vector is multiplied by the corresponding scalar.


Form

z = SXV( s, v )


Inputs

s             (1,:) Scalar
v             (n,:) Vector

Outputs

z             (n,:) Product of the scalar and the vector

See also DupVect.


◆ TanD()

function TanD ( in  a)

Tangent with input in degrees.

Since version 1.

Form

s = TanD( a )


Inputs

a                 Argument (deg)

Outputs

s                 Tangent(a)

◆ TMatrix()

function TMatrix ( in  g)

Compute a transformation matrix from a statespace.

Compute a transformation matrix for the following operation:

x[k+1] = a x[k] + b u[k]
y[k]   = c x[k]

to

x[k+1] = [a11 a21] x[k] + b u[k]
[0   a22]
y[k]   = [c1    0] x[k]

Type TMatrix for a demo.


Form

[g, t] = TMatrix( g )


Inputs

g               (:)    State space system

Outputs

g               (:)    Transformed state space system
t             (:)    Transformation matrix

References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control of Turbofan Engines." MIT 1981.


◆ TransformGridCoordinates()

function TransformGridCoordinates ( in  p,
in  q,
in  n 
)

Transforms between 2D and 1D coordinates.

Assumes at square grid that is n by n.

Form

[k,j] = TransformCoord( p, n    ) 1D to 2D
k     = TransformCoord( p, q, n ) 2D to 1D


Inputs

1D to 2D
p          (1,:) Node
n          (1,:) Number of rows or columns in the grid
2D to 1D
p          (1,:) Row
q          (1,:) Column
n          (1,1) Number of rows or columns in the grid

Outputs

1D to 2D
k          (1,:) Row
j          (1,:) Column
2D to 1D
k          (1,:) Node

◆ TriangleWave()

function TriangleWave ( in  x)

Generates a triangle wave.

0 is the beginning and 2*pi is the end.


Form

y = TriangleWave( x )


Inputs

x   (1,:)   Input

Outputs

y (1,:) Triangle wave

◆ TrigReduction()

function TrigReduction ( in  a,
in  b,
in  c 
)

Solve a*sin(beta) + b*cos(beta) = c.

For a real answer c^2 < a^2 + b^2.


Type TrigReduction for a demo.


Since version 10.

Form

beta = TrigReduction( a, b, c )


Inputs

a                  Coefficient
b                  Coefficient
c                  Right hand side

Outputs

beta               Angle solution (rad)

◆ TwoDSimpsonIntegration()

function TwoDSimpsonIntegration ( in  integrand,
in  a,
in  b,
in  c,
in  d,
in  nX,
in  nY,
in  varargin 
)

Uses 2D Simpson's Rule to integrate an area.

The area is rectangular with boundaries x = a to x = b an dy = c to y = d. The number of divisions is nX in x and nY in y. nX and nY should be odd. If they are even it will add one. The integrand is of the form

integrand(a,b,c,d,varargin)

Type TwoDSimpsonIntegration for a built-in demo for the integral of

y.*sin(x)+x.*cos(y); from pi <= x <= 2pi and 0 <= y <= pi.

rHS is a pointer. The function must be vectorized.


Form

q = TwoDSimpsonIntegration( integrand, a, b, c, d, nX, nY, varargin )


Inputs

integrand   (1,1) Pointer to the integratnd
a           (1,1) Lower x limit
b           (1,1) Upper x limit
c           (1,1) Lower y limit
d           (1,1) Upper y limit
nX          (1,1) Number of divisions in x
nY          (1,1) Number of divisions in y
varargin    {}    Passed to integrand

Outputs

q           (1,1)   Integral

◆ TwosComplementToFloat()

function TwosComplementToFloat ( in  b,
in  bigEndian 
)

Converts a two's complement array to float.

For example:

-27 =  TwosComplementToFloat( [1 1 1 0 0 1 0 1],1 )
28 =  TwosComplementToFloat( [0 0 0 1 1 1 0 0],1 )

Type TwosComplementToFloat for a demo


Form

f = TwosComplementToFloat( b, bigEndian )


Inputs

f                       Binary array
bigEndian               1 == big endian [msb...lsb] else
[lsb...msb]

Outputs

f                       Float

◆ Unit()

function Unit ( in  v)

Unitize vectors by column.

The magnitude is computed internally and available as a second output.


Form

[u,m] = Unit( v )


Inputs

v            (:,n)     Vectors

Outputs

u            (:,n)     Unit vectors
m            (:,1)     Vector magnitudes

◆ UnitVectorAverage()

function UnitVectorAverage ( in  u1,
in  u2 
)

Average unit vector.

Creates a unit vector that lies in the plane created by u1 and u2.
The vector is midway between the vectors.


Type UnitVectorAverage for a demo.


Since version 8.

Form

uA = UnitVectorAverage( u1, u2 )


Inputs

u1                 (3,1) Unit vector
u2                 (3,1) Unit vector

Outputs

uA                 (3,1) Average unit vector

◆ UnwrapPhase()

function UnwrapPhase ( in  theta)

Unwrap a vector of angular values to change continuously.


Form

theta = UnwrapPhase( theta );


Inputs

theta            (1,:) Vector of wrapped angular values [rad]

Outputs

theta            (1,:) Vector of unwrapped angular values [rad]

◆ VerSin()

function VerSin ( in  x,
in  xMax 
)

Produces a smoothly varying function from 0 to xMax.

The minimum value of y is zero and the maximum value is 1.


Since version 2.

Form

y = VerSin( x, xMax )


Inputs

x            (:)       The vector
xMax                   Maximum value

Outputs

y            (:)       Output

◆ WaveletMorlet()

function WaveletMorlet ( in  t,
in  f,
in  w,
in  xEnv 
)

Performs a wavelet transform using a Morlet Wavelet.

Also called a Gabor transform

Type WaveletMorlet for a demo

The demo plots the wavelet analysis of a signal with two components: one with frequency 5 kHz (w1) and one with a frequency that modulates in time around 50 kHz (w2) at frequency 1 kHz (w3).


Form

fConv = WaveletMorlet(t,f,w,xEnv)


Inputs

t               (1,:) Time vector for the signal vector. Units of
seconds. Must be uniformly spaced for the
convolution.
f               (1,:) Signal vector to analyze.
w               (:,1) Angular frequency vector, on which to determine
the wavelet transform value. Units of rad/s.
xEnv            (1,1) Envelope width parameter for the Morlet Wavelet.
Determines tradeoff between frequency and time
resolution. Default: 10

Outputs

fConv           (:,:) Wavelet transform value. Has dimension 1 size of
the w vector and dimension 2 size of the f
vector. Same units as the f vector. Amplitude is
approximately the pkpk value, but Plancherel's
theorem does NOT hold.

◆ WorstFirstAssignment()

function WorstFirstAssignment ( in  mat)

Reorder columns to minimize the diagonal sum with a worst-first policy.


Form

[optOrder,optCost,costVec] = WorstFirstAssignment( mat );


Inputs

mat             (N,N)     Square cost matrix. 
All elements should be >=0 to work properly.

Outputs

optOrder        (1,N)     Optimal order of matrix columns.
optCost          (1)      Total cost = sum of reordered matrix diagonal
costVec         (1,N)     Vector of costs = diagonal of reordered matrix

◆ WrapPhase()

function WrapPhase ( in  angle)

Wrap a phase angle (or vector of angles) to keep it between -pi and +pi.


Form

angle = WrapPhase( angle )


Inputs

angle            (1,:)    Phase angle [rad]

Outputs

angle            (1,:)    Wrapped phase angle between -pi and +pi [rad]