24 views

Uploaded by WesNamtrow

- RDS-300
- Introduction to Control Engineering Modeling, Analysis and Design - Ajit Mandal - 2006
- Introduction to Control Engineering ; Modeling, Analysis and Design - Ajit K. Mandal
- Flight Control Design – Best Practices
- 9UG
- Root Locus (1)
- control theory introduction
- FM_AG-08_TP-088-7
- New Microsoft Word Document (3)
- 7196082644337272
- Introduction to Adaptive Control
- Compensadores
- 00 Index
- The Performance Analysis Of Four Tank System for Conventional Controller and Hybrid Controller
- Module Report ME2142
- Quick Commissioning
- Rr220206 Control Systems
- ec2255-lp
- Final Project FinalReport VikasYADAV
- Controls PROJECT.pdf

You are on page 1of 7

MATLAB Tutorial

Introduction

The aim of this class is to introduce MATLAB to those who may not have used it before, and to

demonstrate specific functions from the control systems toolbox that are particularly useful in control

engineering.

MATLAB 6.1 is found as an icon on the

MENG desktop – double click to start…

prompt…

keys in the command window to reuse them.

You can also drag and drop commands from

the history to the command window

B M Hanson, email b.hanson@ucl.ac.uk

Course web page: http://www.meng.ucl.ac.uk/~b_hanson/MECH3005.htm

Simple Arithmetic

Work through the following exercises to give you a taster of some of the MATLAB commands

and to get you used to the user interfaces. This exercise will help you when you come to do the

examples on which this course is assessed.

Start with some basic commands and record what you see in the boxes below.

1. MATLAB can do sums like a calculator

MATLAB output:

2. Notice that the output says ans= 8 (for the first example). What MATLAB does is assign the

answer to the variable ans (by default). This is very useful as you can now use ans for further

calculations. Try the following and record the output (note that spaces are ignored here):

MATLAB output:

3. So you get the first answer, add 3 with the second command and add 5 more with the

third command. As well as the default variable ans, you can assign your own variables. Try out

the following sequence (note 6.3 x 106 is entered using “e” for exponent):

MATLAB

output:

So the escape velocity you have calculated (in m/s incidentally) is stored in the variable

escape_velocity. You do need to be careful with variable names – you wouldn’t call a variable

pi as MATLAB would get confused with its internal value of pi. MATLAB has also pre-

assigned i, j, (as the square root of -1) and some other constants.

Vectors

Enter each element of the vector separated by a space, between square brackets, and set it

equal to a variable. For example, to create a vector “a”, enter into the Matlab command window:

a = [1 2 3 4 5 6 9 8 7]

Matlab should return:

a =

1 2 3 4 5 6 9 8 7

Let's say you want to create a vector with elements between 0 and 20 evenly spaced in

increments of 2 (this method is frequently used to create a time vector):

t = 0:2:20

t =

0 2 4 6 8 10 12 14 16 18 20

Manipulating vectors is almost as easy as creating them. First, suppose you would like to add 2

to each of the elements in vector 'a':

Here we’re adding a scalar to a vector- try

b = a + 2 a similar method to multiply the elements

of b by a scalar (eg 3.75)

b =

3 4 5 6 7 8 11 10 9

Now suppose, you would like to add two vectors together. If the two vectors are the same length,

it is easy. Simply add the two as shown below:

c = a + b

c =

4 6 8 10 12 14 20 18 16

Subtraction of vectors of the same length works exactly the same way.

Functions

Matlab includes many standard functions. Each function is a block of code that accomplishes a

specific task. Matlab contains all of the standard functions such as sin(), cos(), ln(),

log10(), exp(), sqrt(), as well as many others.

sin(pi/4)

Note: MATLAB performs trigonometry in

ans = radians only

0.7071

For more information on the usage of any function, type help [function name] at the

Matlab command window. For example help sqrt

Polynomials

In Matlab, a polynomial is represented by a vector. To create a polynomial in Matlab, simply

enter each coefficient of the polynomial into the vector in descending order. For instance, let's

say you have the following polynomial:

s 4 + 3s 3 − 15s 2 − 2 s + 9

To enter this into Matlab, just enter it as a vector in the following manner

correspond to the polynomial coefficients

x =

1 3 -15 -2 9

