Top Banner

of 24

Solving a System in Matlab

Apr 06, 2018

Download

Documents

Khurram Hashmi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/3/2019 Solving a System in Matlab

    1/24

    Solving A system in Matlab

    By Engr. Khurram Hashmi

  • 8/3/2019 Solving a System in Matlab

    2/24

    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 2

  • 8/3/2019 Solving a System in Matlab

    3/24

    Default Matlab view

    Solving a System in Matlab 3

  • 8/3/2019 Solving a System in Matlab

    4/24

    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 4

  • 8/3/2019 Solving a System in Matlab

    5/24

    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 givevalues for them

    syms

    is a useful command in this regard

    Solving a System in Matlab 5

  • 8/3/2019 Solving a System in Matlab

    6/24

    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 6

  • 8/3/2019 Solving a System in Matlab

    7/24

    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

  • 8/3/2019 Solving a System in Matlab

    8/24

    Generating a transfer function

    >> s=tf(s)This prompts Matlab to treat all equations of the svariable as a transfer function. All followingequations of s will be automatically simplifiedand 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

  • 8/3/2019 Solving a System in Matlab

    9/24

    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 9

  • 8/3/2019 Solving a System in Matlab

    10/24

    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

  • 8/3/2019 Solving a System in Matlab

    11/24

    Extracting variables

    Solving a System in Matlab 11

    Numerator coefficients Denominator coefficients

  • 8/3/2019 Solving a System in Matlab

    12/24

    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

  • 8/3/2019 Solving a System in Matlab

    13/24

    Step response

    >> step(G)

    This Gives the figure

    shown left.

    We can right click in the windowand enable viewing

    characteristics as peak

    response, settling time etc

    Solving a System in Matlab 13

  • 8/3/2019 Solving a System in Matlab

    14/24

    Impulse response

    >> impulse(G)

    This gives the impulse response

    and can be manipulated

    likewise

    Solving a System in Matlab 14

  • 8/3/2019 Solving a System in Matlab

    15/24

    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

  • 8/3/2019 Solving a System in Matlab

    16/24

    Well have to select one or more of these systems for the plot. Ill select G

    Solving a System in Matlab 16

  • 8/3/2019 Solving a System in Matlab

    17/24

    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

  • 8/3/2019 Solving a System in Matlab

    18/24

    Bode Magnitude and Phase Plot

    There is a range of options you can use.

    Solving a System in Matlab 18

  • 8/3/2019 Solving a System in Matlab

    19/24

    ROOT LOCUS

    The Plot and its meaning

    Solving a System in Matlab 19

  • 8/3/2019 Solving a System in Matlab

    20/24

    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

  • 8/3/2019 Solving a System in Matlab

    21/24

    Root Locus

    G(s)_

    K

    Input 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

  • 8/3/2019 Solving a System in Matlab

    22/24

    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

  • 8/3/2019 Solving a System in Matlab

    23/24

    You can also enable the grid through right click menu. Frequency values along imaginary

    axis and zeta (damping ratio) along real axis 23

  • 8/3/2019 Solving a System in Matlab

    24/24

    Thank you..

    Your feedback is welcome at:

    [email protected]

    Solving a System in Matlab 24