Introduction To Matlab: Application To Electrical Engineering

3y ago
30 Views
7 Downloads
2.34 MB
98 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Matteo Vollmer
Transcription

Introduction to Matlab:Application to ElectricalEngineeringHoussem Rafik El Hana BouchekaraUmm El Qura University(version 1, Februray 2011)1

Contents1CHAPTER 1 . 71.1TUTORIAL LESSONS 1 . 71.1.11.2STARTING AND QUITTING MATLAB . 81.2.1Starting MATLAB . 81.2.2Quitting MATLAB . 81.3MATLAB DESKTOP. 81.4DESKTOP TOOLS . 101.4.1Command Window . 101.4.2Command History . 111.4.3Launch Pad . 121.4.4Help Browser . 121.4.5Current Directory Browser . 131.4.6Workspace Browser. 141.4.7Editor/Debugger . 161.5GETTING STARTED . 171.5.1Using MATLAB as a calculator. 171.5.2Creating MATLAB variables . 181.5.3Overwriting variable . 191.5.4Error messages . 191.5.5Making corrections . 191.5.6Controlling the hierarchy of operations or precedence . 191.5.7Controlling the appearance of floating point number. 211.5.8Managing the workspace . 211.5.9Keeping track of your work session . 221.5.10Entering multiple statements per line . 221.5.11Miscellaneous commands . 221.5.12Getting help . 231.62Introduction . 7EXERCISES. 23CHAPTER 2 . 242.1MATHEMATICAL FUNCTIONS . 242

2.1.12.2Overview. 262.2.2Creating simple plots . 262.2.3Adding titles, axis labels, and annotations . 272.2.4Multiple data sets in one plot . 282.2.5Specifying line styles and colors . 292.2.6Copy/Paste Figures . 312.2.7Saving Figures . 322.3EXERCISES. 322.4ANIMATIONS . 332.4.1Erase Mode Method . 332.4.2Creating Movies . 34WORKING WITH MATRICES . 352.5.1Introduction . 352.5.2Matrix generation . 352.6EXERCISES. 45CHAPTER 3: ARRAY OPERATIONS AND LINEAR EQUATIONS . 463.1ARRAY OPERATIONS . 463.1.1Matrix arithmetic operations . 463.1.2Array arithmetic operations . 463.2SOLVING LINEAR EQUATIONS . 473.2.1Matrix inverse. 493.2.2Matrix functions . 503.34BASIC PLOTTING . 262.2.12.53Examples . 25EXERCISES. 50CHAPTER 4: INTRODUCTION TO PROGRAMMING IN MATLAB . 514.1INTRODUCTION . 514.2M-FILE SCRIPTS . 514.2.1Examples . 514.2.2Script side-effects . 534.3M-FILE FUNCTIONS . 534.3.1Anatomy of a M-File function . 534.3.2Input and output arguments . 543

564.4INPUT/OUTPUT COMMANDS. 554.5EXERCISES. 58CHAPTER 5: CONTROL FLOW AND OPERATORS . 595.1INTRODUCTION . 595.2CONTROL FLOW . 595.2.1The ‘‘if.end’’ structure . 595.2.2Relational and logical operators . 605.2.3The ‘‘for.end’’ loop . 615.2.4The ‘‘while.end’’ loop . 625.2.5Other flow structures . 625.2.6Operator precedence . 625.3SAVING OUTPUT TO A FILE . 635.4EXERCISES. 63CHAPTER 6: DEBUGGING M-FILES . 646.1INTRODUCTION . 646.2DEBUGGING PROCESS . 646.2.1Preparing for debugging . 646.2.2Setting breakpoints . 646.2.3Running with breakpoints . 656.2.4Examining values . 656.2.5Correcting and ending debugging . 656.2.6Ending debugging. 656.2.7Correcting an M-file . 657APPENDIX A: SUMMARY OF COMMANDS . 678APPENDIX C: MAIN CHARACTERISTICS OF MATLAB. 7098.1HISTORY . 708.2STRENGTHS . 708.3WEAKNESSES . 708.4COMPETITION . 70BIBLIOGRAPHY . 714

Matlab is an interactive system for doing numerical computations. The aim of this book is to help thestudent to be familiar with Matlab. The emphasis here is "learning by doing".5

About the authorHoussem REH Bouchekara is an assistant professor in the electrical engineering department ofUmm Al-Qura University. He has received his BS in electrical engineering from University MentouriConstantine, Algeria, in 2004. He received his Master’s in Electronic Systems and Electrical Engineeringfrom Polytechnic School of the University of Nantes, France, 2005. He received his Ph.D. in ElectricalEngineering from Grenoble Electrical Engineering Laboratory, France, in 2008. His research interestincludes Electric machines, Magnetic refrigeration, and Power system.6