If your polynomial is missing any coefficients, you must enter zeros in the appropriate place in

the vector. For example,

You can find the value of a polynomial using the polyval() function. For example, to find the

value of s 4 + 3s 3 − 15s 2 − 2 s + 9 at s = 2:

“arguments”: one vector and one

scalar, separated by a comma.

z =

-15

You can also extract the roots of a polynomial using the function roots(). This is useful when

you have a high-order polynomial, for example s 4 + 3s 3 − 15s 2 − 2 s + 9 :

roots([1 3 -15 -2 9])

ans =

-5.5745 Note: this also finds complex roots, so

2.5836 it’s very handy for plotting root

-0.7951 positions, or root locus diagrams

0.7860

Very often, we want to multiply two polynomials together. The product of two polynomials is

found by taking the “convolution” of their coefficients. Matlab's function conv() that will do

( )

this for you. To perform this multiplication: (s + 2 ) s 2 + 4 s + 8 = s 3 + 6 s 2 + 16 s + 16 we’d enter:

x = [1 2];

y = [1 4 8]; Note: z = conv([1 2],[1 4 8])

z = conv(x,y) would achieve the same result…

1 6 16 16 the brackets by hand.

Notice how the elements of vector z relate to the coefficients of s in the answer of the

multiplication above. Also remember to watch out for “missing” coefficients, for example

( )

This multiplication: s 3 s 2 + 4 s + 8 = s 5 + 4 s 4 + 8s 3 would have to be calculated as:

(s 3

)( )

+ 0 s + 0 s + 0 s + 4 s + 8 = s + 4 s 4 + 8s 3

2 2 5

( plus 0s 2 + 0s + 0 )

x = [1 0 0 0];

y = [1 4 8];

z = conv(x,y)

z =

1 4 8 0 0 0

Note: using a semicolon at the end of the line (as seen above) stops MATLAB from printing the

answer each time! This is essential for calculations on large arrays.

Transfer Functions

Consider an open loop system which has a transfer function of

Y (s) s+7

H (s) = =

U ( s ) s ( s + 5)( s + 15)( s + 20)

Enter the transfer function by entering the two polynomials (called num and den here just to

indicate to ourselves that they’re numerator and denominator, but we’re free to call them other

things, e.g. A, B, plantnum, plantden):

num=[1 7];

The denominator can be entered as follows (there are other ways to perform the convolution):

Note that the “s” term is represented by the vector [1 0] meaning 1 times “s” and 0 times “s0”).

Each “conv” function returns a vector result of a multiplication, and “den” is set to be the result

of the multiplication of those two vectors.

You can check the value of any variable by just typing the name and pressing enter:

>> den

den =

1 40 475 1500 0

Once a system has been entered in this format, MATLAB can do lots of useful things:

Step and impulse responses:

step(num,den)

impulse(num,den)

We can show the positions of the poles and zeros on the s-plane:

pzmap(num,den)

And we can even plot a root locus diagram with one simple command – how useful!:

rlocus(num,den)

Matlab will even compute a closed-loop transfer function from an open-loop transfer function –

the function cloop() should be sufficient for this course. It assumes negative feedback, with

unity gain. See “help feedback” for more details/options. Here, the result of the function

cloop() is a two-element vector, which we’re assigning to the two element vector

“[numCL, denCL]”. Each element of that array is itself a vector.

We’re using the terms “numCL” and “denCL” here, but you can call the closed loop numerator

and denominator whatever you like.

Now you can look at the step response of the closed loop transfer function:

step(numCL,denCL)

You might notice that the steady state error to a step input is zero, since the open-loop transfer

function has a pole at the origin…

Frequency Response

MATLAB generates a frequency response with no trouble at all:

bode(num,den)

It’s as simple as that – but you can add more complexity. For example, by default, bode() plots

a graph, but you can also assign the results to variables in the workspace:

[mag,phase,w]=bode(num,den); you might want a semicolon here

Where w is the list of frequencies used, phase is the phase angle in degrees, and mag is the

magnitude response, but NOT in dB, just to confuse you. You can (of course) convert to dB

using something like:

mag_in_dB = 20*log10(mag);

You can also generate a frequency response over any frequency range you like, not just

MATLAB’s chosen range. In that case, the logspace command is useful (see its help file):

