Vous êtes sur la page 1sur 24

Solving A system in Matlab

By Engr. Khurram Hashmi

Introduction
This effort is dedicated to helping students solve systems in Matlab (10). specially addressing the need to utilize Matlab as a computational tool

Solving a System in Matlab

Default Matlab view

Solving a System in Matlab

Writing an equation
Lets take any equation: F(s)=3s3+4s2+11s+5 Usually this can be realized through a matrix of coefficients A=[3 4 11 5] which may be further manipulated. To evaluate this at any value of s polyval(A,3) Where 3 is the value of s at which function is evaluated

Solving a System in Matlab

Any shortcut to evaluating equations?


For equations of higher order solving manually to obtain coefficients gives room to error Alternatively, we can declare symbolic variables to be treated separately. Matlab doesnt ask you to give values for them syms is a useful command in this regard

Solving a System in Matlab

Symbolic variables
syms s F = 3*s^3 + 4*s^2 + 11 *s + 5 This appears in workspace F= 3*s^3 + 4*s^2 + 11*s + 5 It works in previous versions of Matlab as well You can further simplify this as well simplify(F) This one being already in simplified form ans = 3*s^3 + 4*s^2 + 11*s + 5

Solving a System in Matlab

Generating a transfer function


Usually coefficients of numerator and denominator are used as >> num=[1 1]; >> den=[1 2 3 4]; >> sys=tf(num,den)

Transfer function: s + 1 --------------------s^3 + 2 s^2 + 3 s + 4

however, there is another much direct approach..


Solving a System in Matlab 7

Generating a transfer function


>> s=tf(s) This prompts Matlab to treat all equations of the s variable as a transfer function. All following equations of s will be automatically simplified and made transfer functions >> N=s+1 Transfer function: s + 1 >> D=s^3 + 2*s^2 + 3*s + 4 Transfer function: s^3 + 2 s^2 + 3 s + 4 Further we can play with this >> G = N/D Transfer function: s + 1 --------------------s^3 + 2 s^2 + 3 s + 4
Solving a System in Matlab 8

Workspace Variables
Have a look at your workspace variables. This window is usually in top-right area of your default Matlab layout. You can go to each one of these and see their contents by double-clicking them

Solving a System in Matlab

Variable Editor

Variable editor displays the contents of your variables including transfer functions. Here Im showing the G transfer function we just created Ill double click the num and den to show you

Solving a System in Matlab

10

Extracting variables

Numerator coefficients
Solving a System in Matlab

Denominator coefficients
11

Seeing System Responses


We can view how the system plays to various standard inputs such as step and impulse through the command prompt >> step(G)

Or
>> impulse(G)

Solving a System in Matlab

12

Step response
>> step(G) This Gives the figure shown left. We can right click in the window and enable viewing characteristics as peak response, settling time etc

Solving a System in Matlab

13

Impulse response
>> impulse(G) This gives the impulse response and can be manipulated likewise

Solving a System in Matlab

14

LTI View
Alternatively we can use the Linear Time Invarient View or LTIVIEW for short
>> ltiview An ltiview window will pop up. Well have to select from the system(s) present in the workspace.

Solving a System in Matlab

15

Well have to select one or more of these systems for the plot. Ill select G
Solving a System in Matlab 16

Same plot as before. But in LTI viewer. Right click in the window and youll see a range of options to the type of plot you want to see. you can plot the Bode Magnitude and Phase 17

Bode Magnitude and Phase Plot There is a range of options you can use.
Solving a System in Matlab 18

The Plot and its meaning

ROOT LOCUS

Solving a System in Matlab

19

Evans Root Locus


Evans Root Locus is one way of determining a systems stability. Root Locus is the Path poles and zeroes of a system in closed loop take when multiplied with a gain Factor (usually K ) that varies from 1 to +ve infinity Systems behavior can be judged over this range
Solving a System in Matlab 20

Root Locus
Input
_ G(s) Output

>> rlocus(G)

This command plots the CLOSED LOOP poles of an OPEN LOOP transfer function .G. Note: we do not have to solve the system in closed loop first. We just enter the OPEN LOOP transfer function
Solving a System in Matlab 21

Poles and zeros on the right side of the imaginary axis means a stable system. Poles and zeros on the left side of imaginary axis means an unstable system. Furthermore, closer the poles to the imaginary axis, the less stable the system will be. 22

You can also enable the grid through right click menu. Frequency values along imaginary 23 axis and zeta (damping ratio) along real axis

Thank you..
Your feedback is welcome at: khurram_hashmi_pk@yahoo.com
Solving a System in Matlab 24

Vous aimerez peut-être aussi