MATLAB : An Introduction With Applications

3y ago
122 Views
34 Downloads
5.59 MB
680 Pages
Last View : 2d ago
Last Download : 2m ago
Upload by : Axel Lin
Transcription

MATLABAn IntroductionwithApplications

This pageintentionally leftblank

MATLABAn IntroductionwithApplicationsRao V. DukkipatiPh.D., P.E.Fellow of ASME and CSMEProfessor and ChairGraduate Program DirectorDepartment of Mechanical EngineeringFairfield UniversityFairfield, ConnecticutUSA

Copyright 2010, New Age International (P) Ltd., PublishersPublished by New Age International (P) Ltd., PublishersAll rights reserved.No part of this ebook may be reproduced in any form, by photostat, microfilm,xerography, or any other means, or incorporated into any information retrievalsystem, electronic or mechanical, without the written permission of the publisher.All inquiries should be emailed to rights@newagepublishers.comISBN (13) : 978-81-224-2920-6PUBLISHING FOR ONE WORLDNEW AGE INTERNATIONAL (P) LIMITED, PUBLISHERS4835/24, Ansari Road, Daryaganj, New Delhi - 110002Visit us at www.newagepublishers.com

ToLord Sri Venkateswara(v)

This pageintentionally leftblank

PrefaceThe main objective of this book is to provide the students with the opportunity to improve theirprogramming skills using the MATLAB environment to implement algorithms and to teach the use ofMATLAB as a tool in solving problems in engineering. This book includes the coverage of basics ofMATLAB and application of MATLAB software to solve problems in electrical circuits, control systems,numerical methods, optimization, direct numerical integration methods in engineering. With thisfoundation of basic MATLAB applications in engineering problem solving, the book providesopportunities to explore advanced topics in application of MATLAB as a tool.An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLABcommands. MATLAB is considered as the software of choice. MATLAB can be used interactively andhas an inventory of routines, called as functions, which minimize the task of programming even more.Further information on MATLAB can be obtained from: The MathWorks, Inc., 3 Apple Hill Drive, Natick,MA 01760. In the computational aspects, MATLAB has emerged as a very powerful tool for numericalcomputations involved in engineering problems. The idea of computer-aided design and analysis usingMATLAB with the Symbolic Math Tool box, and the Control System Tool box has been incorporated.Chapter 2,3,4,5 and 6 consists of many solved problems that demonstrate the application of MATLAB tothe analysis of electrical circuits, control systems, numerical methods, optimization and direct numericalintegration methods. In chapter 6, we have briefly reviewed the direct numerical integration methods forthe solution of a single or system of differential equations. Many numerical methods are available for thesolutions of the response of dynamic systems. We have discussed several widely used step-by-stepnumerical integration methods for linear dynamic response analysis. A brief description of theseintegration methods is presented and their application is illustrated. The integration schemes consideredwere three explicit and four implicit methods. They are the explicit schemes (the central difference method,two-cycle interaction with trapezoidal rule and fourth order Runge-Kutta method) and the implicit schemes(Houbolt method, Wilson Theta method, Newmark Beta method and the Park Stiffly stable method).Application of these direct numerical integration methods is illustrated with a case study of a lineardynamic system.Presentations are limited to very basic topics to serve as an introduction to advanced topics inthose areas of discipline. Chapters 2, 3, 4, 5 and 6 include a great number of worked examples andunsolved exercise problems to guide the student to understand the basic principles, concepts and use ofMATLAB in solving a variety of engineering problems.(vii)

viii ——— PrefaceAn extensive references to guide the student to further sources of information on electrical circuits,control systems, numerical methods, optimization and direct numerical integration methods is provided atthe end of each chapter. All end-of-chapter problems are fully solved in the Solution Manual availableonly to Instructors.I sincerely hope that the final outcome of this book will help the students in developing anappreciation for the topic of solving engineering problems with MATLAB.Rao V. Dukkipati

