Introduction to matlab 7 for engineers

348 577 2
Introduction to matlab 7 for engineers

Đ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

Introduction to matlab 7 for engineers

B ASIC E NGINEERING ';ERIES AND OOLS INTRODUCTION TO ~ATLAB 7 FOR ENGINEERS WILLIAM J. PALM III Rip By Computer Killer Numbered Examples: Chapters One to Five Number and Topic Chapter One 1.1 - 1 Volume of a circular cylinder 1.6-1 Analysis of temperature data 1.6-2 Plotting with a for loop 1.6-3 SeIies calculation with a for loop 1.6-4 Series calculation with a while loop 1.6-5 Growth of a bank account 1.7-1 Piston motion Chapter Two 2.3-1 Vectors and relative velocity 2.3-2 2.3-3 2.3-4 2.3-5 2.3-6 Vectors and displacement Aortic pressure model Transportation route analysis Current and power dissipation in resistors A batch distillation process 2.3-7 Height versus velocity 2.4-1 Manufacturing cost analysis 2.4-2 Product co t analysis 2.5-1 Earthquake-resistant building design 2.6-1 An environmental database 2.7-1 A student database Chapter Three 3.2-1 Using global variables 3.2-2 Optimization of an irrigation channel Number and Topic Chapter Four 4.3-1 Height and speed of a projectile 4.5-1 Data sorting 4.5-2 Flight of an instrumented rocket 4.5-3 Time to reach a specified height 4.6-1 Using the swi tch structure for calendar calculations 4.8-1 A college enrollment model: Part I 4.8-2 A college enrollment model: Part II Chapter Five 5.2-1 5.3-1 5.3-2 5.5-1 5.5-2 5.5-3 5.6-1 5.6-2 5.6-3 5.6-4 Load-line analysis of electrical circuits Frequency-response plot of a low-pass filter Plotting orbits A cantilever beam deflection model Temperatme dynamics Hydraulic resistance Estimation of traffic flow Modeling bacteria growth Breaking strength and alloy composition Response of a biomedical instrument Numbered Examples: Chapters Six to Ten Number and Topic Chapter Six 6.1-1 Gauss elimination 6.2-1 Left-division method with three unknowns 6.2-2 An electrical-resistan ce network 6.2-3 Ethanol production 6.2-4 Calculation of cable ten ion 6.2-5 The matrix inverse method 6.4- 1 A set having a unique solution 6.4-2 An und er determined set 6.4- 3 A statically indeterminate problem 6.4-4 A singular , et 6. 4-5 Production planning 6.4-6 Traffic engineering 6.5- 1 The least squares method 6.5-2 An overdetermined set Chapter Seven 7.1- 1 Breaking strength of thread 7.2-1 Mean and standard deviation of heights 7.2- 2 Estimation of height distribution 7.3- 1 Optimal production quantity 7.3- 2 Statistical analysi and manufacturing tolerances 7. 4-1 Robot path control using three knot points Number and Topic Chapter Eight 8.2-1 Velocity from an accelerometer 8.2-2 Evaluation o[ Fre 'nel's cosine integral 8.5-1 Response of an RC circuit 8.5-2 Decayin g s in e voltage applied to an RCcircuit 8.5-3 Liquid height in a spherical tank 8.6-1 A nonlinear pendulum model 8.6-2 Trapezoidal profile for a dc motor Chapter Nine 9.2-1 9. 2-2 9. 2-3 9. 3-1 9. 4-1 Simulink solution of 5' = 10 s in 1 Exporting to the MATLAB work~pace SiJl1ulink model [or y = -lOy + fU) Simulink model of a tWO-Jl1a~s system SiJl1ulink model of a rocket-propelled sled 9.4-2 Model of a relay-controlled motor 9.5-1 Re!>ponse with a dead zone 9.6-1 Model of a nonlinear pendulum Chapter Ten 10.2-1 10. 2-2 10.3-1 Intersection of two circles Positioning a robot arm Topping the Green Monster · EST (Best Engineering Series and McGraw-Hili Continues to Brmg You the B Engineering Education Tool s) Approach to Introductory ;!'~1~~1:/95 ror Scientists and Engineers, 2/e ISB 0072922389 Donaldson The Engineering Student Survival Guide. 3/e ISB 0073019259 EidelJenisonINorthup Imroduction to Engineering Design a nd Problem Solving,2/e ISBN 0072402210 Eisenberg . . A Beoinner Guide to Technical CommUJ1\CalIOn ISBN" 0070920451 Finklestein Pocket Book or Technical Writing for Engineer a nd Scientists. 2e ISBN 0072976837 Gottfried Spreadsheet Tools for Engineer LI in g Excel ISB N 0072480688 Palm Introduction to MATLAB 7 for Engineers ISBN 0072922427 Pritchard . Mathcad: A Tool for Engineering Problem SolvlOg ISBN 0070121893 Schinzinger/Martin Introduction to Engineerin g Et hi cs [SBN 0072339594 Smith Teamwork and Project Manageme nt , 2/e ISBN 0072922303 TanID' Orazio C Programming for Engineering and Computer Science ISBN 0079 J 36788 Additional Titles of Interest Andersen Just Enough Unix. 4/ e ISBN 0072463775 Eide/JenisonIMashaw/Northup Engineering Fundame nt al and Problem Solving, 4/e ISB 0072430273 Hoi tza pple/Reece Founda ti On> of En gi neering. 2/e ISBN 0072480823 Holtzapple/Reece Concepts in Engineering ISBN 0073011770 MartinlSchinzinger Etilics in Engineering, 4/e ISBN 0072831 154 Introduction to MATLAB 7 for Engineers WiUiam J. Palm III Un iversity of Rhode Island ffI Higher Education B oston Burr Ri dge , IL Dubuque, IA Madison , WI New Yor k San Francisco S t. Louis Ba ngkok Bogot a Caracas Kuala Lumpur Lisbon Lo nd on Madrid Mexico City Mil an Montreal New Delhi Santiago Seoul Singapore Sydney Taipei Toronto ABOUT THE AUTHOR William J. Palm 11/ is Professor of M ec hanical Engineering a nd Applied Mecha nic s at the University of Rhode Isl and. In 1966 he rece iv ed a B.S. from Loyola CoJIe ge in Baltimore, and in 197 I a Ph .D. in Mechanical En g in ee rin g a nd Astronautical Sciences from Northweste rn University in Evanston, Illinoi s. During hi s 33 years as a f ac ulty memb er, he h as taug ht 19 courses. On e of the se is a fre hman MATLAB course, which he helped develop. He ha s authored eight te xtbooks d eaJ in g with modeling and simulation, system dynamic s, control sys tem s, and MATLAB. These include System Dynamics (McGraw-Hill, 2005). He wrote a chapter on control sys tem s in the Mechanical Engineers' Handbook (M. Kutz, ed., Wiley , 1999), and was a special contributor to the fifth editions of Statics and Dynami cs, both by J. L. Meriam and L. G. Kraige (Wi ley, 2002). Professor Palm 's research and indu trial experience are in control systems, robotic s, vibrations, and sys tem modelin g. He was the Director of the Robotics Research Center at the University of Rhode Island from 1985 to 1993, and is the coholder of a patent fo r a robot hand. He served as Acting Department Chair from 2002 to 2003 . Hi s industrial experience is in a utom ated manufacturing; modeling and simulation of naval sys tems , including underwater vehicles and tracking systems; and design of control systems for underwater-vehicle engine- test facilitie s. CONTENTS Preface ix CHAPTER 1 An Overview of MATLAB 1.1 MATLAB Interactive Sessions 1.2 Menus a nd the Toolbar 17 1.3 Computing with MATLAB J 9 1.4 Script Files a nd the Editor/Debugger 29 1.5 The MATLAB Help System 38 1.6 Programming in MATLAB 43 1.7 Problem-Solving Methodologies 52 1.8 Summru·y 60 Problems 61 CHAPTER 2 Numeric, Cell, and Structure Arrays 69 2.1 Arrays 70 2.2 Multidimensional Arrays 81 2.3 Element-by-Element Operations 83 2.4 Matrix Operations 97 2.5 Polynomial Operations Using Arrays 107 2.6 Cell Arrays 112 2.7 Structure Arrays 117 2.8 Summary 123 Problems 125 CHAPTER3 Functions and Files 141 3.1 Elementary Mathematical Functions 141 3.2 User-Defined Functions 148 3.3 Advanced Function Programming 163 3.4 Working with Data Files 172 3.5 Summary 177 Problems J 78 CHAPTER4 Programming with MATLAB 183 4.1 Program De sign and Development 184 4.2 Relational Operators and Logical Variables 191 4.3 Logical Operators and Functions 194 4.4 Conditional Statements 201 4.5 Loops 210 4.6 The swi tch Structure 225 4.7 Debugging MATLAB Programs 228 4.8 Applications to Simulation 234 4.9 Summary 239 Problems 241 CHAPTER 5 Advanced Plotting and Model Building 259 5.1 xy Plotting Functions 260 5.2 Subplots and Overlay Plots 271 5.3 Special Plot Type!> 282 5.4 Interactive Plotting in MATLAB 5.5 Function Discovery 298 5.6 Regression 312 5.7 The Basic Fitting Interface 331 5.8 Three-Dimensional Plots 334 5.9 Summary 339 Problems 340 CHAPTER 6 Linear Algebraic Equations 359 6.1 Elementary Solution Method 361 292 6.2 Matrix Methods for Linear Equation 365 viii Contents 6.3 Cramer's Me th od 377 6.4 U nd e rd etermined S ys tems 6.5 Overdetenllined S ys tems 6.6 Summary 398 Problems 403 C HAPTER7 Probability, Statistics, and Interpolation 417 38 0 394 9.4 Pi ecewise-Linear Models 550 9.5 Transfer-Func ti on Models 557 9.6 Nonlinear State-Variable Models 56 1 9.7 Subsystems 563 9.8 Dead Time in Models 568 9.9 Simulation of a Vehicle Suspension 571 9.10 Summary 575 Problems 576 71 Sta ti tics, Hi s to grams, and Probability 418 C HAP T E R 10 8 7:2 The Normal Di stribution 427 Symbolic Processing with MATLAB 5 5 7.3 Random Number Generation 436 10.1 Symbolic Expressions and Algebra 587 7.4 Interpolation 444 10.2 Algebraic and Transcendental 7.5 Summa ry 457 Equations 596 Problem 458 10.3 Calculus 603 CHAPTERS Numerical Calculus and Differential Equations 465 8.1 Review of Integration and Differentiation 466 8.2 Numerical Integration 471 8.3 Numerical Differentiation 478 8.4 Analytical Solutions to Differential Equations 483 8.5 Numerical Methods for Differential Equations 490 8.6 Extension to Higher-Order Equations 8.7 ODE Solvers in the Control System Toolbox 518 8.8 Advanced Solver Syntax 527 8.9 Summary 531 Problems 532 CHAPTER9 Simulink 541 9.1 Simulation Diagrams 542 9.2 Introduction to Simulink 543 9.3 Linear State-Variable Models 548 508 10.4 Differential Equations 615 10.5 Laplace Transforms 622 10.6 Symbolic Linear Algebra 631 10.7 Summary 635 Problems 636 APPENDIXA Guide to Commands and Functions in This Text 649 APPENDIXB Animation and Sound in MATLAB 661 APPENDIX C Formatted Output in MATLAB 672 APPE DIX D References 675 APPENDIXE Some Project Suggestions www.mhhe.com/palm Answers to Selected Problems 676 Index 679 PREFACE F or me rl y used mainly by specialists in signal processing and numerical analysis, MA TL AB* in recent ye ar s has achieved widespread and enthus i- as ti c acceptance throughout the en gineering community. Many engineer- ing schools now re quir e a cour se based entil'ely or in part on MATLAB early in th e curriculum. MA TLAB is programmable and ha the ame logical, relational, conditional, and loop structures as other programming languages, such as Fortran, C, BASIC , and Pa scal. Thus it can be used to teach programming principles. In most schools a MATLAB cour se has replaced th e traditional Fortran course, and MATLAB is the principal computational tool us ed throughout the curriculum. In some techni ca l specialties, such as signal processing and control systems, it is the standa rd software package for analysis and de sign. Tbe popularity of MATLAB is partly due to its long history, and thus it is well developed and well tested. People trust its answers. Its popularity is also due to its us er interface, wbich provides an ea sy-to-use interactive environment that includes extensive numerical computation and visualization capabilities. Its compactness is a big advantage. For example , you can solve a set of many linear algebraic equations with ju st three lines of code, a feat that is impossible witb traditional programming languages. MATLAB is also extensible; currently more than 20 "toolboxes" in various application areas can be used with MATLAB to add new commands and capabilities. MATLAB is available for MS Windows and Macintosb personal computers and for otber operating systems. It is compatible across all tbese platfonllS, which enable s users to share their programs, insights, and ideas. TEXT OBJECTIVES AND PREREQUISITES This text is intended as a stand-alone introduction to MATLAB. It can be used in an introductory course, as a self-study text, or as a supplementary text. The text's material is based on the author's experience in teaching a required two-credit semester course devoted to MATLAB for engineering freshmen. In addition, the text can serve a a reference for later use. The text's many tables, and its referencing system in an appendix and at the end of each chapter. bave been designed witb this purpose in mind. A secondary objective is to introduce and reinforce the use of problem-solving methodology as practiced by the engineering profession in general and as applied to the use of computers to solve problems in particular. This methodology is introduced in Chapter I. MATLAB is " registered trademark of The MathWorks. lnc. Ix Pr eface The reader is a ss umed to h av e some knowledge of algebra a nd trigonometry ; kn ow ledge of calc ul us is not req uired for the fir s ~ s ev ~ n c h aprer s . _ ~om e . ~n o.w l e d ge of high school che mi stry and physics, primanly simple el e. ctl lcal ,C IICU lts, and basic sta ti cs and dy namics is req uired to u nd ers ta nd some of the eXdmples. TEXT ORGANIZATIO N This text is an u pd ate to th e author's pr ev ious tex t. ' In addition to prov.iding new mate ri al based on MATLAB 7, th e text in corporates th e many suggestIons made by reviewer a nd o th er users. '. . The t ex t consists of 10 chapters. The fi rst chapter gIves an. ovel V I ~W of MATLAB features, including it windows a nd me nu structures. It also 1I1t ro- duces the pro bl e m- solving methodology. Chapter 2 introduces th e con c.e pt of an arr ay, which is the fundame nt al data eleme nt in MATLAB, a n~ desc nb es ~ ow to use numeric arrays, cell arrays, a nd structure mTa Ys fo r basIc mathema tI cal operations. . Chapter 3 discusses the use of functions a nd fil es. MAT~AB has an e.x tens lV e number of built- in math fu nctions, and users can define tb elr own functIons and save them as a fi le for reuse. Chapter 4 treats programmi ng wi th MATLAB and covers relation al and logi- cal operator s, conditional statements, for and whi Ie loops, and th e switch structure. A major application of th e chapter's material is in si mul ation, to which a section is devoted. Chapter 5 treats two- and th ree-dimensional pl ott in g. It fi rst estab li shes sta n- dards for profession al -l ook in g, usef ul pl ots. In th e author's experien ce begin n in g students are not aware of these s ta n da rd s, so they are emphasized. The chapter th en covers MATLAB commands fo r pro du cing di fferent types of pl ot s and fo r controlling th e ir appearance. F un ction di scovery, w hi ch uses data plots to di scover a ma th ema ti cal descri pti on of th e data, is a common app li cation of pl ot ting, and a separate section is devoted to thi s topi c. The chapter also treats polyno mi al and multiple linear regre sion as part of its modeling coverage. Chapter 6 covers the solution of linear algebraic equa ti ons, which ar ise in applica ti ons in a ll fie ld s of eng in eering. "Ha nd " solution me tb ods are reviewed fi rs t. This r ev iew has proved he lp f ul to many stude nt s in th e auth or 's classes. T hi s coverage also esta bli shes th e terminology a nd some important con ce pts that are required to use th e compu ter me th ods prope rl y. The chapter th en shows how to u se MATLAB to solve systems of lin ear e qu a ti ons th at have a unique solution. The use of MATLAB with un de rd etermined a nd overdetermined systems is c ove red in two optional sec ti on s. Chapter 7 r ev iews b as ic sta ti s ti cs a nd probability a nd shows how to use MA TL AB to generate hi stograms, perfo rm ca lc ul ations with th e norm al distribu- ti on, and create ra nd om number si mula ti ons. The chapt er concludes with lin ea r " n fl vd ll C li on 10 MArViB 6 for En gin ee r s, McG r aw- Hili . Ne w Yo rk. 2000 . Pr eface and cubic-spline int er polation. Thi s chapter ca n be skipped if necessary. None of the fo Jl owing chapters depend on it. Chapt er 8 cove rs numeri ca l methods for calculus and di fferential equa ti ons. Analytical me th ods are reviewed to provide a fo undation for understanding and interpreting th e nume ri cal method s. Numerical integration and differenti a ti on methods are tre at ed. Ordinary differential equation solvers in th e core MATLAB program are co vered, as we ll as th e l inear -system solvers in th e Co ntrol System toolbox. Chapt er 9 introduces Simulink: which is a graphi ca l inter face for building simulations of dynamic systems. The coverage of Simulink has b ee n expanded to a separate chapter in light of its growing populari ty, as eviden ce d by rece nt workshops held by various professional organizations such as the ASEE. Th is chapter need n ot be covered to r ea d Cha pt er 10. Chapter 10 covers symbol ic me th ods for manipulating al ge br aic ex pr essions and for solving al ge braic and transcendental equa ti ons, ca lculus, differential e qu a- tions, and matrix al ge bra probl ems. The calculus appli ca ti ons include int eg ra- tion and differentia ti on, optimization, Taylor se ri es, se ries eva luation, and limits. La pl ace transform methods for solv in g differential equations are also introdu ce d. This cha pt er requires the u se of th e Symbolic Ma th toolbox or the Student Edition of MAT LA B. Ap pendix A co ntains a guide to the co mm ands and func ti ons introdu ce d in the text. Appendix B is an introduc ti on to producing animation and sound with MA TLA£. Whil e not essential to l ea rning MATLAB, th ese features are helpful for ge nerating student interes t. Appendix C summarizes functions f or creating fo rm atted outpu t. A pp endix D is a li st of r efe rences. App endix E, which is ava il able on the text's w eb s it e, conta in s some suggestions for cour se projects and is b ase d on the author's experience in t ea ching a fres hm an MATLAB c our se. Ans wers to se le ct ed problems and an ind ex app ea r at the end of th e tex t. AU fi gures, tables, equations, and exercises have b ee n number ed according to their chapter a nd se ction. F or exa mpl e, Fi gure 3. 4-2 is the s econd fi gure in Chapter 3, S ec tion 4. This system is designed to help the reader locate these items. Th e end-of-cha pter problems ar e the exception to this numbering system. They are numb ered 1, 2, 3, and so on to avoid confusion with the in- ch a pter exercises. The fi rst f our cha pt ers constitute a cour se in the essentials of MAT LAB. The remaining six cha pt ers ar e independent of each other , and may be covered in any order, or may be omitt ed if ne ce ssary. The se ch apters provide additional cov erage and examples of plotting and model building, linear algebraic e qu ations, proba- bility and statistics, calculus and differential equations, Simulink , and symbolic pro cess ing , respecti ve ly. ' Simulink is a registered trademark of The MathWo rk s .ln c. xi xii Prefac e SPECIAL REFERENCE FEATURES The te xt ha s the following s pecial features, which ha ve been designed to en han ce it s u se fuln ess as a reF ere nc e. • Throuahout each of the chapter s, num e rou s tables summari ze the comm~nds a nd functions a they are introduced. • At the end of each chapter is a guide to tables in that chapter. These m as ter tab l es will help the reader find de sc riptions of specific MATLAB commands. • Appendix A is a complete s umm ary of all the cO ll1l~ ands a nd functions described in the text , grouped by category, along with the number of tbe page on wbich they are introduced. • At the end of each chapter is a li st of the key terms introduced in tbe chapte r, w ith the page number referenced. • Key terms have been placed in the m argin or in sec ti on headings where they are introduced. • The ind ex has four section : a Ii ting of sy mbol s, an alphabetical li st of MATLAB co mmand s a nd functions, a li st of Simulink blocks, an d an alphabetical li st of topics. PEDAGOGICAL AIDS The following pedagogical aids have be en included: • Each chapter begins with an overview. • Test Your Understanding exe rci se appear throughout the chapters near the relev a nt te x t. The se relatively st rai ghtforward exercises allow readers to a ess their gra p of the material as soon as it is covered. In mo st ca es the answer to the exercise is given with the exercise. Students should work these exercises as they are encountered. • Each chapter ends with numerous problem s, grouped according to the relevant sect ion. • Each chapter contains numerous practical examples. The major examples are numbered. • Each chapter has a ummary section that reviews the chapter's objectives. • Answer to many end-oF-chapter problems appear at the end of the text. The e problems are denoted by an asteri k next to their number (for example. 15*). Two features have been included to motivate the student toward MATLAB and the engineering profession: • Mo t of the examples and the problem deal with engineering applications. The~e ru: e drav:n from a variety of engineering fields and show realistic ~pphcatlOns 01 MATLAB. A guide to these example appears on the inside tront cover. Preface • The fac in g page of each chapter co ntains a photograph of a recent engineering ac hi eveme nt that illustrates th e cha ll enging and interesting opportunities th at awai t eng in eers in th e 21 st century. A description of the ac hi evement, its re lat ed eng in eering di sc ipline s, and a di sc u ss ion of how MATLAB can be ap pli ed in those di sc iplines accompanies each photo. An In structor's Manual is ava il a bl e on lin e for in structors who have adopt ed this text for a course. Thi s ma nu al contains the complete so luti ons to a ll the Test Your Understanding exe rci ses and to all the chapter problem s. The text website (at http://www. mhh e.com/palm) also ha s downloadable file s con taining the major programs in th e t ex t, PowerPoint slid es keyed to the text, and suggestions for project . ACKNOWLEDGMENTS Many individuals are due credit for this text. Working with faculty at the Uni- versity of Rhode Island in developing a nd teaching a freshman co ur se based on MATLAB has grea tl y influenced thj s text. Email from many Ll sers contained use- ful suggestions. The following people, as we ll as several anonymou~ re viewer s. patiently reviewed the manuscript a nd sugges ted many helpful corrections and additions. Steven Ciccarelli, Rochester Institute of Technology Dwight D avy, Case Western Reserve University Yueh-Jaw Lin, The University of Akron Armando Rodrique z, Arizona Stale University Thomas Sullivan, Carnegie Mellon University Daniel Valentine, Clarkson University Elizabeth Wyler, Thomas Nelson Community College The MathWork s, Inc. has always been very supportive of educational pub- lishing. I especially want to thank Naomi Fernandes of The MathWorks, Inc. for her help. Carli e Paulson, Michaela Graham, Michelle Flomenhoft, and Peggy Lucas of McGraw-Hill efficiently handled the manuscript review!> and guided the text through production. My sister s, Linda and Chri s, and my mother Lillian, ha ve alway,- been there, cheering my efforts. My father was always there for support before he passed away. Finally. I want to thank my wife, Mary Louise. and my children. Aileene, Bill, and Andy, for their understanding and !>upport of this project. William J. Palm III KingMon. Rhod e Is land April,2004 xiii Introduction to MATLAB 7 for Engineers Engineering in the 21 st Century Remote Exploration I t will be many years before humans ca~1 tra:el to o~her planets. In the mean- time, unmanned probes have been rapidly ll1crea s ll1 g our knowledge of the universe. Their use wi ll increa se in the future as our technology develops to make them more reliable a nd more versatile. Better sensors are expected for imag- ing and ot her data collection. Improved robotic devices will make these probes more autonomous, an d more capable of interacting with their environment, in- stead of just observing it. NASA's pl anetary rover Sojourner landed on Mars on July 4, 1997, and ex- cited people on Earth w hil e they watched it successfu ll y explore the Martian surface to determine whee l- so il interactions, to analyze rocks and so il , and to return im ages of the la nd er for damage assessme nt. Then in ea rl y 2004, two im- pro ve d rovers, Spirit and Oppo rl uni ty, la nd ed on opposite s id es of th e planet. In one of the ma jor di scoveries of the 21st centur y, th ey obtained strong evidence th at water once existed on Mar in sig nifi ca nt amount s. About the size of a golf cart, the n ew rovers have six wheels, eac h with its own motor s. They have a top speed of 5 centimeters per second on flat hard ground and can travel up to about 100 meters per day. Needing 100 watts to move, th~y obtain power from solar arrays that generate 140 watts during a four-hour Wll1dow each day. The so ph isticated temperature control system must not only protect against nighttime te mp eratures of -96 °C, but mu st also prevent the rover from overheating. The robotic arm ha s th~ee joints ( houlder, elbow, and wrist), driven by five motor s, and It ha s a reach of 90 centimeters. The a rm calTies four tools and instru- ments for geo . log~cal studie s. Nine cameras provide hazard avoidance, navigation, a~d panoramic views. The on-boa rd computer ha s 128 MB of DRAM and coor- dmate all the s ub systems including communications. All engineering di sciplines we. re in volved with the rover s' design and launc h. Th~ MATLAB Neural Network, Signal Proce ss ing, Image Processing, PDE , and vanous control s~s tem.toolboxe s a re well suited to assist designers of probes and autonomous vehIcles lIke the Mars rovers . • An OvervielN of MATLAB®* OUTLINE 1.1 MATLAB Interactive Sessions 1.2 Menu s and the Toolbar 1.3 Computing with MATLAB 1.4 Script Files and the EditorlDebugger 1.5 The MATLAB Help System 1.6 Programming in MATLAB 1.7 Problem-Solving Methodologies 1.8 Summary Problem s CHAPTER This is the most important chapter in the book. By the time you have finished this chapter , you wi]] be able to use MATLAB to solve many kinds of engineering problems. Section 1.1 provides a "quick-start" introduction to MATLAB as an interactive calculator. Section 1.2 covers the main menus and tool bar. Section 1.3 gives an overview of MATLAB, and directs the reader to the appropriate chapter where more detailed information is available. Section 1.4 discusses how to create edit, and save MATLAB programs. Section 1.5 introduces the extensive MATLAS Help Sy stem. Section 1.6 treats the use of conditional statements and loops. Section 1.7 discusses methodologies for approaching engineering problems, with particular emphasis on a methodology to use with computer software such as MATLAB. A number of practice problems are given at the end of the chapter. *MATLAB is a registered trademark of The MathWork s. Inc. 1 3 CHAPTER 1 An Overview of MATLAB How to U se T hi s Book The book's ch ap ter orga nization is fl exib le enough to accommodate a va r!ety of u se r s. However, it is imp Oitant to cove r at l eas~ the. fir~ t fo ur c h ~pters, 111 that orde r. Ch a pt er 2 cove rs ar rays, w hi ch are th.e b~s l C butldll1 g blocks 111 M~T L A B . Ch apter 3 cove rs fil e usage, f un c t io n ~ butl~ lIl to MAT LAB, a:~ u se l - d ~fi n ~ d f un c ti on s. Ch a pt er 4 cove rs progra mmll1 g uS lI1 g re l atIO nal and 1 00 lcal opel atol s, co nditi onal stateme nt s, a nd l oo p s. . Use S ec ti on 1 .3 to dete rmin e th ose MA TLAB fea tur es fo r w hl ~ h yo u wa nt more deta il ed in f orm a tion . Thi s sec tion will g uid e yo u to th e a ppropn a t ~ chapter. Ch a pt ers 5 thr ough 10 are ind epe nd e nt cha pt ers :h at can be covered In an y or- der, or ca n be o mitt ed. Th ey co nt a in in-d e pth di sc u ss lOn s of ho w to use MATLAB to so l ve seve ral c ommon typ es of eng in ee rin g probl em s. Ch apter 5 covers t ~ o  a nd thr ee -dim ens ion al plots in more deta il , a nd shows ho w to use pl ots to bUlld math ema tical mod els f rom dat a. Chapter 6 tr ea ts the solution of linear alge- br aic e qu a ti on s, including c as es havin g nonunique solutions Chapter 7 covers probability, s tati s tic s, a nd int erpolation applications. Chapter 8 lIltroduces nume r- ic al methods for calcu lu s and ordinary differential equations. Chapter 9 covers Simulink® ,* which is a graphical user intelface for solving differential equation model s. Chapter 10 covers symbolic proce ss ing in MATLAB , with app li cations to al gebr a, ca lculu s, differential equations, lin ear algebra, and transforms. Reference and Learning Aids The book has been designed as a reference as we ll as a learning tool. The special features useful for the se purposes are as fo ll ows . • Throughout each chapter margin notes identify where new terms are introduced. • Throughout eac h chapter short Test Your Understanding exercises appear. Where app ropriate, answers immediately fo ll ow the exercise so you can measure yo ur mastery of the material. • Homework exe rcises co nclud e each cha pt er. These usually requi re more effort than the Te st Your U nd ersta ndin g exercises. • Each chapter co ntain s t ab l es s umm ar iz in g the MATLAB commands intr od u ced in that chapter. • At the end of each chapter i s: • A ummary g uid e to th e co mmand s covered in th at chapter, • A s umm ary of what you sho uld be a bl e to do after complet in g that chapter, and • A li st of key terms you s hould know. • Appendix A con~ains tables of MATLAB commands, gro up ed by category, W Ith th e a ppr oprIa te page refe rence s. · Simulink i, a r eg istered trad ema rk of The MathWorks. [nc o CHAPTER 1 An Overview of MATLAB • Two in dexes are in c lud ed. Th e fir st is an ind ex of MAT LAB commands and sy mbol s; th e seco nd is an ind ex of to pi cs. Software Upd at es and Accuracy Software publishers can release software updates faster th an book publishe rs can release n ew edition s. This t ex t doc um e nt s th e pre-release vers ion of MATLAB 7 as of th e spring of 200 4. Th ere will be additional updates, numbered 7.1 , 7.2, a nd so fo rth , th at will change some of th e program's features. The best way to protect yo urself aga in st obsolete info rm ation is to c he ck the "What's Ne w? " file provided w ith th e program, a nd to lea rn how to use the ext en s ive MATLAB Help S ys tem, w hi ch is covered in Section 1.5. MATLAB and Related Software MATLAB is both a computer programming lan guage and a oftware environment for using that l an g ua ge effectively. It is maintained and so ld by The MathWorks, Inc ., of Natick, Massachuse tt s, and is ava il ab le for MS Windows and other com- puter system s. The MATLAB interactive environment al l ow you to manage va ri able s, import and export data, perform calc ul ations, generate plot s, and de- ve lop and manage files for use with MATLAB. The language was originally developed in the 1970s for applications involving matrice , linear algebra, and numerical analysis (the name MATLAB stands for "Matrix Laboratory'· ). Thus the language's nLllnerical routines have been well-tested and improved through many years of use, and i ts capabiJities have been grea tl y expanded. MATLAB h as a number of add-on sof tw are modules, called toolboxes, that perform more specia li zed computa ti ons. They can be purchased separatel y, but a ll run under the core MATLAB program. Toolboxes deal with applications such as image and signal processing, financial analysis, control systems design, and fuzzy logic. An up -to -d ate li st can be fo und at The MathWorks webs it e, which is discussed later in this chapte r. Thi text uses material from the core MATLAB program, from two of the t ool boxes (the Control Systems to olbo x. in Chapter 8, and the Symbolic Math toolbox, in Chapter 10), and from SimuJink (in Chapter 9). All of the examples and problems in the first seven chapters can be done with the core MATLAB program. On MS Windows systems MATLAB 7 requires Windows XP or Windows NT to run. The Student Edition of MATLAB contains the core MATLAB program. some co mm ands from two toolboxes (the Signal Processing toolb ox and the Symbolic Math to olbox), a nd the Simulink program. The Simulink program is based on MATLAB, and requires MATLAB to run. This book does not explain how to install MATLAB. If you purcha<;ed it for yo ur own computer, the installation is easily done with the instructions that come with the , oftware. If you will be u ing MATLAB in a computer lab, it will have been in sta ll ed for you. In the next section we introduce MATLAB by means of some imple se ·sions to illustrate its interactive nature. basic syntax, and features. [...]... in stall ed on drive c: in the directo ry c : \ matlab Then the toolbox directory is a subdirectory under the directory c : \matlab, and symbolic is a subdirectory under the toolbox directory The path tells us and MATLAB how to find a palticular file For exa mple, the file sol ve m is a fu nction in the Symbolic Math toolbox The path to thi s file is c : \ matlab \ toolbox \ symbolic The full name... exponent; 6. 379 24 378 478 I 294e-04 Two decimal digits; 126 .73 Po itive negali ve or zero: + Rat ional approximation; 43 17 Suppresses some line feeds Resets to less compact di splay mode short long short e long e format bank format + format format compact format ~oose Menus and the Toolbar 17 ca lcul atio ns, but we rarely need to see all of them The default MATLAB display fo rm at is the short for mat,... directory Most data files and other non -MATLAB files are not listed U e dir to get a list of all fil es Lists the MATLAB- specific fi les in directory dirname force MATLAB to look in th at directory to find your file The general sy ntax of this command is cd dirname, where dirname is the full path to the directory The main directory on the di sk is a:, so if your fi le is in the main directory, be sure to. .. rname command does the same for the directory d i rname You can add a directory to the search path by using the a d dpa th command To remove a directory fro m the search path, use the rmpath command The Set Path tool is a graphical intetface for worki ng with files and directories Type path tool to start the browser To save the path settin crs click on Save in the tool To restore the default search path,... You can di splay more by typing format long, whi ch gives 16 digits To return to the default mode, type format short You can force the output to be in scientifi c notati on by typin g format short e, or forma t long e, where e stands for the number 10 Thu s the output 6 379 2e+03 stands fo r the number 6. 379 2 x 10 3 The output 6 379 2e-03 stands for the number 6. 379 2 x 10- 3 Note that in thi s context... temperatures in degrees Fahrenheit File mydata m: Stores temperature data % Stores the array temp_ F , % which contains temperatures in degrees Fahrenheit temp_F = [72 , 68 , 75 , 77 , 83 , 79 ] A session to access this data from the Command window, and convert th e temperatures to degrees Celsius, is Documenting Units of Measurement »mydata temp_ F = 72 68 75 77 83 79 »temp_C = 5*(temp_ F - 32)/9 temp_ C =... - Formatting Commands The format command controls how numbers appear on the screen Table 1.1-S gives the variants of thi s command MATLAB uses many significant figures in its Table 1.1-5 Numeric di splay format s Command Description and example format formac formal format Four decimal di gi t (the default); 13. 674 5 16 digits: 17 274 840294635 47 Five digits (four decimal s) pillS expo nent; 6. 379 2e+03... Dorectory WOI~spece x • (O:0.02: 6 J; V • MATLAB Inleraclivo Sessions An Overview of MATLAB St'!Hn(x); Figure 1.1-1 The default MATLA B Dc ktop vi LJ(Q](8J Command window, the Command Hi story window, and the Curren t Directory wi ndow Across the top of the Desktop are a row of menu names, 'Ind a row of icon s ca ll ed the too/bar To thc right of the too lbar is a box showing th e directory where MATLAB. .. Ime o~le character at a tllne To move through one word at a time, press Ctrl and ~ Sll1lulta.neously to move to the righr; press Ctrl and ~ simultaneously to move to the left Pr~ss Home to move to the beginning of a line; press End to move to the end of a lme Press Del to delete the character at the cursor; press Backspace to delete the character before the cursor Press Esc to clear the entire line; press... Desktop includes three other windows, the Command Hi story, Current Directory, and Workspace windows, which we discussed in the previous section Across the top of the Desktop are a row of menu names, and a row of icons called the too /bar To the right of the tool bar is a box howing the current directory, where MATLAB looks for files We now describe the menus and the toolbar Other windows appear in a MATLAB . ISB N 0 072 480688 Palm Introduction to MATLAB 7 for Engineers ISBN 0 072 9224 27 Pritchard . Mathcad: A Tool for Engineering Problem SolvlOg ISBN 0 070 121893. 4/e ISBN 0 072 831 154 Introduction to MATLAB 7 for Engineers WiUiam J. Palm III Un iversity of Rhode Island ffI Higher Education B oston Burr

Ngày đăng: 23/03/2014, 17:15

Từ khóa liên quan

Tài liệu cùng người dùng

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

Tài liệu liên quan