ebook img

MATLAB The Language of Technical Computing (Mathematics) ~ Version 7 PDF

366 Pages·2006·2.26 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 The Language of Technical Computing (Mathematics) ~ Version 7

® MATLAB The Language of Technical Computing Mathematics Version 7 How to Contact The MathWorks: www.mathworks.com Web comp.soft-sys.matlab Newsgroup Contents Matrices and Linear Algebra 1 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Matrices in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Creating Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Adding and Subtracting Matrices . . . . . . . . . . . . . . . . . . . . . . . 1-6 Vector Products and Transpose . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Multiplying Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 The Identity Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10 The Kronecker Tensor Product . . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Vector and Matrix Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11 Solving Linear Systems of Equations . . . . . . . . . . . . . . . . . . 1-13 Computational Considerations . . . . . . . . . . . . . . . . . . . . . . . . . 1-13 General Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 Square Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 Overdetermined Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18 Underdetermined Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20 Inverses and Determinants . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23 Pseudoinverses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24 Cholesky, LU, and QR Factorizations . . . . . . . . . . . . . . . . . . 1-28 Cholesky Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-28 LU Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30 QR Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31 Matrix Powers and Exponentials . . . . . . . . . . . . . . . . . . . . . . 1-35 Eigenvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-39 Singular Value Decomposition . . . . . . . . . . . . . . . . . . . . . . . . 1-43 i Polynomials and Interpolation 2 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Polynomial Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Representing Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Polynomial Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Characteristic Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Polynomial Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Convolution and Deconvolution . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 Polynomial Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 Polynomial Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Partial Fraction Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 Interpolation Function Summary . . . . . . . . . . . . . . . . . . . . . . . . 2-9 One-Dimensional Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Two-Dimensional Interpolation . . . . . . . . . . . . . . . . . . . . . . . . 2-12 Comparing Interpolation Methods . . . . . . . . . . . . . . . . . . . . . . 2-13 Interpolation and Multidimensional Arrays . . . . . . . . . . . . . . 2-15 Triangulation and Interpolation of Scattered Data . . . . . . . . . 2-18 Tessellation and Interpolation of Scattered Data in Higher Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26 Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37 Data Analysis and Statistics 3 Column-Oriented Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Basic Data Analysis Functions . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Covariance and Correlation Coefficients . . . . . . . . . . . . . . . . . 3-10 Finite Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11 Data Preprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13 ii Contents Missing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13 Removing Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Regression and Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 Polynomial Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Linear-in-the-Parameters Regression . . . . . . . . . . . . . . . . . . . . 3-18 Multiple Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 Case Study: Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21 Polynomial Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21 Analyzing Residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 Exponential Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25 Error Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27 The Basic Fitting Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28 Difference Equations and Filtering . . . . . . . . . . . . . . . . . . . . 3-39 Fourier Analysis and the Fast Fourier Transform (FFT) . 3-42 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-42 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43 Magnitude and Phase of Transformed Data . . . . . . . . . . . . . . 3-47 FFT Length Versus Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-49 Function Functions 4 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Representing Functions in MATLAB . . . . . . . . . . . . . . . . . . . . 4-3 Plotting Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . . 4-5 Minimizing Functions and Finding Zeros . . . . . . . . . . . . . . . 4-8 Minimizing Functions of One Variable . . . . . . . . . . . . . . . . . . . . 4-8 Minimizing Functions of Several Variables . . . . . . . . . . . . . . . . 4-9 Fitting a Curve to Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Setting Minimization Options . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 iii Output Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 Finding Zeros of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21 Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25 Numerical Integration (Quadrature) . . . . . . . . . . . . . . . . . . . 4-27 Example: Computing the Length of a Curve . . . . . . . . . . . . . . 4-27 Example: Double Integration . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28 Parameterizing Functions Called by Function Functions 4-30 Providing Parameter Values Using Nested Functions . . . . . . 4-30 Providing Parameter Values to Anonymous Functions . . . . . . 4-31 Differential Equations 5 Initial Value Problems for ODEs and DAEs . . . . . . . . . . . . . . 5-2 ODE Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Introduction to Initial Value ODE Problems . . . . . . . . . . . . . . . 5-5 Solvers for Explicit and Linearly Implicit ODEs . . . . . . . . . . . . 5-7 Examples: Solving Explicit ODE Problems . . . . . . . . . . . . . . . 5-10 Solver for Fully Implicit ODEs . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 Example: Solving a Fully Implicit ODE Problem . . . . . . . . . . 5-16 Changing ODE Integration Properties . . . . . . . . . . . . . . . . . . . 5-17 Examples: Applying the ODE Initial Value Problem Solvers . 5-18 Questions and Answers, and Troubleshooting . . . . . . . . . . . . . 5-37 Initial Value Problems for DDEs . . . . . . . . . . . . . . . . . . . . . . . 5-44 DDE Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-44 Introduction to Initial Value DDE Problems . . . . . . . . . . . . . . 5-45 DDE Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-46 Solving DDE Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-48 Discontinuities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-52 Changing DDE Integration Properties . . . . . . . . . . . . . . . . . . . 5-55 Boundary Value Problems for ODEs . . . . . . . . . . . . . . . . . . . 5-64 BVP Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-65 iv Contents Introduction to Boundary Value ODE Problems . . . . . . . . . . . 5-66 Boundary Value Problem Solver . . . . . . . . . . . . . . . . . . . . . . . . 5-67 Solving BVP Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-71 Using Continuation to Make a Good Initial Guess . . . . . . . . . 5-76 Solving Singular BVPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-84 Changing BVP Integration Properties . . . . . . . . . . . . . . . . . . . 5-88 Partial Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . 5-96 PDE Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-96 Introduction to PDE Problems . . . . . . . . . . . . . . . . . . . . . . . . . 5-97 MATLAB Partial Differential Equation Solver . . . . . . . . . . . . 5-98 Solving PDE Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-102 Changing PDE Integration Properties . . . . . . . . . . . . . . . . . . 5-108 Example: Electrodynamics Problem . . . . . . . . . . . . . . . . . . . . 5-109 Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-115 Sparse Matrices 6 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Sparse Matrix Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 General Storage Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Creating Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Importing Sparse Matrices from Outside MATLAB . . . . . . . . 6-11 Viewing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12 Information About Nonzero Elements . . . . . . . . . . . . . . . . . . . 6-12 Viewing Sparse Matrices Graphically . . . . . . . . . . . . . . . . . . . 6-14 The find Function and Sparse Matrices . . . . . . . . . . . . . . . . . . 6-15 Example: Adjacency Matrices and Graphs . . . . . . . . . . . . . . 6-16 Introduction to Adjacency Matrices . . . . . . . . . . . . . . . . . . . . . 6-16 Graphing Using Adjacency Matrices . . . . . . . . . . . . . . . . . . . . 6-17 The Bucky Ball . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17 v An Airflow Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22 Sparse Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24 Computational Considerations . . . . . . . . . . . . . . . . . . . . . . . . . 6-24 Standard Mathematical Operations . . . . . . . . . . . . . . . . . . . . . 6-24 Permutation and Reordering . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25 Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-29 Simultaneous Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . 6-35 Eigenvalues and Singular Values . . . . . . . . . . . . . . . . . . . . . . . 6-38 Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-40 Nondouble Data Types 7 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Integer Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Integer Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Largest and Smallest Values for Integer Data Types . . . . . . . . 7-5 Integer Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 Example — Digitized Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Warnings for Integer Data Types . . . . . . . . . . . . . . . . . . . . . . . 7-15 Single-Precision Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . 7-17 Data Type single . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-17 Single-Precision Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18 The Function eps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19 Example — Writing M-Files for Different Data Types . . . . . . 7-20 Largest and Smallest Numbers of Type double and single . . . 7-23 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-24 Index vi Contents 1 Matrices and Linear Algebra Function Summary (p. 1-2) Summarizes the MATLAB® linear algebra functions Matrices in MATLAB (p. 1-4) Explains the use of matrices and basic matrix operations in MATLAB Solving Linear Systems of Equations Discusses the solution of simultaneous linear equations (p. 1-13) in MATLAB, including square systems, overdetermined systems, and underdetermined systems Inverses and Determinants (p. 1-23) Explains the use in MATLAB of inverses, determinants, and pseudoinverses in the solution of systems of linear equations Cholesky, LU, and QR Factorizations Discusses the solution in MATLAB of systems of linear (p. 1-28) equations that involve triangular matrices, using Cholesky factorization, Gaussian elimination, and orthogonalization Matrix Powers and Exponentials Explains the use of MATLAB notation to obtain various (p. 1-35) matrix powers and exponentials Eigenvalues (p. 1-39) Explains eigenvalues and describes eigenvalue decomposition in MATLAB Singular Value Decomposition (p. 1-43) Describes singular value decomposition of a rectangular matrix in MATLAB 1 Matrices and Linear Algebra Function Summary The linear algebra functions are located in the MATLAB matfun directory. Function Summary Category Function Description Matrix analysis norm Matrix or vector norm. normest Estimate the matrix 2-norm. rank Matrix rank. det Determinant. trace Sum of diagonal elements. null Null space. orth Orthogonalization. rref Reduced row echelon form. subspace Angle between two subspaces. Linear equations \ and / Linear equation solution. inv Matrix inverse. cond Condition number for inversion. condest 1-norm condition number estimate. chol Cholesky factorization. cholinc Incomplete Cholesky factorization. linsolve Solve a system of linear equations. lu LU factorization. luinc Incomplete LU factorization. 1-2

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.