AcknowledgementI am grateful to all those who have had a direct impact on this work. Many people working in the generalareas of engineering have influenced the format of this book. I would also like to thank and recognize allthe undergraduate and graduate students in mechanical and electrical engineering programs at FairfieldUniversity over the years with whom I had the good fortune to teach and work and who contributed insome ways and provide feedback to the development of the material of this book. In addition, I greatly owemy indebtedness to all the authors of the articles listed in the bibliography of this book. Finally, I wouldvery much like to acknowledge the encouragement, patience and support provided by my family members:Sudha, Ravi, Madhavi, Anand, Ashwin, Raghav, and Vishwa; who have also shared in all the pain, frustration,and fun of producing a manuscript.I would appreciate being informed of errors, or receiving other comments about the book. Please writeto the authors’ address or send e-mail to Professordukkipati@yahoo.com.Rao V. Dukkipati(ix)

This pageintentionally leftblank

cknowledgementixMATLAB BASICS1–95IntroductionArithmetic OperationsDisplay FormatsElementary Math Built-in FunctionsVariable NamesPredefined VariablesCommands for Managing VariablesGeneral CommandsArraysOperations with ArraysElement-by-Element OperationsRandom Numbers GenerationPolynomialsSystem of Linear EquationsScript FilesProgramming in MATLABGraphicsInput/Output in MATLABSymbolic MathematicsThe Laplace TransformsControl 823242938394344838485(xi)

xii ——— .224.4.14.24.34.44.54.6ELECTRICAL CIRCUITSIntroductionElectrical CircuitsKirchhoff’s LawsExample Problems and 18CONTROL SYSTEMSIntroductionControl SystemsExamples of Control SystemsControl System ConfigurationsControl System TerminologyControl System ClassesFeedback SystemsAnalysis of FeedbackControl System Analysis and Design ObjectivesMATLAB ApplicationSecond-order SystemsRoot Locus PlotsBode DiagramsNyquist PlotsNichols ChartGain Margin, Phase Margin, Phase Crossover Frequencyand Gain Crossover FrequencyTransformation of System ModelsBode Diagrams of Systems Defined in State SpaceNyquist Plots of a System Defined in State SpaceTransient-Response Analysis in State SpaceResponse to Initial Condition in State SpaceExample Problems and 4126127128129129131132132133134NUMERICAL METHODSIntroductionSystem of Linear Algebraic EquationsGauss Elimination MethodLU Decomposition MethodsCholeski’s DecompositionGauss-Seidel 9139188190

Contents ——— xiii4.74.84.94.104.114.124.134.144.15Gauss-Jordan MethodJacobi MethodThe Householder FactorizationSymmetric Matrix Eigenvalue ProblemsJacobi MethodHouseholder Reduction to Tridiagonal FormSturn SequenceQR MethodExample Problems and NIntroductionConjugate Gradient MethodsNewton’s MethodThe Concept of Quadratic ConvergencePowell’s MethodFletcher-Reeves MethodHooke and Jeeves MethodInterior Penalty Function MethodExample Problems and 62672672682703163166.6.16.26.36.46.56.6DIRECT NUMERICAL INTEGRATION METHODSIntroductionSingle-degree of Freedom SystemMulti-degree of Freedom SystemExplicit SchemesImplicit SchemesExample Problems and 83373813867.7.17.27.37.47.57.67.77.8ENGINEERING MECHANICSIntroductionNewtonian MechanicsNewton’s Laws of MotionResultants of Coplanar Force SystemsResultants of Non-coplanar Force SystemsEquilibrium of Coplanar Force SystemsEquilibrium of Non-coplanar Force SystemTrusses389–548389389389390391392394394

xiv ——— 97.207.21Analysis of BeamsFrictionFirst Moments and CentroidsVirtual WorkKinematics of a ParticleD’Alembert’s PrincipleKinematics of a Rigid Body in Plane MotionMoments of InertiaDynamics of a Rigid Body in Plane MotionWork and EnergyImpulse and MomentumThree-dimensional MechanicsExample Problems and 8.218.228.23MECHANICAL VIBRATIONSIntroductionClassification of VibrationsElementary Parts of Vibrating SystemsDiscrete and Continuous SystemsVibration AnalysisComponents of Vibrating SystemsFree Vibration of Single Degree of Freedom SystemsForced Vibration of Single-degree of Freedom SystemsHarmonic FunctionsTwo-degrees of Freedom SystemsMulti-degree of Freedom SystemsFree Vibration of Damped SystemsProportional DampingGeneral Viscous DampingHarmonic ExcitationsModal Analysis for Undamped SystemsLagrange’s EquationPrinciple of Virtual WorkD’Alembert’s PrincipleLagrange’s Equations of MotionVariational PrinciplesHamilton’s PrincipleExample Problems and 84585585585585586634638647–648649–665