my_freqs = logspace(-2,3,100); Generates 100 log-spaced points between 10-2 and 103

bode(num,den,my_freqs)

polar(phase*pi/180, mag) have a look at help polar()

(Here, we’ve needed to convert the phase to radians.)

margin(num,den)

Though do make sure you know what you’re entering – i.e. the open loop transfer function!

Example:

Using the Remote Position Control Servo Example.

This example compares two models of the same system – one model ignores the effect of coil impedance

st

in the electric motor – the other includes it, as a 1 order lag.

The two models:

J f J f

motor motor

amplifier amplifier

1

θi V = kθ i T = 1 .0 × V θi V = kθ i T= V

error error Ls + R

signal signal

output output

• Equation of motion: • Equation of motion:

shaft θ shaft θ

(

T = θ 0 Js 2 + fs = kθ i ) position (

T = θ 0 Js 2 + fs = ) (Lsk+ R ) θ i

position

θ o (s ) k θ o (s ) k

= =

• Laplace transfer function: θ i (s ) s( Js + f )

• Laplace transform:

θ i (s ) s( Js + f )(Ls + R )

2 -3

J = 0.01 kg m , f = 0.05 N m s, R = 1 Ohm, L = 5 x 10 Henrys

Hint: use cloop() to find the closed loop transfer function (numerator, denominator) then use pzmap()

• Hence define the impulse response of the c.l. system in terms of ζ, ωn - What effect does

inclusion of coil impedance have?

Hint: these are calculated from the positions of the poles on the s-plane. If you mouse-click on the poles, MATLAB

displays information about the position of the poles – damping and natural frequency.

• Now plot the full root locus for the each system (as a check, this should pass through your point

at k=0.1)

Hint: use rlocus(), remember to use the numerator and denominator of the open-loop transfer function

• For each system, find the value of K to give ζ = 0.7 and 0.5 and find the damped natural

frequency ωd at those points

Hint: use rlocus(), and by mouse-clicking on the locus, you can identify the gain for a particular point

• Fully describe the stability of each system with k = 0.1 (phase margin, gain margin). Critical gain

can be found using Routh array or Nyquist method – try both, see which you prefer!

Hint: use margin()

Hint: use margin(), either change the value of “k”, and recalculate “num” and “den” or multiply “num” by a scalar.

Final task:

Copy and paste the contents of the command history (see first page of these notes) into an email

to b.hanson@ucl.ac.uk. Make sure your email contains your name!

- RDS-300Uploaded byj_dominguez_v6990
- Introduction to Control Engineering Modeling, Analysis and Design - Ajit Mandal - 2006Uploaded byRey M Hernandez
- Introduction to Control Engineering ; Modeling, Analysis and Design - Ajit K. MandalUploaded byClara Garrido P
- Flight Control Design – Best PracticesUploaded bycmpmarinho
- 9UGUploaded byAnuj Patel
- Root Locus (1)Uploaded byDheer Mehrotra
- control theory introductionUploaded bySushmita Kujur
- FM_AG-08_TP-088-7Uploaded bycmpmarinho
- New Microsoft Word Document (3)Uploaded bymonu_sr88
- 7196082644337272Uploaded byMuhammad
- Introduction to Adaptive ControlUploaded byGeorge Iskander
- CompensadoresUploaded byEvan AV
- 00 IndexUploaded byElies Ciutat
- The Performance Analysis Of Four Tank System for Conventional Controller and Hybrid ControllerUploaded byIRJET Journal
- Module Report ME2142Uploaded byWai-Yen Chan
- Quick CommissioningUploaded byjcc
- Rr220206 Control SystemsUploaded bychinna_k
- ec2255-lpUploaded bymuthu
- Final Project FinalReport VikasYADAVUploaded byviya123
- Controls PROJECT.pdfUploaded byFeynman2
- 1152-4464-1-PB(1) (1)Uploaded byDalia Murad
- Low 201506 OLC3 SkoltechUploaded bySorn Darong
- BusinessAdministration1_10Uploaded byDinh Quang Dung
- New Microsoft Word DocumentUploaded bymikiale
- 4Uploaded byVijay Rohilla
- CS 4th.pdfUploaded bysanthosh kumar
- Course Project 1_rangansrinivasanUploaded byRangan Srinivasan
- upload.pdfUploaded byRajesh Xyz
- 2 Fuzzy Neural Network Controller DesignUploaded byJavad Rahmany Fard
- Modelo DosUploaded byroyfantasma

