Using MATLAB (779505), страница 40
Текст из файла (страница 40)
It also describes the solution of initial-boundary valueproblems for systems of parabolic and elliptic partial differential equations(PDEs). Topics covered include representing problems in MATLAB, solversyntax, and using integration parameters.• Sparse Matrices — describes how to create sparse matrices in MATLAB, andhow to use them in both specialized and general mathematical operations.11Matrices and LinearAlgebraFunction Summary . . . . . . .
. . . . . . . . . . 11-3Matrices in MATLAB . . .Creation . . . . . . . . .Addition and Subtraction . .Vector Productsand TransposeMatrix Multiplication . . . .The Identity Matrix . . . .The Kronecker Tensor ProductVector and Matrix Norms . .................................Solving Linear Systems of EquationsOverview . .
. . . . . . . . . . .Square Systems . . . . . . . . . .Overdetermined Systems . . . . . .Underdetermined Systems . . . . . .................................................................. 11-5. 11-5. 11-7. 11-7. 11-911-1111-1111-12........................................11-1311-1311-1511-1511-18Inverses and Determinants . . . . .
. . . . . . . 11-21Overview . . . . . . . . . . . . . . . . . . . . . 11-21Pseudoinverses . . . . . . . . . . . . . . . . . . 11-22Cholesky, LU, and QR Factorizations .Cholesky Factorization . . . . . . . .LU Factorization . . . . . . . . . . .QR Factorization . . . . . .
. . . . .Matrix Powers and Exponentials............................11-2511-2511-2611-28. . . . . . . . . 11-32Eigenvalues . . . . . . . . . . . . . . . . . . . 11-35Singular Value Decomposition . . . . . . . . . . . 11-3911Matrices and Linear AlgebraMATLAB supports many matrix operations that are commonly used in linearalgebra, including matrix arithmetic, linear equations, eigenvalues, singularvalues, and matrix factorizations. MATLAB enables you to work with entirematrices quickly and easily.This chapter describes basic matrix operations in MATLAB and explains theiruse in solving problems. It includes:Function SummarySummarizes the MATLAB linear algebra functionsMatrices in MATLABExplains the use of matrices and basic matrix operations in MATLABSolving Linear Systems of EquationsDiscusses the solution of simultaneous linear equations in MATLAB, includingsquare systems, overdetermined systems, and underdetermined systemsInverses and DeterminantsExplains the use in MATLAB of inverses, determinants, and pseudoinverses inthe solution of systems of linear equationsCholesky, LU, and QR FactorizationsDiscusses the solution in MATLAB of systems of linear equations that involvetriangular matrices, using Cholesky factorization, Gaussian elimination, andorthogonalizationMatrix Powers and ExponentialsExplains the use of MATLAB notation to obtain various matrix powers andexponentialsEigenvaluesExplains eigenvalues and describes eigenvalue decomposition in MATLABSingular Value DecompositionDescribes singular value decomposition of a rectangular matrix in MATLAB11-2Function SummaryFunction SummaryThe linear algebra functions are located in the MATLAB matfun directory.Function SummaryCategoryFunctionDescriptionMatrix analysisnormMatrix or vector norm.normestEstimate the matrix 2-norm.rankMatrix rank.detDeterminant.traceSum of diagonal elements.nullNull space.orthOrthogonalization.rrefReduced row echelon form.subspaceAngle between two subspaces.\ and /Linear equation solution.invMatrix inverse.condCondition number for inversion.condest1-norm condition number estimate.cholCholesky factorization.cholincIncomplete Cholesky factorization.luLU factorization.luincIncomplete LU factorization.qrOrthogonal-triangular decomposition.lsqnonnegNonnegative least-squares.Linear equations11-311Matrices and Linear AlgebraFunction Summary (Continued)CategoryEigenvalues andsingular valuesMatrix functions11-4FunctionDescriptionpinvPseudoinverse.lscovLeast squares with known covariance.eigEigenvalues and eigenvectors.svdSingular value decomposition.eigsA few eigenvalues.svdsA few singular values.polyCharacteristic polynomial.polyeigPolynomial eigenvalue problem.condeigCondition number for eigenvalues.hessHessenberg form.qzQZ factorization.schurSchur decomposition.expmMatrix exponential.logmMatrix logarithm.sqrtmMatrix square root.funmEvaluate general matrix function.Matrices in MATLABMatrices in MATLABA matrix is a two-dimensional array of real or complex numbers.
Linearalgebra defines many matrix operations that are directly supported byMATLAB. Linear algebra includes matrix arithmetic, linear equations,eigenvalues, singular values, and matrix factorizations.This section describes these matrix operations:• Creation• Addition and subtraction• Vector products• Matrix multiplicationIt also describes the MATLAB functions you use to produce:• An identity matrix• The Knonecker Tensor product of two matrices• Vector and matrix normsCreationInformally, the terms matrix and array are often used interchangeably.
Moreprecisely, a matrix is a two-dimensional rectangular array of real or complexnumbers that represents a linear transformation. The linear algebraicoperations defined on matrices have found applications in a wide variety oftechnical fields. (The optional Symbolic Math Toolbox extends MATLAB’scapabilities to operations on various types of nonnumeric matrices.)MATLAB has dozens of functions that create different kinds of matrices. Twoof them can be used to create a pair of 3-by-3 example matrices for usethroughout this chapter.
The first example is symmetric.A = pascal(3)A =111123136The second example is not symmetric.11-511Matrices and Linear AlgebraB = magic(3)B =834159672Another example is a 3-by-2 rectangular matrix of random integers.C = fix(10*rand(3,2))C =926487A column vector is an m-by-1 matrix, a row vector is a 1-by-n matrix and ascalar is a 1-by-1 matrix. The statementsu = [3; 1; 4]v = [2 0 -1]s = 7produce a column vector, a row vector, and a scalar.u =314v =2s =711-60-1Matrices in MATLABAddition and SubtractionAddition and subtraction of matrices is defined just as it is for arrays,element-by-element.
Adding A to B and then subtracting A from the resultrecovers B.X = A + BX =94527127108159672Y = X -AY =834Addition and subtraction require both matrices to have the same dimension, orone of them be a scalar. If the dimensions are incompatible, an error results.X = A + CError using ==> +Matrix dimensions must agree.w = v + sw =976Vector Productsand TransposeA row vector and a column vector of the same length can be multiplied in eitherorder. The result is either a scalar, the inner product, or a matrix, the outerproduct.x = v*ux =211-711Matrices and Linear AlgebraX = u*vX =628000-3-1-4For real matrices, the transpose operation interchanges a ij and a ji . MATLABuses the apostrophe (or single quote) to denote transpose.
Our example matrixA is symmetric, so A' is equal to A. But B is not symmetric.X = B'X =816357492Transposition turns a row vector into a column vector.x = v'x =20-1If x and y are both real column vectors, the product x*y is not defined, but thetwo productsx'*yandy'*xare the same scalar. This quantity is used so frequently, it has three differentnames: inner product, scalar product, or dot product.For a complex vector or matrix, z, the quantity z' denotes the complexconjugate transpose, where the sign of the complex part of each element isreversed. The unconjugated complex transpose, where the complex part of eachelement retains its sign, is denoted by z.'.
So if11-8Matrices in MATLABz = [1+2i 3+4i]then z' is1-2i3-4iwhile z.' is1+2i3+4iFor complex vectors, the two scalar products x'*y and y'*x are complexconjugates of each other and the scalar product x'*x of a complex vector withitself is real.Matrix MultiplicationMultiplication of matrices is defined in a way that reflects composition of theunderlying linear transformations and allows compact representation ofsystems of simultaneous linear equations. The matrix product C = AB isdefined when the column dimension of A is equal to the row dimension of B, orwhen one of them is a scalar.
If A is m-by-p and B is p-by-n, their product C ism-by-n. The product can actually be defined using MATLAB for loops, colonnotation, and vector dot products.for i = 1:mfor j = 1:nC(i,j) = A(i,:)*B(:,j);endendMATLAB uses a single asterisk to denote matrix multiplication. The next twoexamples illustrate the fact that matrix multiplication is not commutative; ABis usually not equal to BA.X = A*BX =15264115387015263911-911Matrices and Linear AlgebraY = B*AY =151515283428476043A matrix can be multiplied on the right by a column vector and on the left by arow vector.x = A*ux =81730y = v*By =12-710Rectangular matrix multiplications must satisfy the dimension compatibilityconditions.X = A*CX =173151194170Y = C*AError using ==> *Inner matrix dimensions must agree.Anything can be multiplied by a scalar.w = s*v11-10Matrices in MATLABw =140-7The Identity MatrixGenerally accepted mathematical notation uses the capital letter I to denoteidentity matrices, matrices of various sizes with ones on the main diagonal andzeros elsewhere.
These matrices have the property that AI = A and IA = Awhenever the dimensions are compatible. The original version of MATLABcould not use I for this purpose because it did not distinguish between upperand lowercase letters and i already served double duty as a subscript and asthe complex unit. So an English language pun was introduced. The functioneye(m,n)returns an m-by-n rectangular identity matrix and eye(n) returns an n-by-nsquare identity matrix.The Kronecker Tensor ProductThe Kronecker product, kron(X,Y), of two matrices is the larger matrix formedfrom all possible products of the elements of X with those of Y. If X is m-by-nand Y is p-by-q, then kron(X,Y) is mp-by-nq.