CHAPTER1Matlab Basics1.1 INTRODUCTIONThis chapter is a brief introduction to MATLAB (an abbreviation of MATrix LABoratory) basics, registeredtrademark of computer software, version 4.0 or later developed by the Math Works Inc. The software is widelyused in many of science and engineering fields. MATLAB is an interactive program for numerical computationand data visualization. MATLAB is supported on Unix, Macintosh and Windows environments. For moreinformation on MATLAB, contact The MathWorks.Com. A Windows version of MATLAB is assumed here.The syntax is very similar for the DOS version.MATLAB integrates mathematical computing, visualization, and a powerful language to provide a flexibleenvironment for technical computing. The open architecture makes it easy to use MATLAB and its companionproducts to explore data, create algorithms and create custom tools, that provide early insights and competitiveadvantages.Known for its highly optimized matrix and vector calculations, MATLAB offers an intuitive language forexpressing problems and their solutions both mathematically and visually. Typical uses include: Numeric computation and algorithm development.Symbolic computation (with the built-in Symbolic Math functions).Modeling, simulation and prototyping.Data analysis and signal processing.Engineering graphics and scientific visualization.In this chapter, we will introduce the MATLAB environment. We will learn how to create, edit, save, run anddebug M-files (ASCII files with series of MATLAB statements). We will see how to create arrays (matricesand vectors), and explore the built-in MATLAB linear algebra functions for matrix and vector multiplication,dot and cross products, transpose, determinants and inverses, and for the solution of linear equations.MATLAB is based on the language C, but is generally much easier to use. We will also see how to programlogic constructs and loops in MATLAB, how to use subprograms and functions, how to use comments (%)for explaining the programs and tabs for easy readability, and how to print and plot graphics both two andthree dimensional. MATLAB’s functions for symbolic mathematics are presented. Use of these functions toperform symbolic operations, to develop closed form expressions for solutions to algebraic equations, ordinary

2 ——— MATLAB: An Introduction with Applicationsdifferential equations, and system of equations was presented. Symbolic mathematics can also be used todetermine analytical expressions for the derivative and integral of an expression.1.1.1 Starting and Quitting MATLABTo start MATLAB click on the MATLAB icon or type in MATLAB, followed by pressing the enter or returnkey at the system prompt. The screen will produce the MATLAB prompt (or EDU ), which indicates thatMATLAB is waiting for a command to be entered.In order to quit MATLAB, type quit or exit after the prompt, followed by pressing the enter or return key.1.1.2 Display WindowsMATLAB has three display windows. They are1. A Command Window which is used to enter commands and data to display plots and graphs.2. A Graphics Window which is used to display plots and graphs.3. An Edit Window which is used to create and modify M-files. M-files are files that contain aprogram or script of MATLAB commands.1.1.3 Entering CommandsEvery command has to be followed by a carriage return cr (enter key) in order that the command can beexecuted. MATLAB commands are case sensitive and lower case letters are used throughout.To execute an M-file (such as Project 1.m), simply enter the name of the file without its extension (as inProject 1).1.1.4 MATLAB ExpoIn order to see some of the MATLAB capabilities, enter the demo command. This will initiate the MATLABEXPO. MATLAB EXPO is a graphical demonstration environment that shows some of the different types ofoperations which can be conducted with MATLAB.1.1.5 AbortIn order to abort a command in MATLAB, hold down the control key and press c to generate a local abort withMATLAB.1.1.6 The Semicolon (;)If a semicolon (;) is typed at the end of a command, the output of the command is not displayed.1.1.7 Typing %When per cent symbol (%) is typed in the beginning of a line, the line is designated as a comment. When theenter key is pressed, the line is not executed.1.1.8 The clc CommandTyping clc command and pressing enter cleans the command window. Once the clc command is executed, aclear window is displayed.1.1.9 HelpMATLAB has a host of built-in functions. For a complete list, refer to MATLAB user’s guide or refer to theon-line Help. To obtain help on a particular topic in the list, e.g., inverse, type help inv.