- Ideal Gas Sol3Uploaded byWesNamtrow
- Arduino Programming NotebookUploaded bylass11
- Trig Cheat SheetUploaded byHMaSN
- Common Derivatives & IntegralsUploaded bystr8spades
- Rise and FallUploaded byWesNamtrow
- Laplace Transform TableUploaded bySriram
- CalcIII CompleteUploaded byWesNamtrow
- CalcII CompleteUploaded byWesNamtrow
- Sermons CollectedUploaded byWesNamtrow
- Political SermonsUploaded byWesNamtrow
- CalcI CompleteUploaded byWesNamtrow
- Sovet HealthcareUploaded byWesNamtrow
- FourierLaplaceUploaded byWesNamtrow
- First Second OrderUploaded byWesNamtrow
- RouthHurwitzAnalysisUploaded byWesNamtrow
- Problems0_13_14Uploaded byWesNamtrow
- Place Names ColoradoUploaded byWesNamtrow
- LaPlace TransformUploaded bySuhail Ahamed
- Matlab TutorialUploaded byapi-25906715
- Laplace 76Uploaded byWesNamtrow
- MCDuffReaderUploaded byWesNamtrow
- Revel ShUploaded byWesNamtrow
- Extra Materials Carnot EngineUploaded bytruffelove
- pweUploaded byWesNamtrow
- Wesley Wortman Research Paper Eng 135 Week 8Uploaded byWesNamtrow
- Iron SideUploaded byWesNamtrow
- Nature of RevolutionUploaded byWesNamtrow
- Code of HammmrabiUploaded byWesNamtrow
- A Famers ThoughtsUploaded byWesNamtrow

- Year 10 Separation_techniques Part 3Uploaded bydanielphilip68
- Macaulay's MethodsUploaded byAfia S Hameed
- 42g-td001_-en-p.pd1Uploaded bysoay
- mass volume density powerpointUploaded byapi-295864428
- SKF_6402_EN_11_10_19_GB_high_tcm_12-55843Uploaded byAlvaro
- Topik Ting 4 P2 Trial 2015 Fizik SPMUploaded bySiti Arbaiyah Ahmad
- Alben Daz OleUploaded byMulayam Singh Yadav
- stoch_proc_notes.pdfUploaded bydrhugh3891
- Evaluacion Metodo Van OortmerssenUploaded byfondexx
- chapter 4Uploaded byapi-219047883
- unit 3 parent letterUploaded byapi-325172108
- Geotechnical Engineering BasicsUploaded bydaniel.j.mccarthy
- March on 2018Uploaded byAlfredo Landaverde García
- Selection of Cables/ConductorsUploaded byshuwing
- Assignment -1 Rasmus Fisker BangUploaded byRasmusFiskerBang
- Stability CocaineUploaded byAmalikMalik
- Hydraulic Study of GRE Piping Using Pipenet SimulationUploaded bypsycopaul
- Operaciones Unitarias en Ingenieria Quimica Mccabe 6 Ed SolucionarioUploaded byRafael Lara Verduzco
- 05 Fenton RandomFieldsUploaded byAndres Pino
- USRE35387Uploaded byaussiebear22
- The Spectroscopic Properties of Melanin - Jenny-Riesz-Phd-ThesisUploaded byRobers Armand
- A New Element Model of Solid BodiesUploaded byjiangke
- Deformation and Strength Characteristics of Granular MaterialsUploaded byrshaghayan
- 2013 TJC Prelim H2 Maths Paper 1 (Solutions With Comments From Tutors)Uploaded byGwendolyn Chow
- ftirUploaded byevelyn
- 2 1 4 Calculating Force Vectors AnskeyUploaded byilkpol
- Paper # 719_CIGRECanada2015- Ziomek - Performance of Power Transformers Under GIC R3Uploaded byWaldemar Ziomek
- Elasticity.pdfUploaded byKanishk Mehta
- ASTM D3532_1 (EN) ᴾᴼᴼᴮᴸᴵᶜᴽUploaded bysvvasin2013
- xanthate X2Uploaded byHela Cherif