PSS Math Module
MATLAB toolboxes for aerospace analysis
|
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... | |
The math module functions. View the published Math Demos.
function ACosD | ( | in | x | ) |
function ACot2 | ( | in | x, |
in | y | ||
) |
function ACot2D | ( | in | x, |
in | y | ||
) |
function ACotD | ( | in | x | ) |
function ACscD | ( | in | x | ) |
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.
[sep,minSep,maxSep] = AngleSepFromRotation( axis, u1, u2, phi )
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)
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)
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
[alpha,xnew,m] = Armijo( x, s, beta, sigma, d, f, g )
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
alpha Stepsize xnew New state m Number of iterations
See also: NewtonsMethod.m
function ASecD | ( | in | x | ) |
function ASinD | ( | in | x | ) |
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.
path = AStarSearch( startNode, goalNode, d )
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
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,
function ATan2D | ( | in | x, |
in | y | ||
) |
function ATanD | ( | in | x | ) |
function AutoCorr | ( | in | x, |
in | n | ||
) |
Generates the autocorrelation function for the input sequence.
r = AutoCorr( x, n )
x Input sequence n 1st n samples to be used. If omitted use half.
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.
function BilinearInterpolation | ( | in | x, |
in | y, | ||
in | z, | ||
in | xi, | ||
in | yi | ||
) |
function Binomial | ( | in | y, |
in | n | ||
) |
function BinomialTheorem | ( | in | n, |
in | k, | ||
in | p | ||
) |
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.
[x,n] = BisectionZero( f, x0, xLim, xTol, nmax )
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
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
function BlockDiagonal | ( | in | m0, |
in | n | ||
) |
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.
[d, a, b] = BuildLinearDF( a, b, states, inputs, lambda, dT )
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
d (:) Detection filter .g plant .d gain matrix .t transformation matrix a (n,n) Discrete plant matrix b (n,m) Discrete Input matrix
function CableTensionExample | ( | in | x, |
in | time, | ||
in | t0 | ||
) |
function CFract | ( | in | a, |
in | b, | ||
in | tol | ||
) |
Computes the value of a continued fraction of the form.
b0 - a1
b3
The maximum accuracy depends on the size of a and b. tol is only used for early termination of the series.
x = CFract( a, b, tol )
a a array b b array tol Error tolerance
x value of fraction
References: Battin, R. H., An Introduction to the Mathematics and Methods of Astrodynamics, AIAA, 1987, pp. 67-68.
function CHarm | ( | in | a, |
in | n | ||
) |
function CHarmD | ( | in | a, |
in | n | ||
) |
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.
[c, v, ac] = ColCompR( a, neps )
a Matrix neps Multiple of machine epsilon to be used as the tolerance for a zero column
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.
function Combinations | ( | in | r, |
in | n | ||
) |
function ComplexToReal | ( | in | c | ) |
Convert a matrix from complex to real.
c is assumed to have columns of complex conjugates next to each other.
[r, t] = ComplexToReal( c )
c (n,m) Square complex matrix
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.
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.
c = ConfidenceInterval( x, f, sigma )
x (1,:) Samples f (1,1) Fraction sigma (1,1) Known standard deviation
c (1,1) Confidence
Reference: de Silva, C. W. "Control Sensors and Actuators," Prentice-Hall, 1989, pp. 64-66.
function CosD | ( | in | x | ) |
function CosX | ( | in | x | ) |
function CotD | ( | in | x | ) |
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 )
pDot = CovarianceRHS( t, p, d )
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
pDot (:,1) Covariance matrix derivative
References: Gelb, A. Ed., Applied Optimal Estimation, MIT Press. p.188. Table 6.1-1. Also, pp. 190-191.
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.
a = CRand( c )
c Covariance matrix
a Transformation matrix
function Cross | ( | in | w, |
in | y | ||
) |
function CscD | ( | in | x | ) |
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.
[r, xDF] = DCMotorDetectionFilter( y, v, dT, xDF, alpha, beta, tau )
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
r (2,1) Residuals [theta;omega] xDF (2,1) State estimate [theta;omega]
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.
[c, d] = DCMotorFailures( failure, t, dT, c, d, tFail, pFail )
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
c (5,4) State output matrix d (1,1) Motor structure
function DCMotorParitySpace | ( | in | y, |
in | v, | ||
in | dT, | ||
in | plant, | ||
in | q | ||
) |
Computes the residuals for two DC motors.
Since version 9.
[r, q] = DCMotorParitySpace( y, v, dT, plant, q )
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
r (2,1) Residual q (1,1) Data structure for measurements and inputs .yS (4,1) Measurements .uS (2,1) Inputs
function DelLZ | ( | in | v | ) |
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.
DeltaAngleForNewRADec; deltaAngle = DeltaAngleForNewRADec( v1, rA1, dec1, rA2, dec2 )
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
deltaAngle (1,1) Velocity vector angle change (rad)
function DeltaEig | ( | in | a, |
in | e | ||
) |
function DeltCirc | ( | in | x, |
in | y | ||
) |
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.
[r, x] = DetectionFilter( d, m, u, x, xS )
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
r Residuals x State xS Static state
References: Meserole, J. S., "Detection Filters for Fault-Tolerant
Control of Turbofan Engines." MIT 1981.
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.
d = DetectionFilterBuild( g, lambda )
g (:) State space system lambda (1,1) Inverse time constant
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.
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.
action (1,:) action to be taken modifier (:,:) data corresponding to the action
d Detection filter data structure
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.
[r, xDF, xP] = DetectionFilterSimulation( d, gP, u, failure, xDF, xP )
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
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.
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.
[r, x] = DetectionFilterUnnormalized( d, m, u, x )
d (:) Detection filter .g plant .d gain matrix m Measurements u Inputs x State
r Residuals x State
References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control
of Turbofan Engines." MIT 1981.
function DLyapG | ( | in | a, |
in | q | ||
) |
function Dot | ( | in | w, |
in | y | ||
) |
function DualDCMotors | ( | in | x, |
in | t, | ||
in | d | ||
) |
Simulates two DC motors.
Since version 9.
xDot = DualDCMotors( x, t, d )
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)
xDot (4,1) State vector derivative [theta;omega;theta;omega]
function DUnit | ( | in | r, |
in | v | ||
) |
function DupVect | ( | in | x, |
in | n | ||
) |
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.
[mSV, tCorr] = EMarkov( r, tau )
r (n) Sequence tau (n) Time shifts
mSV (1,1) Mean squared value tCorr (1,1) Correlation time constant
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.
[eAbs, eSRSS, absA] = ErrorCombination( fun, x, e, d )
fun (1,:) y = f(x); x (:,1) Nominal measurement e (:,1) Error on each measurement d (1,1) Data structure to pass to fun
eAbs (1,1) Absolute error eSRSS (1,1) Square root of the sum of the squares absA (:,1) df/dxx
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})
x = Euler( Fun, x, h, t, varargin )
Fun Function Fun(x,{t,...}) x State (column vector) h Independent variable step t Current time varargin Optional arguments
x Updated state
function Factorl | ( | in | n | ) |
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.
k = FindIfInBetween( x, a )
x (1,1) Value a (1,2*n) Even length array
k (1,1) 1 if x is between indices j and j + 1 where j is odd
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.
angles = FindValidAngleRange( axis, u1, u2, minSep );
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.
angles (1,2) Range of valid rotation angles. If empty, the constraint cannot be satisfied for any rotation.
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
[a, err] = FitEllipse( x, y )
x (:,1) x values y (:,1) y values solnMethod (1,1) Solution method. 1=constrained, 2=unconstrained Default is 1, constrained. Calls "eig".
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.
function FitPair | ( | in | x, |
in | y, | ||
in | xF | ||
) |
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.
b = FloatToTwosComplement( f, n, bigEndian )
f Float n Bits per word bigEndian 1 == big endian [msb...lsb] else [lsb...msb]
b Binary array
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.
[x, w, h] = FourierSeries( y, t, n )
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
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
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
u = FracDI(y,alpha,n,h)
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
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
function FTrunc | ( | in | x, |
in | d | ||
) |
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,:)
f = GaussianCPDF( x, mu, sigma, tol )
x (2,:) Limits mu (1,1) Mean sigma (1,1) Standard deviation tol (1,1) Integration tolerance
f (1,:) Value
function GaussianPDF | ( | in | x, |
in | mu, | ||
in | sigma | ||
) |
function GaussianRSG | ( | in | a, |
in | b, | ||
in | N | ||
) |
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.
GenerateGrid; [rA, dec, a, kDec, kR, r, nPL] = GenerateGrid( n, r, stayout, type )
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'
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
function GenSub | ( | in | a, |
in | b | ||
) |
function GJInv | ( | in | a | ) |
function GlobeGrid | ( | in | n | ) |
Generate right ascensions and declinations for a global grid.
Type GlobeGrid for demo.
[rA, dec, kDec] = GlobeGrid( n )
n (1,1) Number of right ascensions
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.
function GridPathCost | ( | in | startLoc, |
in | goalLoc, | ||
in | d | ||
) |
function GridSuccessorNodes | ( | in | node, |
in | parent, | ||
in | d | ||
) |
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.
cost = GridTraverseCost( startNode, nextNode, d )
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
cost (1,:) List of nodes in path
function Heavisde | ( | in | x | ) |
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)
[F, n] = HypgF1( alpha, gamma, x ) [F, n] = HypgF1( alpha, gamma, x, tol ) [F, n] = HypgF1( alpha, gamma, x, tol, nMax )
alpha Argument gamma Argument x Argument tol Tolerance (default 1.e-8); nMax Maximum number of iterations
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.
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;gamma,x)
HypgFr(alpha,0,gamma,x) = HypgF1(alpha,gamma+1,x)
[F, n] = HypgFr( alpha, beta, gamma, x ) [F, n] = HypgFr( alpha, beta, gamma, x, tol ) [F, n] = HypgFr( alpha, beta, gamma, x, tol, nMax )
alpha Argument beta Argument gamma Argument x Argument tol Tolerance nMax Maximum number of iterations
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.
function HypgMr | ( | in | beta, |
in | gamma, | ||
in | x, | ||
in | tol, | ||
in | nMax | ||
) |
Computes the value of the confluent hypergeometric ratio.
M(beta,gamma,x)
[F, n] = HypgMr( beta, gamma, x ) [F, n] = HypgMr( beta, gamma, x,tol ) [F, n] = HypgMr( beta, gamma, x, tol, nMax )
beta Argument gamma Argument x Argument tol Tolerance nMax Maximum number of iterations
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.
function InsideAngleRange | ( | in | theta, |
in | range | ||
) |
function Interp1D | ( | in | y1, |
in | y2, | ||
in | x1, | ||
in | x2, | ||
in | x | ||
) |
function InterpolateCircle | ( | in | x1, |
in | x2, | ||
in | f | ||
) |
function IntersectLineAndCone | ( | in | p, |
in | u, | ||
in | alpha | ||
) |
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.
[y, i] = IntersectLineAndEllipsoid( p, u, e )
p (3,:) Points u (3,:) Unit vectors e (3,1) [a; b; c]
y (3,:) Intersection points i (1,:) 1 = intersected
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.
c = IntExp( a, x, xC, y, yC )
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
c Extrapolated/interpolated values
function IntExpR | ( | in | a, |
in | x, | ||
in | xC | ||
) |
function Inv3x3 | ( | in | a | ) |
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
bInv = InvP( bInvOld, v, k )
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
bInv (n,n) New inverse
function IsSing | ( | in | a | ) |
function IsZero | ( | in | a | ) |
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 [].
[a, fOP] = Jacobian( funFcn, xOP, tOP, varargin )
funFcn 'function name' or handle xOP (n,1) State at the operating point tOP Time varargin Optional arguments
a (n,n) Jacobian matrix of first partials fOP (n,1) f(xOP,tOP) at the operating point
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.
[a, fOP] = JacobianODE( funFcn, tOP, xOP, d )
funFcn (1,:) T'function name' tOP (1,1) Time xOP (n,1) State at the operating point d Optional data structure
a (n,n) Jacobian matrix of first partials fOP (n,1) f(xOP,tOP) at the operating point
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.
jC = JCart2Sp( c )
c (3,1) Cartesian coordinates [x, y, z]
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 ]
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)
jC = JSp2Cart( s )
s (3,1) Spherical coordinates [r,theta,phi]
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 ]
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
[c, err] = LeastSq( e, y, x, w ) [c, err] = LeastSq( e, y, x )
e Array of exponents y Left hand side x Right hand side w Weights
c Coefficients
function LEPDS | ( | in | a, |
in | b | ||
) |
Solves the problem ax = b when a is positive definite symmetric.
Since version 1.
[x, err] = LEPDS( a, b )
a (n,n) Positive definite matrix b (n,1) Right hand side
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.
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.
p = LinearSinCosToQuadCos( a, b, c )
a (1,1) Coefficient on sin(x) b (1,1) Coefficient on cos(x) c (1,1) Linear term
p (1,3) Polynomial coefficients. Quadratic of cos(x)
function LogBaseN | ( | in | n, |
in | x | ||
) |
function Logistic | ( | in | x | ) |
function LSSVD | ( | in | a, |
in | b, | ||
in | tol | ||
) |
Solves ax = b using the singular value decomposition.
Since version 1.
[x, r, cn, rank] = LSSVD( a, b, tol )
a A matrix b Right-hand-side tol Tolerance on the minimum singular value
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.
function LyapG | ( | in | a, |
in | q | ||
) |
function Mag | ( | in | u | ) |
function MakeDistribution | ( | in | x, |
in | f, | ||
in | N | ||
) |
Generate a list of random variables with some specified distribution.
xOuts = MakeDistribution(x,f,N)
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)?
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
function ManeuverCost | ( | in | startNode, |
in | nextNode, | ||
in | d | ||
) |
Finds the cost for going from startNode to nextNode.
cost = ManeuverCost( startNode, nextNode, d )
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
cost (1,:) List of nodes in path
function ManeuverCost3D | ( | in | startNode, |
in | nextNode, | ||
in | d | ||
) |
Finds the cost for going from startNode to nextNode in 3D.
cost = ManeuverCost3D( startNode, nextNode, d )
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
cost (1,1) Cost to traverse the distance
function ManeuverSuccessorNodes | ( | in | node, |
in | parent, | ||
in | d | ||
) |
Finds successor nodes.
successorNodes = ManeuverSuccessorNodes( node, parent, d )
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
successorNodes (1,:) List of nodes in path
function ManeuverSuccessorNodes3D | ( | in | node, |
in | parent, | ||
in | d | ||
) |
Finds successor nodes in 3D.
successorNodes = ManeuverSuccessorNodes3D( node, parent, d )
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
successorNodes (1,:) List of nodes in path
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)
[x, tau] = Markov( sigma, tCorr, n, tSamp )
sigma (:) Square root of mean squared value tCorr (:) Correlation time constant n (1,1) Number of samples tSamp (1,1) Sampling period
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.
function MergeAngleRange | ( | in | range1, |
in | range2 | ||
) |
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.
[x, n] = ModNewt( f, fD, fDD, x, epsilon, nMax, varargin )
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
x Result n Number of iterations
References: Hornbeck, R., Numerical Methods, Quantum, 1975, pp. 69-70.
function NewStats | ( | in | oldS, |
in | oldM, | ||
in | count, | ||
in | x | ||
) |
Calculates the new standard deviation and average.
[s, m] = NewStats( oldS, oldM, count, x )
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
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.
[xopt,nSteps,cpuTime,iterate,objValue] = ... NewtonsMethod(f,grad,hess,x,stopData,stepSizeData); See also: Armijo.m, NLEqSolver.m
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
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
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.
[x, n] = NewtRaph( f, fD, x, epsilon, nMax, varargin )
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
x Result n Number of iterations
References: Hornbeck, R., Numerical Methods, Quantum, 1975, pp. 66-67.
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
[x, err, n] = NLEqSolver( fun, x, opt, d )
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
x (:,1) The solution err (:,1) The errors n (1,1) Number of iterations
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
[x, err, n] = NLEQSolver( fun, x, opt, d )
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
x (:,1) The solution err (:,1) The errors itsTotal (1,1) Number of iterations
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.
yEst = NonlinearEstimator( yEst, yMeas, t, d )
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
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.
function NonlinearSpring | ( | in | x, |
in | t, | ||
in | d | ||
) |
Right-hand-side of a nonlinear spring dynamics model.
Since version 9.
dX = NonlinearSpring( x, t, d )
x (4,1) State t (1,1) Time d (1,1) Input data structure
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.
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.
f = NonlinearSpringFault( x, t, d )
x (2,1) State t (1,1) Time d (1,1) Input data structure
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.
function NormalDistribution | ( | in | x, |
in | mu, | ||
in | sigma | ||
) |
function NormalizeMatrix | ( | in | g, |
in | xRange, | ||
in | yRange, | ||
in | uRange | ||
) |
Normalizes a state space system for use with a detection filter.
Since version 9.
g = NormalizeMatrix( g, xRange, yRange, uRange )
g (:) State space system xRange (:,1) Range of x yRange (:,1) Range of y uRange (:,1) Range of u
g (:) State space system
References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control
of Turbofan Engines." MIT 1981. p. 211.
function Odd | ( | in | x | ) |
function OnlineApproximator | ( | in | y, |
in | theta, | ||
in | d | ||
) |
Implements an online approximator, f( y, theta ).
Uses radial basis functions. Since version 9.
[f, z] = OnlineApproximator( y, theta, d )
y (1,1) State theta (q,1) Parameters d (1,1) Input data structure .sigma (1,1) Standard deviation .c (q,1) Centers
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.
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.
[err, u, x] = OptimalTrajectory( x0, xF, tF, uMax, f, maxIter )
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
err (1,1) Error u (:) Control x (:,:) State
function Orthogonalize | ( | in | m | ) |
function Pade | ( | in | n, |
in | m, | ||
in | T | ||
) |
Create a Padé approximant of exp(sT)
[num, den] = Pade( n, m, T )
n Numerator degree ( 0+ ) m Denominator degree ( 1+ ) T Exponential coefficient
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.
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)
p = PAL ( nMax, mMax, x )
nMax Max value of first index mMax Max value of second index x Argument
p Associated Legendre functions
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
[p, pD] = PDAL( nMax, mMax, x, xD )
nMax Max value of first index mMax Max value of second index x Argument xD Derivative of the argument
p associated Legendre functions pD derivative of the associated Legendre functions
References: Spiegel, M.,R., Mathematical Handbook, McGraw-Hill pp 146-150
function Perpendicular | ( | in | a | ) |
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
[p, dP] = PGauss( nMax, mMax, theta )
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.
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.
t = PointInGridInTriangle( v, n, m )
v (2,3) Vertices of the triangle n (1,1) Rows m (1,1) Columns
t (1,:) Coordinates
Reference: http://www.blackpawn.com/texts/pointinpoly/default.html
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.
r = PointInPolygon( p, v )
p (2,n) Points v (2,m) Vertices of polygon
r (1,n) 1 = yes
Reference: W. Randolf Franklin http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
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.
r = PointInPolygon( p, v )
v (2,3) Vertices of the triangle p (2,:) Points
r (1,:) 1 = yes
Reference: http://www.blackpawn.com/texts/pointinpoly/default.html
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.
p = ProbabilityOfFailure( lambda, t )
lambda (1,1) Failure rate (1/unit time) t (1,:) Time (unit time)
p (1,:) Probability of failure
Reference: Vesely, W, "Fault Tree Analysis with Aerospace Applications," Aug. 2002 p. 85
function Product | ( | in | v | ) |
function R2P5 | ( | in | y | ) |
function RadialBasisFunction | ( | in | y, |
in | c, | ||
in | sigma | ||
) |
Implements a radial basis function for online estimators.
Type RadialBasisFunction for a demo. Since version 9.
f = RadialBasisFunction( y, c, sigma )
y (:,:) Input c (q,1) Center sigma (1,1) Standard deviation
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.
function Ramp | ( | in | t, |
in | t0, | ||
in | v0, | ||
in | vF, | ||
in | vDotMax | ||
) |
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)
[tS, varargout] = Ramps( t, dT, varargin )
t (1,:) Transition times dT (1,1) Time step varargin {:} Any number of input variables
tS (1,p) Times for each step varargout {:} Ramps corresponding to varargin's m (1,:) Mass of tank v (1,:) Volume
function Random | ( | in | seed, |
in | n, | ||
in | m | ||
) |
function RandP | ( | in | lambda, |
in | n, | ||
in | m | ||
) |
function RandPM | ( | in | n, |
in | varargin | ||
) |
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.
q = RandPN( lambda, n, m )
lambda (1,1) Coefficient n (1,1) Rows m (1,1) Columns
q (n,m) Random matrix
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.
x = RK2( Fun, x, h, t, varargin )
Fun Function Fun(x,{t,...}) x State (column vector) h Independent variable step t Current time varargin Optional arguments
x Updated state
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.
x = RK4( Fun, x, h, t, varargin )
Fun Function Fun(x,{t,...}) x State (column vector) h Independent variable step t Current time p1... Optional arguments
x Updated state
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.
[x, hLast] = RK45( Fun, x, h, hMax, hMin, tol, t, varargin )
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
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.
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)
x = RK4TI( rhs, x, h, a )
rhs (:) Right-hand side function handle x (N,1) State (column vector) h (1) Independent variable step a (:) Input provided to rhs function
x (N,1) Updated state
function RMarkov | ( | in | sigma, |
in | tCorr, | ||
in | tau | ||
) |
function RoundN | ( | in | x, |
in | n | ||
) |
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.
[r, uh, ac] = RowCompU( a, neps )
a Matrix neps Multiple of machine epsilon to be used as the tolerance for a zero row
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.
function SCHarm | ( | in | a, |
in | n | ||
) |
function SCHarmD | ( | in | a, |
in | n | ||
) |
function SCSeries | ( | in | t, |
in | nSin, | ||
in | nCos, | ||
in | wo, | ||
in | y | ||
) |
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.
[x, n] = Secant( f, x0, x00, tol, nMax, varargin )
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
x (1,1) Result n (1,1) Number of iterations
References: Hornbeck, R., Numerical Methods, Quantum, 1975, pp. 70-71.
function SecD | ( | in | x | ) |
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
[int,xi,yi,s,t] = SegmentIntersection( x1, y1, x2, y2, x3, y3, x4, y4 )
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
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
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.
[i, j] = Sep( s, x )
Criteria s x matrix to be separated
i Indexes of true results j Indexes of false results
function SHarm | ( | in | a, |
in | n | ||
) |
function SHarmD | ( | in | a, |
in | n | ||
) |
function SignTest | ( | in | x1, |
in | x2 | ||
) |
function Simplex | ( | in | c, |
in | a, | ||
in | b | ||
) |
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.
[u, f, rc] = Simplex( c, a, b, maxValue, maxIter, slack, relax, nhardcon, nsofteq )
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)
u (n,1) Solution f (1,1) Feasible solution = 1, No feasible solution = 0 rc (:,l) Vector denoting which constraints were relaxed
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.
[x,s,g,gU,BInv] = Simplex2(a,c,x,s,g,gU,BInv,maxValue,maxIter)
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
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
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'.
[a_new,anorm,b_new] = SimplexScaling(a,b,nslack)
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
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
function SinD | ( | in | a | ) |
function SinX | ( | in | x | ) |
function Skew | ( | in | v | ) |
function SkewSq | ( | in | v, |
in | u | ||
) |
function SkewSymm | ( | in | v | ) |
function SMarkov | ( | in | sigma, |
in | tCorr, | ||
in | w | ||
) |
function SolveLinearSinCos | ( | in | a, |
in | b, | ||
in | c | ||
) |
function SphericalGrid | ( | in | n | ) |
Generate a grid on a sphere that is evenly spaced.
in right ascension and elevation.
Type SphericalGrid for demo.
[rA, dec, kDec] = SphericalGrid( n )
n (1,1) Number of right ascensions
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.
function SphJacobian | ( | in | x | ) |
function SubPoly | ( | in | a, |
in | b | ||
) |
function SumC | ( | in | x | ) |
function SumV | ( | in | x | ) |
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.
s = SurfaceAreaEllipsoid( a, b, c )
a (1,1) Semi-major axis b (1,1) Semi-major axis c (1,1) Semi-major axis
s (1,1) Surface area
Reference: http://en.wikipedia.org/wiki/Ellipsoid
function SXV | ( | in | s, |
in | v | ||
) |
function TanD | ( | in | a | ) |
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.
[g, t] = TMatrix( g )
g (:) State space system
g (:) Transformed state space system t (:) Transformation matrix
References: Meserole, J. S., "Detection Filters for Fault-Tolerant Control
of Turbofan Engines." MIT 1981.
function TransformGridCoordinates | ( | in | p, |
in | q, | ||
in | n | ||
) |
Transforms between 2D and 1D coordinates.
Assumes at square grid that is n by n.
[k,j] = TransformCoord( p, n ) 1D to 2D k = TransformCoord( p, q, n ) 2D to 1D
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
1D to 2D k (1,:) Row j (1,:) Column 2D to 1D k (1,:) Node
function TriangleWave | ( | in | x | ) |
function TrigReduction | ( | in | a, |
in | b, | ||
in | c | ||
) |
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.
q = TwoDSimpsonIntegration( integrand, a, b, c, d, nX, nY, varargin )
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
q (1,1) Integral
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
f = TwosComplementToFloat( b, bigEndian )
f Binary array bigEndian 1 == big endian [msb...lsb] else [lsb...msb]
f Float
function Unit | ( | in | v | ) |
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.
uA = UnitVectorAverage( u1, u2 )
u1 (3,1) Unit vector u2 (3,1) Unit vector
uA (3,1) Average unit vector
function UnwrapPhase | ( | in | theta | ) |
function VerSin | ( | in | x, |
in | xMax | ||
) |
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).
fConv = WaveletMorlet(t,f,w,xEnv)
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
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.
function WorstFirstAssignment | ( | in | mat | ) |
Reorder columns to minimize the diagonal sum with a worst-first policy.
[optOrder,optCost,costVec] = WorstFirstAssignment( mat );
mat (N,N) Square cost matrix. All elements should be >=0 to work properly.
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