|
||||||||
Linear AlgebraThis chapter introduces the linear algebra toolbox. This is the most important toolbox in numEclipse. In fact, it implements the core functionality of the application. All other toolboxes depend on this. Some of the functions are implemented as part of the core functions and others are implemented as an extension toolbox. This chapter presents all the functions related to numerical linear algebra regardless of where they are implemented. In the first section, 7.1, we present all the basic functions. In the second section, 7.2, we discus all the specialized matrices. Finally, in section 7.3 we look at the advanced linear algebra functions. 7.1 Basic FunctionsIn this section, we look at all the basic functions used in numerical linear algebra. LengthLength of a vector or matrix is determined using the following function.
n = length(X)
If X is a row or column vector then, it will return the maximum number of elements. If X is a matrix then, it will return the maximum number of columns.
SizeSize of a vector or matrix is determined using the following function.
The first alternative returns row vector where each element contains the size of corresponding dimension. > n = size(rand(3, 5)) ans = 3 5 The second form of the function call returns the size of each dimension of the matrix X to a separate variable listed as output argument. > [m n] = size(rand(3, 5)) m = 3 n = 5 The third form of the function call returns the size of dimension specified in the second argument. > size(rand(3, 5), 1) ans = 3 > size(rand(3, 5), 2) ans = 5
Number of DimensionsNumber of dimensions of a vector or matrix is determined by the following function.
n = ndims(X)
At this point, numEclipse does not implement multi-dimensional arrays. So the above function call will always return the same value of "2".
Identity MatrixThe following function returns the identity matrix.
The first function call returns an identity matrix of size n x n. The second and third function call returns an identity matrix of size m x n.
Ones MatrixThe following function returns a matrix with all 1s.
The first function call returns a matrix of size n x n. The second and third function call returns a 1s matrix of size m x n.
Zeros MatrixThe following function returns a matrix with all 0s.
The first function call returns a matrix of size n x n. The second and third function call returns a 0s matrix of size m x n.
SumThe following function returns the sum of vector or Matrix elements.
If A is a row or column vector then the first function call returns the sum of all elements. If A is a matrix then the first function call returns a row vector such that each row element is a sum of all elements in corresponding column in A. The second function call returns a row vector as previous function call for dim = 1. It returns a column vector containing sum of rows in matrix A, when dim = 2.
ProductThe following function returns the product of vector or Matrix elements.
If A is a row or column vector then the first function call returns the product of all elements. If A is a matrix then the first function call returns a row vector such that each row element is a product of all elements in corresponding column in A. The second function call returns a row vector as previous function call for dim = 1. It returns a column vector containing product of rows in matrix A, when dim = 2.
DiagonalThe following function returns the diagonal matrix.
D = diag(X)
If X is a matrix then the function will return a column vector contain the diagonal elements of matrix X. In case of a vector, it will return a matrix with diagonal elements from X and all other elements will be zero.
TraceThe following function returns the sum of all the diagonal elements of argument matrix X.
s = trace(X)
Note: This method is adopted from GNU Octave.
RepeatThe following function repeats and tile a matrix.
The above function calls create a bigger matrix Y containing m x n copies of input argument matrix X.
ReshapeThe following function changes the rows and columns size of a matrix.
The above function calls reshape the size of input argument matrix X to m x n.
Real partThe following function returns the real part of the input argument matrix.
R = real(X)
Imaginary partThe following function returns the imaginary part of the input argument matrix.
I = imag(X)
ConjugateThe following function determines the complex conjugate of a matrix.
C = conj(X)
All non-zeroThe following function determines if the input argument matrix has all non-zero elements.
If X is a row or column vector then the first function call will return a 1 if all elements are greater than zero otherwise it will return 0. In case of a matrix argument it will return a row vector such that each element of the vector will be 1 if the corresponding column in input matrix is greater than zero otherwise the output vector element be 0. The second function call works similar to the above function when the second argument dim = 1. In case of dim = 2, it will return a column vector such that each element of the vector will be 1 if corresponding row in the input argument matrix X is greater than zero otherwise the output vector element be 0.
Any non-zeroThe following function determines if the input argument matrix has any non-zero elements.
If X is a row or column vector then the first function call will return a 1 if any element is greater than zero otherwise it will return 0. In case of a matrix argument it will return a row vector such that each element of the vector will be 1 if the corresponding column in input matrix has at least one element greater than zero otherwise the output vector element be 0. The second function call works similar to the above function when the second argument dim = 1. In case of dim = 2, it will return a column vector such that each element of the vector will be 1 if corresponding row in the input argument matrix X has at least one element greater than zero otherwise the output vector element be 0.
Test Real MatrixThe following function determines if the input argument matrix is a real matrix.
b = isreal(X)
The function call returns 1 when X is a real matrix otherwise it returns 0.
Number of ElementsThe following function call returns the total number of elements in a matrix.
n = numel(X)
SortThe following function sort vector and matrix.
If X is a vector then the first function call will sort the vector in ascending order. If X is a matrix then the function call will sort each column of the input argument matrix. The second function call works similar to last function call when dim = 1. It will sort along the rows when d = 2.
Flip left-rightThe following function flips columns of the given matrix in the left-right direction.
Y = fliplr(X) Note: Implementation of the function is adopted from GNU Octave.
Flip up-downThe following function flips rows of the given matrix in the up-down direction.
Y = flipud(X)
Note: Implementation of the function is adopted from GNU Octave.
Lower Triangular MatrixThe following function return the lower triangular matrix for a given matrix.
The first function call returns the lower triangular matrix of X, i.e., all the elements for which i < j are zeroed out in the given matrix X. The second function call is similar to the first except that the diagonal is determined using the second argument. The d = 0 corresponds to the main diagonal, d = 1 is first diagonal above the main diagonal and d = -1 is first diagonal below the main diagonal.
Upper Triangular MatrixThe following function return the upper triangular matrix for a given matrix.
The first function call returns the upper triangular matrix of X, i.e., all the elements for which i > j are zeroed out in the given matrix X. The second function call is similar to the first except that the diagonal is determined using the second argument. The d = 0 corresponds to the main diagonal, d = 1 is first diagonal above the main diagonal and d = -1 is first diagonal below the main diagonal.
Above functions are considered basic functions by the author since they are utility functions used to build more complex linear algebra functions. In the next section, we will discuss some specialized matrices.
7.2 Special MatricesHessenberg MatrixThe following function call creates a hessenberg matrix form for the input argument matrix
The first function call finds the hessenberg matrix form H for the input matrix X. The second function call returns the hessenberg matrix form and unitary matrix P such that X = P * H * P'. Note that the hessenberg form for a matrix is not unique.
Note: Implementation of the function is adopted from jampack library.
Hankel MatrixThe following function creates a hankel matrix.
The above function call returns a hankel matrix.
Note: Implementation of the function is adopted from GNU Octave.
Hilbert MatrixThe following function creates a hilbert matrix.
H = hilb(n)
The above function call returns a hilbert matrix of order n × n.
Note: Implementation of the function is adopted from GNU Octave.
Magic MatrixThe following function creates a magic matrix of order n × n.
M = magic(n)
Note: Implementation of the function is adopted from GNU Octave.
Pascal MatrixThe following function creates a pascal matrix.
H = pascal(n)
The above function call returns a pascal matrix of order n × n.
Note: Implementation of the function is adopted from GNU Octave. Toeplitz MatrixThe following function creates a toeplitz matrix.
The above function call returns a toeplitz matrix.
Note: Implementation of the function is adopted from GNU Octave.
Vandermonde MatrixThe following function creates a pascal matrix.
V = vander(x)
The above function call returns a vandermonde matrix.
Note: Implementation of the function is adopted from GNU Octave.
7.3 Advance FunctionsIn this section we look at the numerical linear algebra functions.
Cholesky FactorizationThe following function determines the cholesky factor matrix of the input argument matrix.
C = chol(X)
The input argument matrix must be positive definite matrix, otherwise an error message is returned. The returned matrix is upper triangular matrix such that C' * C = X.
Note: Implementation of this function is adopted from jampack library.
Condition NumberThe following function determines the 2-norm condition number of the input argument matrix.
C = cond(X)
Note: Implementation of the function is adopted from GNU Octave.
DeterminantThe following function determines the determinant of given matrix.
d = det(X)
Note: Implementation of the function is adopted from GNU Octave.
DifferencesThe following function determines the difference matrix for a given input argument matrix.
The first function call calculates the first order differences between adjacent matrix elements. The second function call calculates the n-th order differences between adjacent matrix elements. The third function call calculates the n-th order differences between adjacent matrix elements along matrix dimension dim.
Note: Implementation of the function is adopted from GNU Octave.
Eigen ValuesThe following function determines the eigen values and eigen vectors of a given matrix.
The first function call returns a column vector containing the eigen values of matrix X. The second function call returns a matrix U containing columns of eigen vectors and matrix D a diagonal matrix with eigen values.
Note: Implementation of the function is adopted from jampack library.
FunctionsThe following functions determine the exp, log and sqrt of the given matrix respectively.
Note: Implementation of the function is adopted from GNU Octave.
InverseThe following function determines the inverse of a matrix.
Y = inv(X)
Note: Implementation of the function is adopted from jampack library.
LU DecompositionThe following function determines the LU-decomposition of a given matrix.
The above function calls decompose the given matrix X into lower, upper and permutation matrix such that P' * L * U = X.
Note: Implementation of the function is adopted from jampack library.
NormThe following function determines the norm of a vector or matrix.
The first function call returns the 2-norm whereas the second function call returns d-norm. Here d could be 1, 2, or inf.
QR DecompositionThe following function determines the QR-decomposition of a given matrix.
The above function calls decompose the given matrix X into an orthonormal and upper triangular matrix such that Q * R = X.
Note: Implementation of the function is adopted from jampack library.
RankThe following function determines the rank of a matrix.
In the second function call argument tol is used to specify the tolerance to number of singular values.
Note: Implementation of the function is adopted from GNU Octave.
Reduced Echelon FormThe following function determines the reduced row echelon form of a given matrix
In the second function call argument tol is used to specify the tolerance.
Note: Implementation of the function is adopted from GNU Octave.
Schur DecompositionThe following function determines the schur form of a given matrix.
The above function calls decompose the given matrix X such that U * T * U' = X.
Note: Implementation of the function is adopted from jampack library.
SVD DecompositionThe following function determines the singular value decomposition of a given matrix.
The above function calls decompose the given matrix X such that U * S * V' = X.
Note: Implementation of the function is adopted from jampack library.
|