MATLAB Basics ——— 31.1.10 Statements and VariablesStatements have the form variable expressionThe equals (“ ”) sign implies the assignment of the expression to the variable. For instance, to enter a 2 2matrix with a variable name A, we write A [1 2 ; 3 4] 〈ret〉The statement is executed after the carriage return (or enter) key is pressed to displayA 12341.2 ARITHMETIC OPERATIONSThe symbols for arithmetic operations with scalars are summarized below in Table 1.1.Table 1.1Arithmetic operationAdditionSubtractionMultiplicationRight divisionLeft divisionExponentiationSymbol –*/\ Example6 3 96–3 36 * 3 186/3 26\3 3/6 1/26 3 63 2161.3 DISPLAY FORMATSMATLAB has several different screen output formats for displaying numbers. These formats can be found bytyping the help command: help format in the Command Window. A few of these formats are shown in Table 1.2for 2π.Table 1.2 Display formatsCommandformat shortformat longformat short eformat long eformat short gDescriptionFixed-point with 4decimal digitsFixed-point with 14decimal digitsScientific notation with 4decimal digitsScientific notation with 15decimal digitsBest of 5 digit fixed orfloating pointExample 351/7ans 50.1429 351/7ans 50.14285714285715 351/7ans 5.0143e 001 351/7ans 5.014285714285715e001 351/7ans 50.143Contd.

4 ——— MATLAB: An Introduction with Applications 351/7ans 50.1428571428571 351/7format bankans 50.14format compact Eliminates empty lines to allow more lines with informationdisplayed on the screenAdds empty lines (opposite of compact)format looseformat long gBest of 15 digit fixed orfloating pointTwo decimal digits1.4 ELEMENTARY MATH BUILT-IN FUNCTIONSMATLAB contains a number of functions for performing computations which require the use of logarithms,elementary math functions and trigonometric math functions. List of these commonly used elementaryMATLAB mathematical built-in functions are given in Tables 1.3 to 1.8.Table 1.3 Common math ptionComputes the absolute value of x.Computes the square root of x.Rounds x to the nearest integer.Rounds (or truncates) x to the nearest integer toward 0.Rounds x to the nearest integer toward – .Rounds x to the nearest integer toward .Returns a value of –1 if x is less than 0, a value of 0 if x equals 0,and a value of 1 otherwise.Returns the remainder of x/y. for example, rem(25, 4) is 1, andrem(100, 21) is 16. This function is also called a modulus function.Computes ex, where e is the base for natural logarithms, orapproximately 2.718282.Computes ln x, the natural logarithm of x to the base e.Computes log10 x, the common logarithm of x to the base 10.Table 1.4 Exponential ptionExponential (ex)Natural logarithmBase 10 logarithmSquare root

MATLAB Basics ——— 5Table 1.5 Trigonometric and hyperbolic ionComputes the sine of x, where x is in radians.Computes the cosine of x, where x is in radians.Computes the tangent of x, where x is in radians.Computes the arcsine or inverse sine of x, where x must be between –1 and 1.The function returns an angle in radians between –π/2 and π/2.acos(x)Computes the arccosine or inverse cosine of x, where x must be between–1 and 1. The function returns an angle in radians between 0 and π.atan(x)Computes the arctangent or inverse tangent of x. The function returns anangle in radians between –π/2 and π/2.atan2(y,x) Computes the arctangent or inverse tangent of the value y/x. The functionreturns an angle in radians that will be between –π and π, depending on thesigns of x and y.sinh(x)cosh(x)tanh(x)asinh(x)acosh(x)atanh(x)ex e x.2ex e xComputes the hyperbolic cosine of x, which is equal to.2sinh xComputes the hyperbolic tangent of x, which is equal to.cosh xComputes the inverse hyperbolic sine of x, which is equal toln x x2 1 . Computes the inverse hyperbolic cosine of x, which is equal toln x x 2 1 . Computes the hyperbolic sine of x, which is equal toComputes the inverse hyperbolic tangent of x, which is equal to lnfor x 1.Table 1.6 Round-off functionsFunctionround(x)DescriptionRound to the nearest integerfix(x)Round towards zeroceil(x)Round towards infinityfloor(x)Round towards minus infinityrem(x,y)Returns the remainder after x is divided by ysign(x,y)Signum function. Returns 1 if x 0, –1 if x 0,and 0 if x 0.Example round(20/6)ans 3 fix(13/6)ans 2 ceil(13/5)ans 3 floor(–10/4)ans –3 rem(14,3)ans 2 sign(7)ans 11 x1 x

