Matlab  Basics  Tutorial for ELEC Students-2004
23 pages
English

Matlab Basics Tutorial for ELEC Students-2004

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
23 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Matlab Basics Tutorial for Electrical and Electronic Engineering & Electrical and Communication Engineering Students Prepared by P.Leung Revised by I.Jahmeerbacus May 2004 P.L Matlab Tutorial 1.0 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: To enter this into Matlab, just enter it as a vector in the following manner x = [1 3 -15 -2 9] x = 1 3 -15 -2 9 Matlab can interpret a vector of length n+1 as an nth order polynomial. Thus, if your polynomial is missing any coefficients, you must enter zeros in the appropriate place in the vector. For example, would be represented in Matlab as: y = [1 0 0 0 1] 2.0 Matrices In matrix, each row of elements is separated by a semicolon (;) or a return: B = [1 2 3 4;5 6 7 8;9 10 11 12] B = 1 2 3 4 5 6 7 8 9 10 11 12 B = [ 1 2 3 4 5 6 7 8 9 10 11 12] B = 1 2 3 4 5 6 7 8 9 10 11 12 P.L Matrices in Matlab can be manipulated in many ways. For one, you can find the transpose of a matrix using the apostrophe key: C = B' C = 1 5 9 2 6 10 ...

Informations

Publié par
Nombre de lectures 23
Langue English

Extrait




Matlab Basics Tutorial


for


Electrical and Electronic Engineering
&
Electrical and Communication Engineering
Students











Prepared by P.Leung
Revised by I.Jahmeerbacus
May 2004


P.L Matlab Tutorial
1.0 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:

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

x = [1 3 -15 -2 9]

x =
1 3 -15 -2 9

Matlab can interpret a vector of length n+1 as an nth order polynomial. Thus, if your
polynomial is missing any coefficients, you must enter zeros in the appropriate place in
the vector. For example,

would be represented in Matlab as:

y = [1 0 0 0 1]


2.0 Matrices
In matrix, each row of elements is separated by a semicolon (;) or a return:

B = [1 2 3 4;5 6 7 8;9 10 11 12]

B =
1 2 3 4
5 6 7 8
9 10 11 12

B = [ 1 2 3 4
5 6 7 8
9 10 11 12]

B =
1 2 3 4
5 6 7 8
9 10 11 12
P.L
Matrices in Matlab can be manipulated in many ways. For one, you can find the
transpose of a matrix using the apostrophe key:

C = B'

C =
1 5 9
2 6 10
3 7 11
4 8 12

It should be noted that if C had been complex, the apostrophe would have actually given
the complex conjugate transpose. To get the transpose, use .' (the two commands are the
same if the matix is not complex).
Now you can multiply the two matrices B and C together. Remember that order matters
when multiplying matrices.
D = B * C

D =
30 70 110
70 174 278
110 278 446

D = C * B

D =
107 122 137 152
122 140 158 176
137 158 179 200
152 176 200 224
Another option for matrix manipulation is that you can multiply the corresponding
elements of two matrices using the .* operator (the matrices must be the same size to do
this).

E = [1 2;3 4]
F = [2 3;4 5]
G = E .* F


E =
1 2
3 4

F =
2 3
4 5

G =
2 6
12 20

P.L If you have a square matrix, like E, you can also multiply it by itself as many times as
you like by raising it to a given power.

E^3

ans =
37 54
81 118

If wanted to cube each element in the matrix, just use the element-by-element cubing.

E.^3

ans =
1 8
27 64

You can also find the inverse of a matrix:

X = inv(E)

X =
-2.0000 1.0000
1.5000 -0.5000
or its eigenvalues:

eig(E)

ans =
-0.3723
5.3723
There is even a function to find the coefficients of the characteristic polynomial of a
matrix. The "poly" function creates a vector that includes the coefficients of the
characteristic polynomial.

p = poly(E)

p =

1.0000 -5.0000 -2.0000

Remember that the eigenvalues of a matrix are the same as the roots of its characteristic
polynomial:

roots(p)


ans =
5.3723
-0.3723




P.L 3.0 Stability of a system