1 Chapter 11.1 Tutorial lessons 11.1.1 IntroductionThe primarily objective is to help you learn quickly the first steps. The emphasis here is “learning bydoing”. Therefore, the best way to learn is by trying it yourself. Working through the examples will give youa feel for the way that MATLAB operates. In this introduction we will describe how MATLAB handlessimple numerical expressions and mathematical formulas.The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to provide easyaccess to matrix software developed by the LINPACK (linear system package) and EISPACK (Eigen systempackage) projects.The basic building block in MATLAB is the matrix. The fundamental data type is the array. Vectors,scalars, real and complex matrices are all automatically handled as special cases of basic arrays. The builtin functions are optimized for vector operations. Thus, vectorized commands or codes run much faster inMATLAB (vectorization is a way of computing in which an operation is performed simultaneously on a listof numbers rather than sequentially on each member of the list).A nice thing to realize is that MATLAB is primarily a numerical computation package, although withthe 'Symbolic' Toolbox it can do also symbolic algebra. Mathematica, Maple, and Macsyma are primarilysymbolic algebra packages. MATLAB's ease of use is its best feature since you can have more learning withless effort, while the computer algebra systems have a steeper learning curve.In mathematical computations, especially those that utilize vectors and matrices, MATLAB is betterin terms of ease of use, availability of built-in functions, ease of programming, and speed. MATLAB'spopularity today has forced such packages as Macsyma and Mathematica to provide extensions for files inMATLAB's format.There are numerous prepared commands for 2D and 3D graphics as well as for animation. Theuser is not limited to the built-in functions; he can write his own functions in MATLAB language. Oncewritten, these functions work just like the internal functions. MATLAB's language is designed to be easy tolearn and use.The many built-in functions provide excellent tools for linear algebra, signal processing, dataanalysis, optimization, solution of ordinary differential equations (ODEs), and many other types of scientificoperations.There are also several optional 'toolboxes' available which are collections of functions written forspecial applications such as 'Image Processing', 'Statistics', 'Neural Networks', etc.The software package has been commercially available since 1984 and is now considered as astandard tool at most universities and industries worldwide.7

1.2 Starting and Quitting MATLAB1.2.1 Starting MATLABOn a Microsoft Windows platform, to start MATLAB, double-click the MATLAB shortcut icon onyour Windows desktop.On Linux, to start MATLAB, type matlab at the operating system prompt.After starting MATLAB, the MATLAB desktop opens – see “MATLAB Desktop”.You can change the directory in which MATLAB starts, define startup options including running ascript upon startup, and reduce startup time in some situations.1.2.2 Quitting MATLABTo end your MATLAB session, select Exit MATLAB from the File menu in the desktop, or type quitin the Command Window. To execute specified functions each time MATLAB quits, such as saving theworkspace, you can create and run a finish.m script.1.3 MATLAB DesktopWhen you start MATLAB, the MATLAB desktop appears, containing tools (graphical user interfaces)for managing files, variables, and applications associated with MATLAB.The first time MATLAB starts, the desktop appears as shown in the following illustration, althoughyour Launch Pad may contain different entries.8

Figure 1: The graphical interface to the MATLAB workspace.You can change the way your desktop looks by opening, closing, moving, and resizing the tools init. You can also move tools outside of the desktop or return them back inside the desktop (docking). All thedesktop tools provide common features such as context menus and keyboard shortcuts.You can specify certain characteristics for the desktop tools by selecting Preferences from the Filemenu. For example, you can specify the font characteristics for Command Window text. For moreinformation, click the Help button in the Preferences dialog box as shown in Figure 2.9

Figure 2: Customization1.4 Desktop ToolsThis section provides an introduction to MATLAB’s desktop tools. You can also use MATLABfunctions to perform most of the features found in the desktop tools. The tools are: Command Window”.Command History.Launch PadHelp Browser.Current Directory Browser.Workspace Browser.Array Editor.Editor/Debugger.1.4.1 Command WindowUse the Command Window to enter variables and run functions and M-files.10

Figure 3: Command Window.1.4.2 Command HistoryLines you enter in the Command Window are logged in the Command History window. In theCommand History, you can view previously used functions, and copy and execute selected lines.Figure 4: Command History.To save the input and output from a MATLAB session to a file, use the diary function.11

Running External ProgramsYou can run external programs from the MATLAB Command Window. The exclamation pointcharacter ! is a shell escape and indicates that the rest of the input line is a command to the operatingsystem. This is useful f

a feel for the way that MATLAB operates. In this introduction we will describe how MATLAB handles simple numerical expressions and mathematical formulas. The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to provide easy access to matrix software developed by the LINPACK (linear system package) and EISPACK (Eigen system

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

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 .

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 .