MATLAB – The Language of Technical Computing
اسم المؤلف
Julio Salvador
التاريخ
المشاهدات
463
التقييم
(لا توجد تقييمات)
Loading...
التحميل

MATLAB – TheLanguage of Technical Computing
Julio Salvador
Contents
Development Environment Starting and Quitting MATLAB
1 S
tarting MATLAB 1-3
Starting MATLAB on Windows Platforms 1-3
Starting MATLAB on UNIX Platforms . 1-3
Startup Directory for MATLAB 1-3
Startup Options 1-5
Reducing Startup Time with Toolbox Path Caching 1-10
Quitting MATLAB .1-15 Running a Script
When Quitting MATLAB .1-15 Using the Desktop
2 D
esktop Tools 2-4 Launch
Pad .2-5
Configuring the Desktop 2-7
Opening and Closing Desktop Tools .2-7
Resizing Windows .2-9
Moving Windows .2-10
Using Predefined Desktop Configurations 2-16
Common Desktop Features 2-17
Desktop Toolbar 2-17
Context Menus 2-17
Keyboard Shortcuts and Accelerators . 2-18 Selecting Multiple Items
. 2-19 Using the Clipboard
2-20 Accessing The MathWorks on the Web
. 2-20
Setting Preferences 2-21 General Preferences
for MATLAB 2-23 Running MATLAB Functions
3The Command Windo w 3-2
Opening the Command Window . 3-2
Running Functions and Entering Variables 3-2
Controlling Input and Output 3-4
Running Programs 3-11
Keeping a Session Log .3-12
Preferences for the Command Window .3-13
Command History . 3-17
Viewing Functions in the Command History Window 3-17
Running Functions from the Command History Window .3-18
Copying Functions from the Command History Window 3-19
Getting Help
4 T
ypes of Information 4-3
Using the Help Bro w ser 4-4 Changing the Size of
the Help Browser . 4-5
Using the Help Navigator 4-7 Using the Product
Filter 4-7
Viewing the Contents Listing in the Help Browser . 4-9
Finding Documentation Using the Index 4-11
Searching Documentation . 4-13
Bookmarking Favorite Pages 4-15
Vie w ing Documentation in the Display P ane 4-17
Browsing to Other Pages . 4-18
Bookmarking Pages . 4-18
Revisiting Pages 4-19
Printing Pages . 4-19
Finding Terms in Displayed Pages . 4-19
Copying Information . 4-19
Evaluating a Selection . 4-19
Viewing the Page Source (HTML) . 4-20
Viewing Web Pages . 4-20
Preferences for the Help Bro w ser 4-21
Documentation Location – Specifying the help Directory . 4-22
Product Filter – Limiting the Product Documentation . 4-23
PDF Reader – Specifying Its Location . 4-23
General – Synchronizing the Contents Pane
with the Displayed Page 4-23
Help Fonts Preferences – Specifying Font Name,
Style, and Size . 4-24Printing Documentation 4-26
Printing a Page from the Help Browser 4-26
Printing the PDF Version of Documentation 4-26
Using Help Functions 4-28 Viewing Function
Reference Pages – the doc Function . 4-29 Getting Help in the Command Window – the
help Function . 4-29
Other Methods for Getting Help 4-31
Product-Specific Help Features . 4-31
Running Demos . 4-31
Contacting Technical Support . 4-32
Providing Feedback . 4-32
Getting Version and License Information . 4-32
Accessing Documentation for Other Products . 4-33 Participating in the
Newsgroup for MathWorks Products 4-33 Workspace, Search P ath, and File
Operations
5 M
ATLAB Workspace . 5-3
Workspace Browser 5-3
Viewing and Editing Workspace Variables
Using the Array Editor 5-10
Search Path 5-14
How the Search Path Works .5-14
Viewing and Setting the Search Path .5-15
File Operations 5-20
Current Directory Field .5-20
Current Directory Browser 5-20
Viewing and Making Changes to Directories 5-22
Creating, Renaming, Copying, and
Removing Directories and Files 5-23
Opening, Running, and Viewing the Content of Files .5-26
Finding and Replacing Content Within Files 5-28
Preferences for the Current Directory Browser 5-30
Importing and Exporting Data
6 Im
porting Text Data . 6-4
Using the Import Wizard with Text Data 6-4
Using Import Functions with Text Data 6-9Importing Numeric Text Data .6-11
Importing Delimited ASCII Data Files .6-12
Importing Numeric Data with Text Headers 6-13
Importing Mixed Alphabetic and Numeric Data . 6-14
Exporting ASCII Data . 6-16
Exporting Delimited ASCII Data Files . 6-17
Using the diary Command to Export Data 6-18
Importing Binary Data 6-20
Using the Import Wizard with Binary Data Files . 6-20
Using Import Functions with Binary Data . 6-22
Exporting Binary Data 6-25 Exporting MATLAB
Graphs in AVI Format . 6-27
Working w ith HDF Data . 6-29
Overview of MATLAB HDF Support . 6-30
MATLAB HDF Function Calling Conventions 6-31
Importing HDF Data into the MATLAB Workspace . 6-33
Exporting MATLAB Data in an HDF File 6-41
Including Metadata in an HDF File 6-47
Using the MATLAB HDF Utility API . 6-49
Using Lo w-Level File I/O Functions 6-51
Opening Files 6-52
Reading Binary Data . 6-54
Writing Binary Data . 6-55
Controlling Position in a File . 6-56
Reading Strings Line-By-Line from Text Files . 6-58
Reading Formatted ASCII Data 6-59
Writing Formatted Text Files . 6-61
Closing a File . 6-62
Editing and Debugging M-Files
7 S
tarting the Editor/Debugger 7-3
Creating a New M-File in the Editor/Debugger . 7-4
Opening Existing M-Files in the Editor/Debugger . 7-5
Opening the Editor Without Starting MATLAB .7-6 Closing the Editor/Debugger
.7-6
Creating and Editing M-Files w ith the Editor/Debugger .7-8
Appearance of an M-File .7-8Navigating in an M-File 7-11
Saving M-Files 7-15
Running M-Files from the Editor/Debugger 7-15
Printing an M-File . 7-16
Closing M-Files . 7-16
Debugging M-Files 7-17
Types of Errors 7-17
Finding Errors . 7-17
Debugging Example – The Collatz Problem 7-18
Using Debugging Features 7-22
Preferences for the Editor/Debugger . 7-35
General Preferences for the Editor/Debugger . 7-36
Font & Colors Preferences for the Editor/Debugger 7-37
Display Preferences for the Editor/Debugger 7-38
Keyboard and Indenting Preferences for the Editor/Debugger 7-40
Printing Preferences for the Editor/Debugger . 7-42
Imp roving M-File Performance– the Profiler
8 W
hat Is Profiling? . 8-3
Using the Profiler . 8-4
The profile Function . 8-4
An Example Using the Profiler 8-6
Vie w ing Profiler Results 8-7
Viewing Profile Reports 8-7
Profile Plot 8-12
Saving Profile Reports .8-13
Interfacing with Source Control Systems
9 P
rocess of Interfacing to an SCS . 9-3
Vie w ing or Selecting the Source Control System . 9-4 Function Alternative for
Viewing the SCS . 9-5
Setting Up the Source Control System . 9-6
For SourceSafe Only – Mirroring MATLAB Hierarchy 9-6
For ClearCase on UNIX Only – Set a View and
Check Out a Directory 9-6Checking Files into the Source Control System 9-7 Function Alternative for
Checking In Files 9-8
Checking Files Out of the SCS 9-9
Function Alternative for Checking Out Files 9-10
Undoing the Check-Out .9-10
Using Notebook
10
Notebook Basics . 10-3
Creating an M-Book 10-3
Entering MATLAB Commands in an M-Book .10-6
Protecting the Integrity of Your Workspace 10-6
Ensuring Data Consistency .10-7
Defining MATLAB Commands as Input Cells 10-8 Defining Cell
Groups .10-8 Defining Autoinit Input
Cells 10-10 Defining Calc Zones
10-10 Converting an Input Cell to Text
10-11
Evaluating MATLAB Commands . 10-12 Evaluating Cell
Groups .10-13
Evaluating a Range of Input Cells . 10-14
Evaluating a Calc Zone .10-14
Evaluating an Entire M-Book 10-15
Using a Loop to Evaluate Input Cells Repeatedly 10-15
Converting Output Cells to Text 10-16
Deleting Output Cells 10-17
Printing and Formatting an M-Book . 10-18
Printing an M-Book 10-18
Modifying Styles in the M-Book Template .10-18
Choosing Loose or Compact Format .10-19
Controlling Numeric Output Format .10-20
Controlling Graphic Output .10-20
Configuring Notebook . 10-24
Notebook Command Reference . 10-26
Bring MATLAB to Front Command .10-26
Define Autoinit Cell Command 10-26
Define Calc Zone Command .10-27
Define Input Cell Command 10-27Evaluate Calc Zone Command .10-28
Evaluate Cell Command 10-28
Evaluate Loop Command .10-29
Evaluate M-Book Command 10-30
Group Cells Command 10-30
Hide Cell Markers Command .10-31
Notebook Options Command 10-31
Purge Output Cells Command .10-31
Toggle Graph Output for Cell Command .10-31
Undefine Cells Command 10-32
Ungroup Cells Command .10-32
Mathematics Matrices and Linear Algebra
11
Function Summary 11-3
Matrices in MATLAB 11-5
Creation 11-5
Addition and Subtraction 11-7
Vector Productsand Transpose 11-7
Matrix Multiplication 11-9
The Identity Matrix .11-11
The Kronecker Tensor Product .11-11
Vector and Matrix Norms .11-12
Solving Linear Systems of Equations . 11-13
Overview .11-13
Square Systems .11-15
Overdetermined Systems 11-15
Underdetermined Systems 11-18
Inverses and Determinants . 11-21
Overview .11-21
Pseudoinverses 11-22
Cholesky, LU, and QR Factorizations . 11-25
Cholesky Factorization 11-25
LU Factorization .11-26
QR Factorization .11-28
Matrix P o w ers and Exponentials 11-32
Eigenvalues . 11-35
Singular Value Decomposition . 11-39 P olynomials and
Interpolation12
P olynomials . 12-3
Polynomial Function Summary .12-3
Representing Polynomials .12-4
Polynomial Roots .12-4
Characteristic Polynomials .12-5
Polynomial Evaluation 12-5
Convolution and Deconvolution .12-6
Polynomial Derivatives .12-6
Polynomial Curve Fitting 12-7
Partial Fraction Expansion .12-8
Interpolation 12-10
Interpolation Function Summary .12-10
One-Dimensional Interpolation 12-11
Two-Dimensional Interpolation 12-13
Comparing Interpolation Methods 12-14
Interpolation and Multidimensional Arrays .12-16
Triangulation and Interpolation of Scattered Data .12-19
Tessellation and Interpolation of Scattered Data in
Higher Dimensions 12-27
Selected Bibliography 12-38 Data Analysis and
Statistics
13
Column-Oriented Data Sets 13-4
Basic Data Analysis Functions 13-8 Function Summary
.13-8 Covariance and Correlation
Coefficients .13-11 Finite
Differences 13-12
Data Preprocessing 13-14
Missing Values .13-14
Removing Outliers 13-15
Regression and Curve Fitting . 13-17
Polynomial Regression .13-18
Linear-in-the-Parameters Regression .13-19
Multiple Regression .13-21
Case Study: Curve Fitting 13-22
Polynomial Fit 13-22
Analyzing Residuals .13-24Exponential Fit .13-27
Error Bounds 13-30
The Basic Fitting Interface 13-31
Difference Equations and Filtering . 13-40
Fourier Analysis and the Fast Fourier Transform (FFT) 13-43
Function Summary 13-43
Introduction 13-44
Magnitude and Phase of Transformed Data 13-49
FFT Length Versus Speed 13-50
Function Functions
14
Function Summary 14-3
Representing Functions in MATLAB 14-4
Plotting Mathematical Functions . 14-6
Minimizing Functions and Finding Zeros . 14-9
Minimizing Functions of One Variable .14-9
Minimizing Functions of Several Variables 14-10
Setting Minimization Options .14-11
Finding Zeros of Functions . 14-12
Tips 14-15
Troubleshooting 14-15
Converting Your Optimization Code to
MATLAB Version 5 Syntax 14-16
Numerical Integration (Quadrature) . 14-19
Example: Computing the Length of a Curve 14-19
Example: Double Integration .14-20
Differential Equations
15
Initial Value Problems for ODEs and DAEs 15-3
ODE Function Summary .15-3
Introduction to Initial Value ODE Problems .15-6
Initial Value Problem Solvers .15-6
Representing ODE Problems 15-10
Improving ODE Solver Performance .15-16
Examples: Applying the ODE Initial Value Problem Solvers 15-31
Questions and Answers, and Troubleshooting 15-50Boundary Value Problems for ODEs . 15-57
BVP Function Summary .15-57
Introduction to Boundary Value ODE Problems .15-59
Boundary Value Problem Solver .15-60
Representing BVP Problems .15-63
Using Continuation to Make a Good Initial Guess .15-68
Improving BVP Solver Performance .15-75
P artial Differential Equations . 15-82
PDE Function Summary .15-82
Introduction to PDE Problems 15-83
MATLAB Partial Differential Equation Solver .15-84
Representing PDE Problems .15-88
Improving PDE Solver Performance .15-93
Example: Electrodynamics Problem 15-94
Selected Bibliography . 15-99 Sparse Matrices
16
Function Summary 16-3
Introduction 16-6
Sparse Matrix Storage 16-6
General Storage Information 16-7
Creating Sparse Matrices 16-7
Importing Sparse Matrices from Outside MATLAB .16-12
Vie w ing Sparse Matrices . 16-13
Information About Nonzero Elements 16-13
Viewing Sparse Matrices Graphically .16-15
The find Function and Sparse Matrices 16-16
Example: Adjacency Matrices and Graphs 16-17
Introduction to Adjacency Matrices 16-17
Graphing Using Adjacency Matrices .16-18
The Bucky Ball 16-18
An Airflow Model 16-23
Sparse Matrix Operations . 16-25
Computational Considerations 16-25
Standard Mathematical Operations 16-25
Permutation and Reordering .16-26
Factorization .16-30
Simultaneous Linear Equations 16-36
Eigenvalues and Singular Values .16-39Selected Bibliography 16-42
Programming and Data Types M-File Programming
17
MATLAB Programming: A Quick Start 17-3
Kinds of M-Files 17-3
What’s in an M-File? .17-4
Providing Help for Your Programs 17-4
Creating M-Files: Accessing Text Editors .17-5
Scripts 17-7 Simple Script
Example 17-7
Functions . 17-8
Simple Function Example .17-8
Basic Parts of a Function M-File .17-9
Function Names 17-11
How Functions Work .17-12
Checking the Number of Function Arguments 17-14
Passing Variable Numbers of Arguments .17-16
Local and Global Variables . 17-19
Persistent Variables 17-20
Special Values .17-21
Data Types 17-22
Key w ords . 17-25
Operators . 17-26
Arithmetic Operators 17-26
Relational Operators .17-28
Logical Operators 17-29
Operator Precedence .17-32
Flo w Control 17-35
if, else, and elseif 17-35
switch .17-37
while .17-39
for .17-40
continue 17-41
break 17-41
try . catch .17-42
return .17-42
Subfunctions 17-43
Private Functions 17-45Subscripting and Indexing . 17-46
Subscripting .17-46
Advanced Indexing .17-51
String Evaluation . 17-54
eval .17-54
feval 17-54
Command/Function Duality 17-56
Empty Matrices . 17-57
Operating on an Empty Matrix 17-57
Using Empty Matrices with If or While .17-58
Errors and Warnings . 17-59
Error Handling with eval and lasterr 17-59
Displaying Error and Warning Messages 17-60
Dates and Times 17-62
Date Formats .17-62
Current Date and Time 17-67
Obtaining User Input 17-69
Prompting for Keyboard Input .17-69
Pausing During Execution .17-69
Shell Escape Functions 17-70
Optimizing MATLAB Code . 17-71
Vectorizing Loops .17-71
Preallocating Arrays 17-73
Making Efficient Use of Memory 17-74
Character Arrays (Strings)
18
Character Arrays 18-5
Creating Character Arrays .18-5
Creating Two-Dimensional Character Arrays .18-6
Converting Characters to Numeric Values .18-7
Cell Arrays of Strings 18-8 Converting to a Cell
Array of Strings 18-8
String Comparisons 18-10
Comparing Strings For Equality .18-10
Comparing for Equality Using Operators .18-11Categorizing Characters Within a String .18-12
Searching and Replacing . 18-13
String/Numeric Conversion . 18-15 Array/String
Conversion .18-16 Multidimensional Arrays
19
Multidimensional Arrays . 19-3
Creating Multidimensional Arrays .19-4
Accessing Multidimensional Array Properties 19-8
Indexing 19-9
Reshaping .19-10
Permuting Array Dimensions 19-12
Computing w ith Multidimensional Arrays . 19-14
Operating on Vectors 19-14
Operating Element-by-Element 19-14
Operating on Planes and Matrices .19-15
Organizing Data in Multidimensional Arrays 19-16
Multidimensional Cell Arrays 19-18 Multidimensional
Structure Arrays . 19-19 Applying Functions to Multidimensional
Structure Arrays . 19-20 Structures and Cell Arrays
20
Structures . 20-4
Building Structure Arrays .20-5
Accessing Data in Structure Arrays 20-7
Finding the size of Structure Arrays .20-10
Adding Fields to Structures 20-10
Deleting Fields from Structures 20-10
Applying Functions and Operators .20-10
Writing Functions to Operate on Structures .20-11
Organizing Data in Structure Arrays .20-12
Nesting Structures 20-17
Cell Arrays 20-19
Creating Cell Arrays .20-20
Obtaining Data from Cell Arrays 20-23
Deleting Cells 20-24
Reshaping Cell Arrays .20-25
Replacing Lists of Variables with Cell Arrays 20-25
Applying Functions and Operators .20-27Organizing Data in Cell Arrays . 20-27
Nesting Cell Arrays 20-29
Converting Between Cell and Numeric Arrays 20-30
Cell Arrays of Structures 20-31
Function Handles
21
Benefits of Using Function Handles 21-3 A Simple Function
Handle 21-5
Constructing a Function Handle . 21-7 Maximum Length of a
Function Name .21-7
Evaluating a Function Through Its Handle 21-9 Function Evaluation
and Overloading 21-9 Examples of Function Handle
Evaluation .21-10
Displaying Function Handle Information . 21-13
Fields Returned by the Functions Command 21-14
Types of Function Handles 21-17
Function Handle Operations . 21-21
Converting Function Handles to Function Names 21-21
Converting Function Names to Function Handles 21-22
Testing for Data Type 21-23
Testing for Equality 21-23
Saving and Loading Function Handles . 21-25
Handling Error Conditions 21-26
Handles to Nonexistent Functions 21-26
Including Path In the Function Handle Constructor 21-26
Evaluating a Nonscalar Function Handle .21-27
Historical Note – Evaluating Function Names . 21-28 MATLAB Classes
and Objects
22
Classes and Objects: An Overvie w 22-3
Features of Object-Oriented Programming .22-3
MATLAB Data Class Hierarchy 22-4
Creating Objects 22-4
Invoking Methods on Objects 22-5
Private Methods 22-6
Helper Functions .22-6Debugging Class Methods .22-6
Setting Up Class Directories .22-7
Data Structure 22-8
Tips for C++ and Java Programmers 22-8
Designing User Classes in MATLAB 22-9 The MATLAB
Canonical Class .22-9 The Class Constructor
Method 22-10 Examples of Constructor Methods
22-11 Identifying Objects Outside the Class
Directory .22-11 The display Method .22-
12 Accessing Object Data .22-13 The set and get Methods
.22-13 Indexed Reference Using subsref and
subsasgn 22-14 Handling Subscripted Reference .22-
14 Handling Subscripted Assignment 22-17 Object Indexing Within
Methods 22-17 Defining end Indexing for an Object
.22-18 Indexing an Object with Another
Object .22-19 Converter
Methods 22-20
Overloading Operators and Functions . 22-21
Overloading Operators 22-21
Overloading Functions 22-23
Example – A P olynomial Class . 22-24
Polynom Data Structure .22-24
Polynom Methods 22-24
The Polynom Constructor Method 22-24
Converter Methods for the Polynom Class 22-25
The Polynom display Method . 22-28
The Polynom subsref Method .22-28
Overloading Arithmetic Operators for polynom .22-29
Overloading Functions for the Polynom Class .22-31
Listing Class Methods .22-33
Building on Other Classes 22-35
Simple Inheritance .22-35
Multiple Inheritance 22-36
Aggregation 22-37
Example – Assets and Asset Subclasses 22-38
Inheritance Model for the Asset Class .22-38
Asset Class Design .22-39
Other Asset Methods 22-39
The Asset Constructor Method .22-39
The Asset get Method .22-41
The Asset set Method 22-41The Asset subsref Method 22-42
The Asset subsasgn Method .22-43
The Asset display Method 22-44
The Asset fieldcount Method 22-45
Designing the Stock Class 22-45
The Stock Constructor Method .22-46
The Stock get Method .22-48
The Stock set Method .22-48
The Stock subsref Method .22-49
The Stock subsasgn Method .22-51
The Stock display Method 22-52
Example – The Portfolio Container 22-54
Designing the Portfolio Class .22-54
The Portfolio Constructor Method 22-55
The Portfolio display Method .22-56
The Portfolio pie3 Method 22-57
Creating a Portfolio 22-58
Saving and Loading Objects 22-60 Modifying Objects
During Save or Load .22-60
Example – Defining saveobj and loadobj for P ortfolio . . . 22-61 Summary of Code Changes
.22-61 The saveobj Method
22-62 The loadobj
Method .22-62 Changing the Portfolio Constructor
22-63 The Portfolio subsref
Method 22-64
Object Precedence .22-65 Specifying
Precedence of User-Defined Classes 22-66
Ho w MATLAB Determines Which Method to Call 22-67
Selecting a Method 22-67
Querying Which Method MATLAB Will Call 22-70
External Interfaces and the MATLAB API
A Fi
nding the Documentation in Online Help A-2
Reference Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-4 xxii Contents
1S
tarting and Quitting MATLAB
Starting MATLAB 1-3Starting MATLAB on Windows Platforms 1-3
Starting MATLAB on UNIX Platforms .1-3
Startup Directory for MATLAB 1-3
Startup Options 1-5
Reducing Startup Time with Toolbox Path Caching .1-10
Quitting MATLAB 1-15
Running a Script When Quitting MATLAB 1-15
These sections describe how to start and quit MATLAB, including options associated with
starting and quitting.
• “Starting MATLAB on Windows Platforms” on page 1-3
•“Starting MATLAB on UNIX Platforms” on page 1-3
•“Startup Directory for MATLAB” on page 1-3
•“Startup Options” on page 1-5
•“Reducing Startup Time with Toolbox Path Caching” on page 1-10
•“Quitting MATLAB” on page 1-15
•“Running a Script When Quitting MATLAB” on page 1-15

كلمة سر فك الضغط : books-world.net
The Unzip Password : books-world.net

تحميل

يجب عليك التسجيل في الموقع لكي تتمكن من التحميل

تسجيل | تسجيل الدخول