A system is stable if all the roots of its characteristic equation lie on the left half of the s-
plane otherwise the system is unstable. Given the characteristic equation is given by

= 0

determine the stability of the system.

cl=[1 3 -15 -2 9];
r = roots(c1)

r =

-5.5745
2.5836
-0.7951
0.7860

The system is unstable.


Exercises :



1. Form with Matlab the matrices

1 2 2 4 7 2 8⎡ ⎤ ⎡ ⎤ ⎡ ⎤
A = B = C = ⎢ ⎥ ⎢ ⎥ ⎢ ⎥3 4 6 8 1 5 3⎣ ⎦ ⎣ ⎦ ⎣ ⎦

Compute the following matrix computations:

T AB, BA, A+B, A+C, BC, CC, CC

2. Given a matrix m and a vector v : 1 1



T Calculate the product m =m v : 2 1 1

P.L
3. Write the following system of equations in matrix form (AX=B)

− x + 4y + 3z = 1
2x + z = 3
x − y − 2z = −5


T and then, by finding the inverse of the matrix A, solve to find X = ( x,y,z) and
hence x,y,z.

4. Consider the matrix

2 1⎛ ⎞
A = ⎜ ⎟ ⎜ ⎟4 −1⎝ ⎠

(a) Find the eigen values of A
(b) Determine the eigenvectors of A
(c ) Create a 2X2 modal matrix M out of the column eigenvectors. Then
-1 -1 evaluate M and finally evaluate D = M AM.


5. Determine the stability of the system, given the characteristic equation is

Kc /( τ 1 τ 2 τ 3)( τ 4s +1)
1 + = 0
τ 4s[s + (1/ τ 1)][s + (1/ τ 2)][s + (1/ τ 3)]

use τ =1, τ = ½, τ =1/3, Kc = 5 and τ = 0.25. 1 2 3 4















P.L 4.0 Root Locus

Consider a simple RC circuit as shown in Fig. 1 in which a voltage source v(t) is applied
to a series combination of a resistance R and capacitance C where e(t) is the voltage
across the capacitor. In this example the system is the RC circuit, the system input is the
voltage v(t) and the system output is the voltage e(t). The relation between the input and
output of the system in the frequency domain is the transfer function.





Fig. 1 RC circuit

Applying Kirchoff’s law,

1
v(t) = Ri(t) + idt ∫C
1
e(t) = idt ∫C

v(t) = Ri(t) + e(t) (1)


Taking Laplace Transform of Eq. (1) and rearranging,the transfer function gives

E(s) 1
=
V(s) τs +1

where the time constant τ = RC





P.L 4.1 Plotting the root locus of a transfer function

From the example above, let τ = 1 then

E(s) 1
G(s) = =
V(s) s +1
To model this system into Matlab, create a new m-file and add the following code:

num=1;
den=[1 1];
g=tf(num,den);
rlocus(h)



Consider a system which has a transfer function:

s + 7

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

the command to plot the root locus is given below:

num=[1 7];
den=conv([1 0],[1 5]),conv([1 15],[1 20]);
rlocus(num,den)

P.L

Exercises

1. Using Matlab, obtain the root locus of the transfer function of a system below:

3 2s + 0.196s + 2s

4 3 2s + 0.392s + 3.004s + 0.588s

2. The open-loop transfer function for DC motor’s speed is derived by the
expression:
Q K=
2v (Js + b)(Ls + R) + K

where electrical resistance (R ) = 1 ohm
electrical inductance (L)= 0.5H
electromotive force constant (K)=0.01Nm/Amp
2 2 moment of inertia of the rotor (J)=0.01 kgm /s
damping ratio of the mechanical system (b) = 0.1Nms
input (v) : source voltage
output (Q) : Rotating speed

Create an m-file and obtain the root locus of the system.








P.L 4.2 Closed-loop response
In order to find the step response of a system, you need to know the closed-loop transfer
function. You could compute this using the rules of block diagrams, or let Matlab do it
for you:
[numCL, denCL] = cloop(num, den)

The two arguments to the function cloop are the numerator and denominator

  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents