ebook img

MATLAB® Mathematics - MathWorks PDF

648 Pages·2016·6.42 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview MATLAB® Mathematics - MathWorks

® MATLAB Mathematics R2017a How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 MATLAB® Mathematics © COPYRIGHT 1984–2017 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc. Trademarks MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders. Patents MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information. Revision History June 2004 First printing New for MATLAB 7.0 (Release 14), formerly part of Using MATLAB October 2004 Online only Revised for MATLAB 7.0.1 (Release 14SP1) March 2005 Online only Revised for MATLAB 7.0.4 (Release 14SP2) June 2005 Second printing Minor revision for MATLAB 7.0.4 September 2005 Second printing Revised for MATLAB 7.1 (Release 14SP3) March 2006 Second printing Revised for MATLAB 7.2 (Release 2006a) September 2006 Second printing Revised for MATLAB 7.3 (Release 2006b) September 2007 Online only Revised for MATLAB 7.5 (Release 2007b) March 2008 Online only Revised for MATLAB 7.6 (Release 2008a) October 2008 Online only Revised for MATLAB 7.7 (Release 2008b) March 2009 Online only Revised for MATLAB 7.8 (Release 2009a) September 2009 Online only Revised for MATLAB 7.9 (Release 2009b) March 2010 Online only Revised for MATLAB 7.10 (Release 2010a) September 2010 Online only Revised for MATLAB 7.11 (Release 2010b) April 2011 Online only Revised for MATLAB 7.12 (Release 2011a) September 2011 Online only Revised for MATLAB 7.13 (Release 2011b) March 2012 Online only Revised for MATLAB 7.14 (Release 2012a) September 2012 Online only Revised for MATLAB 8.0 (Release 2012b) March 2013 Online only Revised for MATLAB 8.1 (Release 2013a) September 2013 Online only Revised for MATLAB 8.2 (Release 2013b) March 2014 Online only Revised for MATLAB 8.3 (Release 2014a) October 2014 Online only Revised for MATLAB 8.4 (Release 2014b) March 2015 Online only Revised for MATLAB 8.5 (Release 2015a) September 2015 Online only Revised for MATLAB 8.6 (Release 2015b) October 2015 Online only Rereleased for Version 8.5.1 (Release 2015aSP1) March 2016 Online only Revised for MATLAB 9.0 (Release 2016a) September 2016 Online only Revised for MATLAB 9.1 (Release 2016b) March 2017 Online only Revised for MATLAB 9.2 (Release 2017a) Contents Matrices and Arrays 1 Creating and Concatenating Matrices . . . . . . . . . . . . . . . . . . 1-2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Constructing a Simple Matrix . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Specialized Matrix Functions . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Concatenating Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Matrix Concatenation Functions . . . . . . . . . . . . . . . . . . . . . . 1-7 Generating a Numeric Sequence . . . . . . . . . . . . . . . . . . . . . . 1-9 Matrix Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11 Accessing Single Elements . . . . . . . . . . . . . . . . . . . . . . . . . 1-11 Linear Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12 Functions That Control Indexing Style . . . . . . . . . . . . . . . . 1-12 Assigning to Elements Outside Array Bounds . . . . . . . . . . . 1-13 Accessing Multiple Elements . . . . . . . . . . . . . . . . . . . . . . . . 1-13 Using Logicals in Array Indexing . . . . . . . . . . . . . . . . . . . . 1-16 Single-Colon Indexing with Different Array Types . . . . . . . 1-19 Indexing on Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20 Getting Information About a Matrix . . . . . . . . . . . . . . . . . . . 1-22 Dimensions of the Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22 Classes Used in the Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 1-23 Data Structures Used in the Matrix . . . . . . . . . . . . . . . . . . 1-24 Resizing and Reshaping Matrices . . . . . . . . . . . . . . . . . . . . . 1-25 Expanding the Size of a Matrix . . . . . . . . . . . . . . . . . . . . . . 1-25 Delete Matrix Rows and Columns . . . . . . . . . . . . . . . . . . . . 1-29 Reshaping a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30 Preallocating Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32 Shifting and Sorting Matrices . . . . . . . . . . . . . . . . . . . . . . . . 1-34 Shift and Sort Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34 Shifting the Location of Matrix Elements . . . . . . . . . . . . . . 1-34 v Sorting the Data in Each Column . . . . . . . . . . . . . . . . . . . . 1-35 Sorting the Data in Each Row . . . . . . . . . . . . . . . . . . . . . . . 1-36 Sorting Row Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37 Operating on Diagonal Matrices . . . . . . . . . . . . . . . . . . . . . . 1-39 Diagonal Matrix Functions . . . . . . . . . . . . . . . . . . . . . . . . . 1-39 Constructing a Matrix from a Diagonal Vector . . . . . . . . . . 1-39 Returning a Triangular Portion of a Matrix . . . . . . . . . . . . 1-40 Concatenating Matrices Diagonally . . . . . . . . . . . . . . . . . . . 1-40 Empty Matrices, Scalars, and Vectors . . . . . . . . . . . . . . . . . . 1-41 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41 The Empty Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-42 Scalars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-44 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-45 Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-47 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-47 Creating Multidimensional Arrays . . . . . . . . . . . . . . . . . . . 1-49 Accessing Multidimensional Array Properties . . . . . . . . . . . 1-52 Indexing Multidimensional Arrays . . . . . . . . . . . . . . . . . . . 1-52 Reshaping Multidimensional Arrays . . . . . . . . . . . . . . . . . . 1-56 Permuting Array Dimensions . . . . . . . . . . . . . . . . . . . . . . . 1-58 Computing with Multidimensional Arrays . . . . . . . . . . . . . . 1-60 Organizing Data in Multidimensional Arrays . . . . . . . . . . . 1-62 Multidimensional Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . 1-63 Multidimensional Structure Arrays . . . . . . . . . . . . . . . . . . . 1-64 Summary of Matrix and Array Functions . . . . . . . . . . . . . . 1-66 Linear Algebra 2 Matrices in the MATLAB Environment . . . . . . . . . . . . . . . . . 2-2 Creating Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Adding and Subtracting Matrices . . . . . . . . . . . . . . . . . . . . . 2-3 Vector Products and Transpose . . . . . . . . . . . . . . . . . . . . . . . 2-4 Multiplying Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Identity Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Kronecker Tensor Product . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 vi Contents Vector and Matrix Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 Using Multithreaded Computation with Linear Algebra Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Systems of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Computational Considerations . . . . . . . . . . . . . . . . . . . . . . 2-11 General Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 Square Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13 Overdetermined Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15 Underdetermined Systems . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 Using Multithreaded Computation with Systems of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 Iterative Methods for Solving Systems of Linear Equations . 2-21 Inverses and Determinants . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23 Pseudoinverses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Factorizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27 Cholesky Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27 LU Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28 QR Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30 Using Multithreaded Computation for Factorization . . . . . . 2-33 Powers and Exponentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35 Positive Integer Powers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35 Inverse and Fractional Powers . . . . . . . . . . . . . . . . . . . . . . 2-35 Element-by-Element Powers . . . . . . . . . . . . . . . . . . . . . . . . 2-36 Exponentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36 Eigenvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39 Eigenvalue Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39 Multiple Eigenvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40 Schur Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41 Singular Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43 LAPACK in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-48 vii Random Numbers 3 Random Numbers in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Why Do Random Numbers Repeat After Startup? . . . . . . . . . 3-3 Create Arrays of Random Numbers . . . . . . . . . . . . . . . . . . . . 3-4 Random Numbers Within a Specific Range . . . . . . . . . . . . . . 3-6 Random Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Random Numbers from Normal Distribution with Specific Mean and Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 Random Numbers Within a Sphere . . . . . . . . . . . . . . . . . . . . . 3-9 Generate Random Numbers That Are Repeatable . . . . . . . . 3-11 Specify the Seed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11 Save and Restore the Generator Settings . . . . . . . . . . . . . . 3-12 Generate Random Numbers That Are Different . . . . . . . . . 3-15 Managing the Global Stream . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Random Number Data Types . . . . . . . . . . . . . . . . . . . . . . . 3-21 Creating and Controlling a Random Number Stream . . . . . 3-23 Substreams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24 Choosing a Random Number Generator . . . . . . . . . . . . . . . 3-25 Multiple Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31 Replace Discouraged Syntaxes of rand and randn . . . . . . . 3-34 Description of the Discouraged Syntaxes . . . . . . . . . . . . . . . 3-34 Description of Replacement Syntaxes . . . . . . . . . . . . . . . . . 3-35 Replacement Syntaxes for Initializing the Generator with an Integer Seed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-35 Replacement Syntaxes for Initializing the Generator with a State Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36 If You Are Unable to Upgrade from Discouraged Syntax . . . 3-37 viii Contents Sparse Matrices 4 Computational Advantages of Sparse Matrices . . . . . . . . . . . 4-2 Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Computational Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Constructing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 Creating Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 Importing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8 Accessing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Nonzero Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Indices and Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 Indexing in Sparse Matrix Operations . . . . . . . . . . . . . . . . 4-12 Visualizing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . 4-15 Sparse Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18 Efficiency of Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18 Permutations and Reordering . . . . . . . . . . . . . . . . . . . . . . . 4-19 Factoring Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22 Systems of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . 4-30 Eigenvalues and Singular Values . . . . . . . . . . . . . . . . . . . . 4-33 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35 Graph and Network Algorithms 5 Directed and Undirected Graphs . . . . . . . . . . . . . . . . . . . . . . 5-2 What Is a Graph? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Creating Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4 Graph Node IDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 Modify an Existing Graph . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10 Modify Nodes and Edges of Existing Graph . . . . . . . . . . . . . 5-11 Add Graph Node Names, Edge Weights, and Other Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 ix Graph Plotting and Customization . . . . . . . . . . . . . . . . . . . . 5-20 Visualize Breadth-First and Depth-First Search . . . . . . . . . 5-34 Partition Graph with Laplacian Matrix . . . . . . . . . . . . . . . . 5-38 Add Node Properties to Graph Plot Data Cursor . . . . . . . . 5-43 Functions of One Variable 6 Create and Evaluate Polynomials . . . . . . . . . . . . . . . . . . . . . . 6-2 Roots of Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Numeric Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Roots Using Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Roots in a Specific Interval . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Symbolic Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8 Integrate and Differentiate Polynomials . . . . . . . . . . . . . . . 6-10 Polynomial Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12 Roots of Scalar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14 Solving a Nonlinear Equation in One Variable . . . . . . . . . . 6-14 Using a Starting Interval . . . . . . . . . . . . . . . . . . . . . . . . . . 6-16 Using a Starting Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17 Computational Geometry 7 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Triangulation Representations . . . . . . . . . . . . . . . . . . . . . . . . 7-3 2-D and 3-D Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 Triangulation Matrix Format . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Querying Triangulations Using the triangulation Class . . . . 7-6 x Contents

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.