1. Trang chủ
  2. » Khoa Học Tự Nhiên

Davis MATLAB primer 8th txtbk

233 8 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 233
Dung lượng 0,94 MB

Nội dung

www.elsolucionario.net 4_FM.indd www.elsolucionario.net 7/16/10 12:15:4 4_FM.indd www.elsolucionario.net 7/16/10 12:15:4 4_FM.indd www.elsolucionario.net 7/16/10 12:15:4 4_FM.indd MATLAB® and Simulink® are trademarks of The MathWorks, Inc and are used with permission The MathWorks does not warrant the accuracy of the text or exercises in this book This book’s use or discussion of MATLAB® and Simulink® software or related products does not constitute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the MATLAB® and Simulink® software CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2011 by Taylor and Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S Government works Printed in the United States of America on acid-free paper 10 International Standard Book Number: 978-1-4398-2862-5 (Paperback) This book contains information obtained from authentic and highly regarded sources Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint Except as permitted under U.S Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers For permission to photocopy or use material electronically from this work, please access www.copyright com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400 CCC is a not-for-profit organization that provides licenses and registration for a variety of users For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe Library of Congress Cataloging‑in‑Publication Data Davis, Timothy A MATLAB primer / Timothy A Davis 8th ed p cm Includes index ISBN 978-1-4398-2862-5 (pbk : alk paper) MATLAB Numerical analysis Data processing I Title QA297.D38 2011 518.0285 dc22 2010023858 Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com www.elsolucionario.net and the CRC Press Web site at http://www.crcpress.com 7/16/10 12:15:4 ✐ ✐ “8primer” — 2010/6/7 — 16:45 — page v — #5 ✐ ✐ Contents Preface xiii Introduction xv Getting Started The MATLAB Desktop 2.1 2.2 2.3 2.4 2.5 2.6 2.7 10 12 12 Referencing individual entries Matrix operators Matrix division (slash and backslash) Entry-wise operators Relational operators Complex numbers Strings 13 Submatrices and Colon Notation 4.1 4.2 Command Window Command History window Current Folder window Workspace window Help window File Exchange window Variable Editor window Matrices and Matrix Operations 3.1 3.2 3.3 3.4 3.5 3.6 3.7 19 Generating vectors 19 Accessing submatrices 20 MATLAB Functions 5.1 5.2 5.3 5.4 5.5 5.6 13 14 15 16 16 17 18 22 Constructing matrices Scalar functions Vector functions and data analysis Matrix functions The linsolve function The find function 22 24 25 26 27 28 v www.elsolucionario.net ✐ ✐ ✐ ✐ ✐ ✐ “8primer” — 2010/6/7 — 16:45 — page vi — #6 ✐ ✐ 5.7 5.8 5.9 M-Files 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 The for loop The while loop The if statement The switch statement The try/catch statement Matrix expressions (if and while) Infinite loops Object methods Object inheritance and abstract classes Object attributes A more extensive example Object handle classes Cell arrays Structs Sets Other data types 44 46 47 48 49 50 52 52 Object-Oriented Programming 9.1 9.2 9.3 9.4 9.5 34 36 39 40 41 42 42 43 44 Advanced Data Structures 8.1 8.2 8.3 8.4 34 M-File Editor window Script files Function files Multiple inputs and outputs Variable arguments Unused arguments Comments and documentation The MATLAB path Control Flow Statements 7.1 7.2 7.3 7.4 7.5 7.6 7.7 1-D indexing and the reshape function 29 Logical indexing 30 The bsxfun and repmat functions 31 10 Advanced M-file Features 53 53 55 56 57 59 61 64 66 66 67 vi www.elsolucionario.net ✐ ✐ ✐ ✐ ✐ ✐ “8primer” — 2010/6/7 — 16:45 — page vii — #7 ✐ ✐ 10.1 10.2 10.3 10.4 10.5 10.6 Function handles and anonymous functions Name resolution Error and warning messages User input Performance measures Efficient code 11 Code Development Tools 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 77 Code Analyzer (M-Lint) report Advanced Editor features TODO/FIXME report Help report Contents report Dependency report Profiler tool and Coverage report File and Folder Comparison tool 12 Calling C from MATLAB 12.1 12.2 12.3 12.4 12.5 12.6 67 71 71 72 73 75 77 79 80 81 83 84 85 85 86 A simple example C versus MATLAB arrays A matrix computation in C MATLAB mx and mex routines Online help for MEX routines Larger examples on the web 13 Calling Fortran from MATLAB 87 88 89 93 95 95 95 13.1 Solving a transposed system 96 13.2 A Fortran mexFunction with %val 97 13.3 If you cannot use %val 99 14 Calling Java from MATLAB 14.1 14.2 14.3 14.4 14.5 A simple example Encryption/decryption Java class path Calling your own Java methods Loading a URL as a matrix 100 100 100 102 103 104 vii www.elsolucionario.net ✐ ✐ ✐ ✐ ✐ ✐ “8primer” — 2010/6/7 — 16:45 — page viii — #8 ✐ ✐ 15 Two-Dimensional Graphics 15.1 15.2 15.3 15.4 15.5 15.6 15.7 15.8 15.9 15.10 Planar plots Multiple figures Graph of a function Parametrically defined curves Titles, labels, text in a graph Control of axes and scaling Multiple plots Line types, marker types, colors Subplots and specialized plots Graphics hard copy 106 16 Three-Dimensional Graphics 16.1 16.2 16.3 16.4 16.5 16.6 Curve plots Mesh and surface plots Parametrically defined surfaces Volume and vector visualization Color shading and color profile Perspective of view 106 107 108 108 109 110 110 111 112 112 113 17 Advanced Graphics 113 114 115 116 116 117 118 17.1 Handle Graphics 118 17.2 Graphical user interface 118 17.3 Images 119 18 Sparse Matrix Computations 18.1 18.2 18.3 18.4 18.5 Storage modes Generating sparse matrices Computation with sparse matrices Permutation vectors and matrices Visualizing matrices 120 Symbolic variables Calculus Variable precision arithmetic Numeric and symbolic substitution 19 The Symbolic Math Toolbox 19.1 19.2 19.3 19.4 120 121 123 124 125 125 126 127 132 133 viii www.elsolucionario.net ✐ ✐ ✐ ✐ ✐ ✐ “8primer” — 2010/6/7 — 16:45 — page 201 — #217 ✐ ✐ G G.1 Object-Oriented Programming Classes and Objects class determines the class of a variable See p 184 classdef is a statement that defines a class, with properties and methods The class definition is terminated by an end statement [p 57] exist determines if a class or object exists See p 166 methods is both a function and a keyword The function methods(A) lists the public methods of a class or object A As a keyword, the methods statement defines the set of methods for a class, terminated by an end statement [p 59] properties is both a function and a keyword The function properties(A) lists the public properties of a class or object A As a keyword, the properties statement defines the set of properties for a class, terminated by an end statement [p 58] subsref is the method for subscripted references to objects G.2 Handle Classes delete deletes a handle object findobj finds a graphics object with specific properties get returns the properties of an object See p 205 handle is the superclass for all handle classes, including Handle Graphics [p 66] set lists or sets the properties of an object set(H) lists the properties that can be modified via set(H,’Property’,value) See p 205 201 www.elsolucionario.net ✐ ✐ ✐ ✐ ✐ ✐ “8primer” — 2010/6/7 — 16:45 — page 202 — #218 ✐ ✐ H H.1 Graphics Basic Plots and Graphs box displays or hides the boundary of a plot hold controls how new data is plotted With hold on, a plot command overlays the new plot onto the old one With hold off (the default), a new plot erases the old [p 111] line creates a line object (a low-level version of plot) loglog draws a logarithmic 2-D line plot, with logarithmic x-y axes Otherwise identical to plot plot draws a 2-D line plot plot(Y) plots the columns of a real matrix Y versus the row index With multiple arguments, plot(x,y) plots the vector x versus y plot(x1,y1,x2,y2, ) plots multiple lines on a single figure Adding a string after each pair sets the line color and type [p 106] plot3 draws a 3-D line plot [p 113] semilogx draws a semi-logarithmic 2-D line plot, with a logarithmic x-axis and a linear y-axis Otherwise identical to plot semilogy draws a semi-logarithmic 2-D line plot, with a linear x-axis and a logarithmic y-axis Otherwise identical to plot subplot creates a tiled array of plots in a single figure subplot(2,3,1) creates a 2-by-3 tiling of plots, and sets the first one (in the (1,1) position) as the current plot [p 112] H.2 Plotting Tools rotate3d rotates the 3-D view using the mouse [p 117] zoom zooms into or out of a plot [p 107] 202 www.elsolucionario.net ✐ ✐ ✐ ✐ ✐ ✐ “8primer” — 2010/6/7 — 16:45 — page 203 — #219 ✐ ✐ H.3 Annotating Plots legend adds a legend to a plot If three plot commands have been drawn on a figure, use legend(’s1’,’s2’,’s3’), where each string describes each plot Add ,’Location’, ’SouthEast’ as the last two arguments to place the legend in the bottom right corner (for example) [p 111] rectangle draws a rectangle title sets the title of a plot [p 109] xlabel sets the label for the x-axis [p 109] ylabel sets the label for the y-axis [p 109] zlabel sets the label for the z-axis, for a 3-D plot [p 113] H.4 Specialized Plotting area displays an area plot, which is just like a 2-D line plot except that the area below the curve is filled in with a color bar draws a bar graph Try bar(sin(0:.1:pi)) contour draws a contour plot stem plots a discrete sequence of data hist draws a histogram plot hist(y) uses 10 bins; hist(y,20) uses 20 hist(y,x) uses bins centered at the points in x histc counts the elements in each bin of a histogram (without actually drawing the plot) The bins are defined differently than hist, however histc(y,x) defines the bins by their edges, where y(i) is in the kth bin if x(k)

Ngày đăng: 16/10/2021, 15:40

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN