fundamentals of matlab - content.kopykitab.com€¦ · fundamentals of matlab dt. a.s.aravinda...

21

Upload: others

Post on 20-Jul-2020

33 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted
Page 2: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

Fundamentals of MATLAB

Page 3: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

Fundamentals of

MATLAB

Dr. A.S. Aravinda MurthyProfessor in Electrical Engineering (Retired)

The National Institute of EngineeringMysore.

SANGUINE

Note to the User: while reducing the size, Accordingly reduce the stroke size also, for a proportionate reduction.

Sanguine Technical PublishersBangalore.

2014

(With Application to Electrical Engineering)

Page 4: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

Fundamentals of MATLABDt. A.S.Aravinda Murthy

This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted with permission, and sources are indicated. Reasonable efforts have been made to publish reliable data and information, but the author and the publisher cannot assume responsibility for the validity of all materials or for the consequences of their use.

Neither this book nor any part may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, microfilming and recording, or by any information storage or retrieval system, without prior remission in writing from the publishers.

The consent of SANGUINE TECHNICAL PUBLISHERS does not extend to copying for general distribution, for promotion, for creating new works, or for resale. Specific permission must be obtained in writing from SANGUINE for such copying.

The export rights of this book are vested solely with the publisher.

Direct inquiries: E-mail [email protected]. Visit our website at www.sanguineindia.com

© 2014 by Sanguine Technical Publishers, Bangalore – 560 016.

Published by Lal Prasad for Sanguine.Production Editor: R.Subramanian.Printed in India.

Price: ̀ 425.00

ISBN 978 9383506 24 8

Page 5: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

This book is dedicated to

My beloved sons Amshumanth and Abhijith

Page 6: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted
Page 7: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

i

Foreword

There is a great churning of various issues related to academic programs the worldover. This is mainly due to changes in expectations, rapidly impacting global Cli-matic and Socio-Economic factors and above all a sense of “saturation” of contentin many disciplines. At the same time, the domination of ICT tools and techniqueshave reshaped the Teaching-Learning process in subjects as diverse as Medicineand Archaeology too. There is no doubt, Engineering in general and in that, CircuitBranches (Electrical, Electronics, Computer Sciences, Information sciences, etc)have been the recipient of maximum beneficiaries of the changes in ICT domain.These changes are not without some long term negative consequences. These rangefrom overdependence on Information and Communication Technology (ICT) toolsat one end to neglect / limited emphasis on strong (pedagogic) basics at the other.Thus there is an urgent need for this to be addressed and not many are equippedto do this appropriately. This book is one such attempt, done by the author whohas over 40 years of teaching experience. In some sense it reflects his own journey,where he started with emphasis on strong basics in Electrical Engineering and at theclosing stages of his formal career he had to use state of art ICT tools to do researchin the same discipline . Thus he has successfully journeyed the change which iscaptured in this book. What is this book all about? The best way to explain this is“Back to the Future”. This aspect of looking back and redefining future course ofaction is being done successfully in many facets of Academics. Thus it is neces-sary to do two things; One of looking back to reemphasize on basics (pedagogic)aspects of the discipline and other is to move forward using ICT tools. Needless toadd, only the very mature, competent, expereinced and concerned people can do,and this Author is definitely one among them. The author while focusing on useof MATLAB in basic aspects of Electrical Engineering, has done a splendid taskof picking the right topics that constitute for richer understanding of the subject ofElectrical Engineering. The core of this discipline being; Circuits, Machines andPower Systems. These three major aspects of Electrical Engineering have been ex-plained in rich detail using MATLAB as an Enabler. Given the fact that MATLAB

Page 8: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

ii

and other “cousins” of MATLAB are widely prevalent in all Electrical Engineeringprograms the world over, this book enables faculty to teach more effectively andstudents to learn more comprehensively. Interestingly this book subtly addresses(even if it is limited to EE discipline) an even more challenging issue of improvingTeaching-Learning process. While it may be difficult to find all the content of thisbook in a one semester course, it definitely can be used as a “companion” to EEprogram, since the contents here can be found in courses typically spread over 3-4semesters. It is even more useful to people doing projects, implementing ideas andattempting to do research. Thus it is little beyond being just a text book. It has beenmy privilege to write the foreword to this book, because the author was my teacherwho taught (excellently) me electrical machines three decades back. Strangely hedid research with me a decade back using ICT tools in EE. Further to add, the authorhails from a family of distinguished teachers in Mysore University for over sevendecades. This book is a welcome break in style and emphasis among the many goodbooks in the current market. I am confident it will have a long shelf life. I look for-ward to its use by the Electrical Engineering fraternity and await the feedback fromits users.

08 - 08 - 2014 Dr.Ashok RaoMysore Former Head, Network Project

CEDT, Indian Institute of ScienceBangalore, INDIA

Page 9: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

iii

Preface

MATLAB is a software tool (considered as the abbreviation of ’MATrix LABo-ratory’) whereas Electrical Engineering (EE) is a specific branch of engineering.When the context is the study of electrical engineering, a noteworthy feature isthat the paradigm of study has qualitative aspects conveying the concepts throughfundamental principles and postulates which are well supported by analytical andgraphical investigation. The nature of MATLAB with its immense graphics, compu-tational and presentation capabilities along with simulation and animation optionsmakes it a perfect match as a useful tool for carrying out such analytical and graph-ical investigation. Chronologically, long hand calculation was followed by sliderule which in due course was replaced by pocket calculators. The advent of digitalcomputers and development of programming languages changed the computationalcapabilities tremendously. Among such software tools, MATLAB suits nicely foruse in the field of Electrical Engineering.

The study of an EE system broadly has a definite pattern - the physical features ofthe system and the basic principle of operation followed by a detailed analysis. Inthis context an EE system may be associated with a set of parameters, input vari-ables and output variables. Parameters are generally those which are fixed depend-ing upon the physical properties and attributes of the system. Response produced inthe system when an input is given and the input itself are together called the systemvariables. A system can be a multiple input multiple output (MIMO) system too.A specific variable in the generated response is designated as the output variable.(For example, in as simple an example as an electric iron box, the resistance of thecoil, weight of the box are parameters while the input voltage and frequency are theinput variables and the heat generated is the output variable. In an electric motor,electromagnetic torque is produced on the rotating member as well as heat in theiron and copper parts of the motor. But, the torque is designated as the output andthe heat,as loss).

System analysis can be summarised as studying the behaviour of the system byobserving the manner of variation of the output variables for changes in the in-

Page 10: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

iv

put variables and or the system parameters. During this process, the mathematicalmodelling of the system is formed which may be a differential equation, algebraicequation, linear equation, non linear equation, multiple equations expressed in amatrix form in all of which there is a relationship between the input variables (andor their derivatives), output variables (and or their derivatives) and the parameters.The mathematical analysis of an electrical system is generally preceded by its cir-cuit model. In fact formulating an appropriate circuit model befitting a requiredanalysis is a key feature of studying an electrical system. The circuit model is usu-ally made up of a combination of linear, lumped, finite, passive, bilateral elements,dependant and/or independant voltage and/or current sources. It is possible thatthe circuit represents an analogous circuit of a non electrical system or an elec-tromechanical system in which case evaluation of the electrical variable directlyevaluates the analogous non electrical variable. For example, an induction motor,an electromechanical device, has an electrical equivalent circuit. The mechanicalpower developed is associated with the power consumed by a resistor in the circuitmodel. In general, performance equations are obtained for the circuit using basiccircuit principles. These equations may be algebraic or integrodifferential in nature,linear or non linear. The solution for a particular set of independant variables enablethe determination of the dependant variables. The solution may some times requirean iterative computation as in a major topic of study ’Load Flow Analysis’ . Theresult may be required for a range of input - for example in another major topic ofstudy - ’Stabilty Analysis’, the variation of a variable called the power angle is stud-ied over a range of (input) time interval. Depending upon the size and number ofvariables, the mathematical modelling may require matrix representation requiringmatrix algebra for computation. Some times a graphical presentation of the resultmay be preferable to a tabular form. In general, the study of a given system re-quires a unique mathematical method of analysis as applicable to a specific context.In this background, MATLAB is an appropriate software tool for evaluation andpresentation of the results.Among the several useful features of MATLAB, the availability of a large set ofbuilt in functions is a unique one. For example, the roots of a quadratic equation

Page 11: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

v

aX2 +bX + c = 0 is classically obtained by evaluating X1,X2 =−b± b2−4ac2a , for a

given set of numerical values of a,b,c. Actually this is what is taught to a studentat an entry level to roots of a quadratic equation. However, when determining theroots is a part of a bigger compuation at a higher level, it is just enough to use thebuilt in function ’roots’ in MATLAB. Typing X = roots ([a b c]) in the command

window (numerical values of a,b,c) displays a column vector X =

[X1

X2

](without

the square brackets). While the example is extremely elementary, it conveys the factthat invoking a built in function in MATLAB greatly simplifies the computations.The principle is equally valid for a variety of much more complex mathematicalcomputations.

In this book an attempt is made to show the utility of MATLAB for the computa-tional aspects in hard core electrical engineering subjects such as Circuits, Machinesand Power Systems. The first chapter gives an elementary treatise on MATLAB fol-lowed by application to electrical engineering in the subsequent chapters. It wouldbe appropriate to mention that the topics covered are only illustrative since each ofthe subject by itself is a vast field of study. To the extent felt necessary a brief back-ground is given for each topic. While Electrical Machines traditionally include DCMachines in addition to Transformers, Induction and Synchronous Machines, theDC Machines seem to be receiving a lot less importance with the advent of staticconverters and sophisticated and precise speed control mechanisms for InductionMotors; as such DC Machines are excluded in the book. It is hoped that the user,be it the teacher or the taught, appreciate the capability of MATLAB to analyse thesystem performance for multitudes of variation of system variables and parameters,and help gain a deep insight into the qualitative aspects of performance, and getmotivated to pursue higher levels of learning in these areas.

LABVIEW is another computing and simulation software often compared withMATLAB. While at some quarters there seems to be a feeling that the advent ofLABVIEW is driving MATLAB to the back seat, it is quite far from truth. It wouldbe just unfair to judge one to be better than the other for all situations of computingand simulation. The following link gives an excellent logical and scientific compar-

Page 12: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

vi

ison of the two in a very convincing way. The paper has taken a couple of yardsticksfor comparison and with a number of examples shown the relative advantage of oneover the other.http://annals.fih.upt.ro/pdf-full/2012/ANNALS-2012-3-68.pdf

Dated: 08 - 08 - 2014 Dr.A.S.Aravinda MurthyMysore

Page 13: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

Contents

Contents vii

1 Fundamental Aspects 11.1 Principle Windows . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Creating vectors and matrices . . . . . . . . . . . . . . . . . . . . . 5

1.3 Basic Mathematical operations . . . . . . . . . . . . . . . . . . . . 8

1.4 Basic Mathematical Functions . . . . . . . . . . . . . . . . . . . . 14

1.5 Conditional Operators . . . . . . . . . . . . . . . . . . . . . . . . . 19

1.6 Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

1.7 Function File & Inline Function . . . . . . . . . . . . . . . . . . . . 40

1.8 Plotting 2D Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 42

1.9 Subscripted variables . . . . . . . . . . . . . . . . . . . . . . . . . 55

1.10 Solution of equations . . . . . . . . . . . . . . . . . . . . . . . . . 61

1.11 Solution of Differential Equations . . . . . . . . . . . . . . . . . . 67

1.12 Residue Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . 70

1.13 Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

1.14 Differentiation and Integration . . . . . . . . . . . . . . . . . . . . 81

1.15 More about Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

1.16 Symbolic Mathematics . . . . . . . . . . . . . . . . . . . . . . . . 93

1.17 GUI and Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . 101

2 MATLAB and Electric Circuits 105

vii

Page 14: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

viii CONTENTS

2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

2.2 Solving for currents and voltages . . . . . . . . . . . . . . . . . . . 106

2.2.1 General Background . . . . . . . . . . . . . . . . . . . . . 106

2.2.2 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

2.2.3 Complete Programme for solution of network . . . . . . . . 132

2.2.4 Further Applications . . . . . . . . . . . . . . . . . . . . . 152

2.3 Transients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

2.3.1 DC Transient - Step Response . . . . . . . . . . . . . . . . 152

2.3.2 AC Transient - Sinusoidal Input . . . . . . . . . . . . . . . 155

2.4 Locus Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

2.5 Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . 163

2.6 Network Theorems . . . . . . . . . . . . . . . . . . . . . . . . . . 169

2.6.1 Thevenin Theorem: . . . . . . . . . . . . . . . . . . . . . . 169

2.6.2 Millman Theorem: . . . . . . . . . . . . . . . . . . . . . . 174

2.6.3 Maximum Power Transfer Theorem: . . . . . . . . . . . . . 177

2.6.4 Tellegen’s Theorem . . . . . . . . . . . . . . . . . . . . . . 180

2.7 Two Port Parameters . . . . . . . . . . . . . . . . . . . . . . . . . 184

2.7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . 184

2.7.2 ABCD Parameters . . . . . . . . . . . . . . . . . . . . . . 185

2.8 Symmetrical Components . . . . . . . . . . . . . . . . . . . . . . . 188

2.9 Fourier Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

2.10 Node Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

2.10.1 Star Delta Transformation . . . . . . . . . . . . . . . . . . 208

2.10.2 Matrix Method of node elimination . . . . . . . . . . . . . 210

3 MATLAB and Power System 2173.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

3.2 Per Unit System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

3.2.1 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . 219

3.2.2 Illustration . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

3.3 Bus Admittance Matrix . . . . . . . . . . . . . . . . . . . . . . . . 228

Page 15: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

CONTENTS ix

3.3.1 Y Bus Formation - Method of inspection . . . . . . . . . . 232

3.3.2 Method of Singular Transformation . . . . . . . . . . . . . 235

3.4 Load Flow Analysis, Gauss Seidal Method . . . . . . . . . . . . . . 240

3.5 Power Flow Calculation . . . . . . . . . . . . . . . . . . . . . . . . 251

3.6 Unsymmetrical Fault Analysis . . . . . . . . . . . . . . . . . . . . 259

3.7 Load Flow Analysis, Newton Raphson Method . . . . . . . . . . . 269

3.7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . 269

3.7.2 Jacobian . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

3.7.3 Newton Raphson Method . . . . . . . . . . . . . . . . . . . 278

3.8 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

3.8.1 Classification . . . . . . . . . . . . . . . . . . . . . . . . . 286

3.8.2 System Analysis . . . . . . . . . . . . . . . . . . . . . . . 288

4 MATLAB and Transformer 2994.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

4.2 The OC, SC Test and the Equivalent Circuit . . . . . . . . . . . . . 301

4.3 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

4.3.1 Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

4.3.2 Regulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 312

4.3.3 Parallel Operation . . . . . . . . . . . . . . . . . . . . . . . 321

4.4 Polyphase Connection -Scott Connection . . . . . . . . . . . . . . . 332

5 MATLAB and Induction Motor 3395.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339

5.2 Method of Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 341

5.3 No load and Blocked Rotor tests . . . . . . . . . . . . . . . . . . . 343

5.4 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

5.5 Starting and Speed Control . . . . . . . . . . . . . . . . . . . . . . 355

5.5.1 Motor - Load Dynamics . . . . . . . . . . . . . . . . . . . 356

5.5.2 Starting Speed time curve . . . . . . . . . . . . . . . . . . . 360

5.5.3 Speed Control . . . . . . . . . . . . . . . . . . . . . . . . . 362

Page 16: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

x CONTENTS

5.5.4 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367

6 MATLAB and Synchronous Machine 3776.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3776.2 Generated EMF . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3796.3 Regulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3826.4 Syn.Gen. on Infinite Bus . . . . . . . . . . . . . . . . . . . . . . . 386

6.4.1 Variable excitation-Constant Power . . . . . . . . . . . . . 3866.4.2 Power Angle Diagram . . . . . . . . . . . . . . . . . . . . 3916.4.3 Salient Pole Generator . . . . . . . . . . . . . . . . . . . . 3956.4.4 Armature current Locus . . . . . . . . . . . . . . . . . . . . 402

Bibliography 409

Index 411

Page 17: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

Chapter 1

Fundamental Aspects

1.1 Principle Windows

While the entry to a home is through a door, let us enter MATLAB through itswindows !!! . After launching MATLAB, in order to plan, execute and obtainresults for a specific analysis, there are dedicated display screens with associatedtask bars. These are called the windows. Command window, Editor window andthe Graphics window may be considered as the principle windows. Workspace maybe considered as the the area where the variables are formed when a MATLABprogramme is run.

Command window of MATLAB is the principle screen area where the input andoutput variables as well as the MATLAB commands are displayed. Commands as-signing values to the input variables and the programming commands can be typedon the command window directly and are automatically saved in the command his-tory with an option to clear the same if required. For example, to calculate 20×10,like in a calculator, it is just enough to type in the command window

20*10

and hit the enter key (* is the multiplication operator). The display would read

answer = 200

Alternatively, the following lines may be typed in the command window (pressing

1

Page 18: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

2 CHAPTER 1. FUNDAMENTAL ASPECTS

the enter key moves the cursor to the next line; therefore in the following lines, enterkey is pressed after typing the semicolon symbol (;) at the end of each of the lines).

x = 10;

y = 20∗ x;

To see the result,

y

is typed and the enter key pressed. The display would read as

y = 200

A semicolon at the end of a line suppresses the display of the output. In the aboveexample, if the semicolon after the line 2 is not typed, the result automaticallydisplays

y = 200

and typing y again to see the result would not be necessary.

Editor window is the area where programmes are written and saved as ’ m’ files(file extension is .m; for example a file by name ’test’ is saved as test.m). UsuallyMATLAB is accompanied by an editor. However a suitable text editor such as NotePad or Geany can also be used provided the file is saved as what is called a ’scriptfile’ with a .m extension. When the running of a programme generates a figure, agraphics window automatically appears showing the display of the figure. The samecan be saved with a .fig extension. With a suitable command, the figure can alsobe saved in other graphics editors like scalable vector graphics (svg). Relativelysimple computations can be made directly on the command window. However,it is is advantageous to create a ’script file’ in the editor and run the same in thecommand window. A script file by name say test.m can be run in the commandwindow by just typing the name of the file without the . extension. Thus, to run thescript file test.m, it is just necessary to type ’test’ (without quotes) on the commandwindow. After looking at the results in the command window, the script file can beeasily modified, saved and rerun for getting modified results.

The structure of a script file is usually as follows:

1.Clearing statements.

Page 19: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

1.1. PRINCIPLE WINDOWS 3

2. Assignment of values of input variables and constants3. Sequential logical commands to simulate the mathematical model4. Obtain the display of the output in the required format, graphical or otherwise.1. One of the clearing statements, clc effectively makes the screen look like a cleanslate, removing any existing display. The other statement, clear all removes all thevariables and functions from workspace. These two commands are invariably thecommenecing statements in a script file.2. The assignment of variables can be made in two ways. The value of the inputis assigned to a particular variable by predefining it or defining the same whileassigning the value. For example, if v is the voltage input with a numerical valueof 10 volts, one way of giving the input is by typing the following two lines in theeditor and saving it as, say, test.m file.% x is the input voltagex = 10;In MATLAB, a % operator indicates only a comment. Thus, the first of the previoustwo lines only defines x as the input voltage. In the second line, the voltage x isassigned a numerical value of 10 volts. In fact, depending upon the situation, thevariable x may be a scalar, vector or a matrix and may be either real or complex.In the other method of giving the input, the basic command isx = input(’value of voltage, in volts is’)When the programme is run, display appears asvalue of voltage, in volts is ;and waits for the numerical value to be entered. Upon entering 10 and hitting theenter key, x is assigned the entered value of 10 and the display appears asvalue of voltage, in volts is 10Upon typing x, the value assigned to it displayed asx = 103. Sequential logical commands is the heart of the main programme. It is an orderlycombination of arithmetic, algebraic, trigonometric and such other mathematicalprocessing along with logical statements and built in functions. Variables otherthan the input are generated during this process and a specific variable is associated

Page 20: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

4 CHAPTER 1. FUNDAMENTAL ASPECTS

with the desired output. As a trivial example, if y = 20x is an amplified voltage, thecommand to be typed, is

y = 20∗ x

4. Obtaining the display can be either in a graphical form or a tabular form whenthe values of output are obtained for several values of input. Considering y as theoutput in the example under consideration, the following pair of lines are to be typedfor the display of output.

output = y

output

The complete script to be saved as test.m is as follows

clear all

clc

x = input(’value of voltage, in volts is’);

y = 20∗ x ;

output = y;

output;

To run the script file, the name of the file without the .m extension is typed in thecommand window. In the present case,

test

is typed on the command window

The display on the screen would be

value of voltage, in volts is

The desired value of the voltage is typed and the enter key pressed; In the presentcase

10

is typed and the enter key pressed

MATLAB would perform the remaining steps in the programme.

To see the output, the following line is typed and the enter key pressed.

output

The display on the screen would be

Page 21: Fundamentals of MATLAB - content.kopykitab.com€¦ · Fundamentals of MATLAB Dt. A.S.Aravinda Murthy This book contains information obtained from authentic and highly regarded sources.Reprinted

Fundamentals Of MATLAB

Publisher : Sanguine Publishers ISBN : 9789383506248 Author : Dr. A S AravindaMurthy

Type the URL : http://www.kopykitab.com/product/6004

Get this eBook

50%OFF