Appl Matlab

Download Appl Matlab

Post on 04-Dec-2014




1 download

Embed Size (px)


introduction to matlab


<p>CONTENTSAbout the Aufhor Prefoce xiii xvii iv</p> <p>Guided Tour</p> <p>PanrOur Modeling, Computers, ond Error Anolysis Il. I Motivofion I 1.2 Port Orgonizotion 2</p> <p>CHAPTER IMothemqticol Modeling, Numericol Methods, ond Problem Solving 4 I .l A Simple M o t h e m o t i cM o lo d e l 5 1.2 Conservotion Lowsin Engineering ond Science 12 1.3 Numericol Methods Covered in ThisBook l3 P r o b l e m s1 7</p> <p>CHAPTER 2MATLAB Fundomeniqls 2.1 2.2 2.3 2.4 2.5 2.6 2.7^ l l</p> <p>20</p> <p>TheMATIABEnvironmenl21 Assignment 22 Mothemoticol Operotions 27 U s eo f B u i l t l n Functions 30 Groohics 33 OtherResources36 CoseStudy: Explorotory DotoAnolysis 37</p> <p>rroblems JY</p> <p>CHAPTER 3Progromming with MATTAB 42 3.1 M-Files 43 3.2 InputOutput 47</p> <p>vl</p> <p>CONTENTSdr o g r o m m i n g 3 . 3 S h u c t u r eP 5l 3.4 Nesting ond Indentotion 63 gunction 3 . 5 P o s s i nF to s M-Files66 3.6 CoseStudy: Bungee Velocity 71 Jumper Problems 75</p> <p>4 CHAPTERRoundoff qnd Truncotion Errors 79 4.1 ErrorsB0 4.2 Roundoff Errors 84 4.3 Truncotion Errors 92 ,l03 4 . 4 T o t oN l umerico E l rror , o d e lE r r o r so 4.5 Blunders M , n d D o t oU n c e r t o i n t y1 0 8 ,l09 Problems</p> <p>.|11 PnnrTwo Roots ondOptimizotion2.1 Overview tll 2.2 Port Orgonizotion I 12</p> <p>CHAPTER 5Roois: Brocketing Methods I l4 in Engineerin 5.1 Roots og ndScience I l5 5 . 2 G r o p h i c oM l ethods I l6 ge t h o d s 5.3 Brocketin M o n d I n i t i oG l u e s s e s1 1 7 5 . 4 B i s e c t i o n1 2 2 5.5 Folse Position128 5.6 CoseStudv: Greenhouse Gosesond Roinwoter 132 ,l35 Problems</p> <p>CHAPTER 6Roots: Open Methods | 39 6.1 Simple F i x e d - P o iln te i rotion 140 6 . 2 N e w t o n - R o p h s o1 n4 4 6 . 3 S e c o nM t ethods 149 6.4 MATLAB Function f :z e r o r 5 1 6 . 5 P o l v n o m l o l s1 5 4 : i p eF r i c t i o n 1 5 7 6 . 6 C o s eS t u d yP Problems 162</p> <p>CONTENTS</p> <p>Yrt</p> <p>7 CHAPTEROptimizofion 166 7.1 Introduciion ond Bockground 167 7 . 2 O n e - D i m e n s i o n o l O p t i m i z o t i1 o7 n0 7 . 3 M u l t i d i m e n s i o n o l O p t i m i z o t i1 o7 n9 Eln e r g y l 8 l m ndMinimum Potentio 7 . 4 C o s eS t u d yE : q u i l i b r i uo P r o b l e m s1 8 3</p> <p>,|89 PrnrTxnrr Lineor Systems3.1 Overview 189 3.2 Port Orgonizotion l9l</p> <p>CHAPTER 8Lineqr Algebroic Equofions ond Motrices | 93 8.1 MotrixAlgebroOverview 194 Algebroic Equotions with MATLAB 203 Lineor 8.2 Solving in Circuits 205 Currents ond Voltoges 8.3 CoseStudy: Problems 209</p> <p>9 CHAPTERGouss Eliminotion 212 of Equotio sn 2 1 3 9.1 Solving SmolN l umbers E l i m i n o t i o n2 1 8 9 . 2 N o i v eG o u s s 9.3 Pivoting225 9.4 Tridiogono Sly s t e m s2 2 7 9.5 CoseStudy: Model of o HeotedRod 229 Problems 233</p> <p>IO CHAPTER[U Foctorizotion 236 237 l0.l Overview of lU Foctorizotion Eliminotio 238 10.2 Gouss on s lU Foctorizotion 244 1 0 . 3 C h o l e s kF yoctorizotion 'l0.4 Left Division 246 MATLAB Problems 247</p> <p>vIt!</p> <p>CONIENTS</p> <p>CHAPTER IIMotrix lnverse ond Condition 249 1 i .l TheMotrix lnverse 249 I I .2 ErrorAnolysis ond System Condition 253 I 1 . 3 C o s eS t u d yI A i r P o l l u t i o n2 5 8 :n d o o r Problems 261</p> <p>CHAPTER I2Iterotive Methods 264 l2.l Lineor 264 Systems: Gouss-Seidel ,l2.2 N o n l i n e oS r y s t e m s2 7 0 1 2 . 3 C o s eS t u d vC : h e m i c oR l eoctions 277 P r o b l e m s2 7 9</p> <p>PtrnrFoun Curve Fitting 2814.1 Overview 281 4.2 Port Orgonizotion 283</p> <p>CHAPTER I3Lineor Regression 284 R 13.I Stotistic se v i e w 2 8 6 es gression 1 3 . 2 L i n e oL r e o s t - S q u oR re 292 ,l3.3 Lineorizotion f N o n l i n e oR s0 0 r e l o t i o n s h i p3 1 3 . 4 C o m p u t eA r p p l i c o t i o n s3 0 4 1 3 . 5 C o s eS i u d y E : nzyme K i n e t i c s3 0 7rroDtems 5 | z^ l l</p> <p>CHAPTER I4Generol lineqr Leosf-Squores qnd Nonlineqr Regression 316 1 4 .I P o l y n o m i o Rle g r e s s i o n 3 16 14.2 Multiple L i n e oR r egression 32O 1 4 . 3 G e n e r oL r e o sS l i n e oL t ouores322 14.4 QR Foctorizotion ond the Bockslosh Ooerotor 325 1 4 . 5 N o n l i n e oR e g r e s s i o n 3 2 6 r 1 4 . 6 C o s eS l u d y F : itting S i n u s o i d s3 2 8h</p> <p>rrontcms</p> <p>l l</p> <p>.1.1 /</p> <p>CONIENIS</p> <p>'I 5.'l lntroduction to Interpotofion336 I5.2 NewronInterpoloring polynomiol 33g polynomiol j: .j tosron9etnrerpoloring 347 rJ.4 tnverse tnterpolotion350 I J.J txkopolotion ondOscillotions 351 Problems 355</p> <p>t6 cHAPTERSplines ond piecewise Inferpofofion I 6 . I l n k o d u c t i otn o Splines 359 l o . z L i n e aS r p l i n e s3 6 1 16.3 Quodroiic Splines365 1 6 . 4 C u b i cS p l i n e s 3 6 8 359</p> <p>374 i 6.6 Multidimensionol Interpolotion 37g l6 Z CoseStudy: HeotTronsfer 3g2 rrobtems 386</p> <p>Inrerpotorion inMATLAB l9: liTewise</p> <p>PnnrFvr Infegrotion ond Differentiotion 3g95.1 Overview 3g9 5.2 Port Orgonizotion 39O !H,\PTER| 7Numericof fnfegrofion Formutos Sg2 'l Z.J lnhoduction ond Bocrground 393 I7.2 Newton-Cotes Formutos 396 17.3 TheTropezoidol Rule 39g 17.4 Simpson, su l e s 4 0 5 R 17.5 Higher-Order Newfon_Cotes Formulos 4j j l7 6 lntegration with Unequol Segments 412 17.7 OpenMerhods 416 I7 8 Muh,ple I n t e g r o l s4 j 6 Compuring Work wirh Numericol lnregrorion 4j9 ;lJ;:r";udy:t It I</p> <p>!</p> <p>i{.</p> <p>Numericof Integrotion of Functions 'l 8.I Introducfion 426 18.2 RomberI qn i e q r o t i o n4 2 7</p> <p>CONTENTS18.3 Gouss Q u o d r o t u r e4 3 2 I8.4 Adoptive Q u o d r o t u r e4 3 9 I8.5 CoseStudy:Root-Meon-Squore Current 440 Problems 444</p> <p>CHAPTER I9Numericql Differentiqtion 19.I 19.2 I9.3 ,l9.4 ,l9.5 448 Inhoduction ond Bockground 449 High-Accurocy Differentiotion Formulos 452 Richordso nx t r o p o l o t i o n E 455 Derivotives of Unequolly SpocedDoto 457 Derivotives ond lntegrols for Dofo with Errors 458 19.6 Portiol Derivotives 459 I9.2 Numericol Differentiotion with MATLAB 460 I 9 . 8 C o s eS t u d yV : i s u o l i z i nF gi e l d s 4 6 5 Problems 467</p> <p>Pnnr5x</p> <p>Ordinory Differentiol Equotions 4736.1 Overview 473 6.2 Porl Orgonizofion 477</p> <p>CHAPTER 20Initiol-Volue Problems 479 20.I Overview 481 20.2 EuleisMethod 481 20.3 lmprovemenls of Euler's Method 487 20.4 Runge-Kutfo Methods 493 20.5 Systems of Equotions 498 20.6 CoseStudy:Predotory-Prey Modelsond Choos 50A Problems 509</p> <p>CHAPTER 2IAdopfive Merhods ond Stiff Systems 514 21 .'l AdoptiveRunge-Kutto Methods 514 2l .2 Multistep Methods 521 2l .3 Stiffness525 2l .4 MATLAB Applicotion :u n g e J B e u m p ew r i t hC o r d 5 3 1 2l .5 CoseStudy: Pliny's lntermittent Fountoin 532 r r o D l e m s3 J /</p> <p>CONTENTS</p> <p>xl</p> <p>22 CHAPTERBoundory-Volue Problems 540 22.1 lntrodvction ond Bockground 541 Method 545 22.2 lhe Shooting 22.3 Finite-Difference Methods 552 P r o b l e m s5 5 9</p> <p>APPENDIX A: EIGENVALUES 565 FUNCTIONS 576 APPENDIX B: MATLAB BUILT-IN APPENDIX : MATIAB M-FltE FUNCTIONS 578 BIBLIOGRAPHY579 rNDEX 580</p> <p>Modqling,CoTpute''i ,qnd Erior Anolysis</p> <p>t.t</p> <p>MoTtvATtoNWhat are numericalmethodsand why shouldyou stridythem? problemsare formulatedso are techniques by which mathematical Numericalmethods Because digital computers that they can be solved with arithmeticand logical operations. numericalmethodsare sometimes referredto as comexcel at suchoperations. puter mathematics. se.-In the pre-computerera, the time and drudgeryof implementingsuchcalculations riously limited their practical use. However, with the advent of fast, inexpensivedigttul computers,the role of numerical methodsin engineeringand scientific problem solving has exploded.Becausethey figure so prominently in,:' much of our work, I believe that numerical methods should be a part of every engineer'sand scientist's basic education.Just as we a.ll must have solid founand science, dationsin the other areasof mathematics of we should also have a fundamentalunderstanding numerical methods.In particular,we should have a solid appreciation of both their capabilitiesand their limitations. Beyond contributing to your overall education. .thog T9 several additibnat reasons why you shoutO .",,,,rr,,,r,,,r,,,,,, study numerical methods: 1. Numerical methods greatly expqld the types of , problems you can address. They are capableof nonlinearihandlinglarge systems of equations. , , d.l, and complicated geometriesthat are not uncommon in engineeringand scienceand that are often impossible to solve analyticallywith stanyour dard calculus. As such"they greatlyenhance problem-solving skills. 2. Numorical methods allow you to use "canned" so-ftware with insight. During your career,you will q*"</p> <p>AND ERROR ANALYSIS I MODELING, COMPUTERS, PARTprepackaged computerproto use commercially available invariablyhave occasion grarnsthat involve numericalmethods. The intelligentuseof theseprogramsis greatly of the basic theory underlyingthe methods.In the abenhanced by an understanding you will be left to treat suchpackages as "black boxes" senceof suchunderstanding, with little critical insightinto their inner workingsor the validity of the resultsthey produce. Many problemscannotbe approached using cannedprograms.If you are conversant with numerical methods,and are adept at computer programming,you can design expensive your own programs withouthavingto buy or commission to solveproblems software. Because nuNr.rrnerical methodsare an efficient vehiclefbr learningto usecomputers. they areidealtbr mericalmethods ale expressly designed for computerimplementation, implement powers and limitations.When you successfully illustratingthe conrputer's numericalmethodson a computer,and then apply them to solve otherwiseintractable problenrs, you will be plovided with a dramaticdernonstration of how computerscan At the sarne serveyour professional development. lime, you rvilI alsolearnto acknowledge and control the errors of approximationthat are part and parcel of large-scale numericalcalculations. Numericalmethodsprovidea vehiclefbr you to reinforceyour understanding of mathernatics. Because one tunction of numericalmethodsis to reducehigher mathematics to basic arithmetic operations.they get at the "nuts and bolts" of some otherwise and insight can result from this alternative obscuretopics. Enhancedunderstanding perspective.</p> <p>3.</p> <p>4.</p> <p>5.</p> <p>how numerical With thesereasons lls motivation.we can now set out to understand work in tandemto generate reliablesolutionsto mathematmethodsand digital computers ical problems.The remainderof this book is devotedto this task.</p> <p>1.2 PART ORGANIZATIONThis book is divided into six parts.The latter five partsfocus on the major areasof numerAlthough it might be temptingto jump right into this material,Part One conical methods. of dealng with essential backgroundmaterial. sists four chapters provides 1 concrete example of how a numericalmethodcan be employed Chapter a problem. this, we develop tt muthematicalmodel of a fiee-falling To do to solve a real jumper. model, is Newton's secondlaw, resultsin an ordinary The which basedon bungee to develop a closed-formsolution,we then differentialequation.After first using calculus generated can with a simple numerical method.We be show how a comparablesolution rnethods that we cover in an of the major areers of numerical overview end the chapterwith Parts Two throughSir. Chapters2 and 3 provide an introduction to the MATLAB' software environment. way of operatingMATLAB by enteringcommandsone Chapter2 dealswith the standard modeprovidesa straightforward t'alculatornuttle.Thisinteractive at a time in the so-called meansto orient you kl the enviroumentand illustrateshow it is usedibr common opera-</p> <p>I.2 PART ORGANIZATIONChapter-l shows how MATLAB's programming mode providesa vehicle for assemThus,our intentis to illustrate how MATLAB into algorithms. bling individualcommands your software. programming environment to own a develop servesas convenient ChapterI dealswith the irnportanttopic of error analysis,which must be understood for the effective use of numerical methods.The first part of the chapterfocuseson the roundoJferrors thar result becausedigital computerscannot representsome quantities truncationerrctrsthat arisefiom using an approximation exactly.The latter part addresses procedure. in place of an exactmathematical</p> <p>{.1:i</p> <p>ffilT**TFi +</p> <p>i.t "</p> <p>i'i,rI r,if i</p> <p>..,,lrfi;</p> <p>U1</p> <p>I</p> <p>Mothemoticol Modeling, Numericol Methods, ond Problem Solving</p> <p>I</p> <p>4CHAPTER OBJECTIVESThe prirnary objectiveof this chapteris to provide you with a concreteidea of what numericalmethodsare and how they relateto engineering anclscientificproblem solving. Specificobjectivesand topicscoveredare o r o Learning how mathematical modelscan be formulatedon the basisof scientific principles to simulate the behavior of a simplephysicalsystem. Understanding how numericalmethodsirlford a meansto generate solutionsin a rnannerthat can be irnplemented on a digital computer. Understanding the different typesof conservation laws that lie beneath the models usedin the variousengineering disciplinesand appreciating the diff'erence betweensteady-state irnd dynamic solutionsof thesemodels. Learning aboutthe difterent typesof numericalmethodswe will cover in this book.</p> <p>r</p> <p>1</p> <p>FIG For</p> <p>f-^^ l I cc-</p> <p>ium</p> <p>r</p> <p>YOU'VE GOT A PROBTEMupposethat a bungee-jumping companyhires you. You're given the task of predicting the velocity of a jumper (Fig. l.l ) as a function of time during the free-fall part of thejump. This inlbrmationwill be usedaspart of a largeranalysisto determine the length and requiredstrengthof the bungeecord for jumpers of differentmass You know from your studies ofphysics that the acceleration shouldbe equalto the ratio of the tbrceto the mass(Newton'ssecond law). Based on this insightandyour knowledge</p> <p>I .I A SIMPTE MATHEMATICAL MODELof fluid mechanics, you developthe following mathematical model for the rate of change r.r'itr he s p e ctto t i m e . ol'velocityducd. dt''m</p> <p>Upwardforce d u et o a i r resistance</p> <p>ttil</p> <p>Downward forcedue to gravrty</p> <p>til v</p> <p>where rr : vertical velocity (n/s). r : time (s), g : the accelerationdue to gravity (:9.81nls21, ca: a second-order drag coetficient (kg/m), and m: the jumper's mass(kg). Because this is a ditlerentialequation,you know that calculusmight be usedto obtain an analyticalor exactsolutionfor u as a function of /. However,in the following pages,we will illustrate an alternativesolution approach. This will involve developinga con.rputerorientednumericalor approximate solution. Aside from showing you how the computercan be usedto solve this particularproblem, our more generalobjective will be to illustrate (a) what numericalmethodsare and (b) how they figure in engineering and scientificproblen solving.In so doing, we will also show how mathematical n.rodels figure prominentlyin the way engineers and scientists use numericalmethodsin their work.</p> <p>flGURE l.lForces ociing on o lreeJolling bungee iumpet.</p> <p>I.l</p> <p>A SIMPTE MATHEMATICAT MODETA motlrcnntical ntodelcan be broadly definedas a tbrmulation or equationthat expresses features the essential of a physicalsystemor process in mathematical terms.In a very general sense, it can be represente...</p>