6 ——— MATLAB: An Introduction with ApplicationsTable 1.7 Complex number functionsFunctionDescriptionconj(x)Computes the complex conjugate of the complex number x. Thus, ifx is equal to a ib, then conj(x) will be equal to a – ib.angle(x) Computes the real portion of the complex number x.real(x) Computes the imaginary portion of the complex number x.imag(x) Computes the absolute value of magnitude of the complex number x.abs(x)Computes the angle using the value of atan2(imag(x), real(x)); thus,the angle value is between –π and π.Table 1.8 Arithmetic operations with complex numbersOperationResultc1 c2(a1 a2) i(b1 b2)c1 c2(a1 – a2) i(b1 – b2)c1 y c2(a1a2 – b1b2) i(a1b2 – a2b1)c1c2a1a2 c1 a12c1*a22b1b2b22ia2b1 b2 a1a22 b22b12 (magnitude or absolute value of c1)a1 – ib1 (conjugate of c1)(Assume that c1 a1 ib1 and c2 a2 ib2.)1.5 VARIABLE NAMESA variable is a name made of a letter or a combination of several letters and digits. Varia

foundation of basic MATLAB applications in engineering problem solving, the book provides opportunities to explore advanced topics in application of MATLAB as a tool. An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLAB commands. MATLAB is considered as the software of choice. MATLAB can be used .

Related Documents:

19 MATLAB Excel Add-in Hadoop MATLAB Compiler Standalone Application MATLAB deployment targets MATLAB Compiler enables sharing MATLAB programs without integration programming MATLAB Compiler SDK provides implementation and platform flexibility for software developers MATLAB Production Server provides the most efficient development path for secure and scalable web and enterprise applications

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for algebra, plotting, calculus, and solving differential .

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for

3. MATLAB script files 4. MATLAB arrays 5. MATLAB two‐dimensional and three‐dimensional plots 6. MATLAB used‐defined functions I 7. MATLAB relational operators, conditional statements, and selection structures I 8. MATLAB relational operators, conditional statements, and selection structures II 9. MATLAB loops 10. Summary

I. Introduction to Programming Using MATLAB Chapter 1: Introduction to MATLAB 1.1 Getting into MATLAB 1.2 The MATLAB Desktop Environment 1.3 Variables and Assignment Statements 1.4 Expressions 1.5 Characters and Encoding 1.6 Vectors and Matrices Chapter 2: Introduction to MATLAB Programming 2.1 Algorithms 2.2 MATLAB Scripts 2.3 Input and Output

Compiler MATLAB Production Server Standalone Application MATLAB Compiler SDK Apps Files Custom Toolbox Python With MATLAB Users With People Who Do Not Have MATLAB.lib/.dll .exe . Pricing Risk Analytics Portfolio Optimization MATLAB Production Server MATLAB CompilerSDK Web Application

Lecture 14: MATLAB I “Official” Supported Version in CS4: MATLAB 2018a How to start using MATLAB: CS Dept. Machines - run ‘cs4_matlab’ Total Academic Handout (TAH) Local Install - software.brown.edu MATLAB Online (currently 2019a) - matlab.mathworks.com Navigating the Workspace (command window, variables, etc.) Data types in MATLAB (everything is a 64-bit .

since 2012. The third and final year of the strategy provided a good opportunity for us . to take stock of what we as nurses, midwives and care staff have achieved through the strategy and how we have contributed to ensuring high quality, compassionate care. This means not only thinking about this final year, but also reflecting on the last three years as a whole. I have been privileged to .