control&simulink

Upload: zbmdmd808975591

Post on 04-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Control&Simulink

    1/53

    1

    Application Software Course

    Control

    &Simulink

    By: Mahdi Akbari

    09,November

    http://elecdl.com/
  • 7/30/2019 Control&Simulink

    2/53

    Roots

    >> roots([1,2,3,4,5,6])

    ans =0.5517+ 1.2533i

    0.5517- 1.2533i

    -1.4918

    -0.8058+ 1.2229i

    -0.8058- 1.2229i

    2

    65432)( 2345 ssssssG

  • 7/30/2019 Control&Simulink

    3/53

    3

    Symbolic Mathematic

    Sym: Create symbolic object

    >> x=sym(x)

    Syms: Shortcut for creating multiple symbolic objects

    >> syms x,y

  • 7/30/2019 Control&Simulink

    4/53

    4

    Symbolic Mathematic

  • 7/30/2019 Control&Simulink

    5/53

    5

    >> syms s

    >>f= (5*s^2 + 3*s +6)/(s^4 + 3*s^3 + 7*s^2 + 9*s +12);

    >> ilaplace(f )

    Example

  • 7/30/2019 Control&Simulink

    6/53

    Transfer Functions

    >> num=[1,5];

    >> den=[1,2,3,4,5];

    >> G=tf(num,den)

    6

    5432

    5)(

    234

    ssss

    ssG

  • 7/30/2019 Control&Simulink

    7/53

    7

    Transfer Functions

    >> den=conv(conv(conv([1,3,1],[1,3,1]),[1,6]),[1,6,5,3]);

    >> num=6*[1,5];

    >> G=tf(num,den)

  • 7/30/2019 Control&Simulink

    8/53

    Transformation of System Model

    (Steady State)

    >> G=ss(A,B,C,D)

    8

    DuCxy

    BuAxx.

  • 7/30/2019 Control&Simulink

    9/53

    Example

    9

    >> A=[2.25, -5, -1.25, -0.5; 2.25, -4.25, -1.25, -0.25; 0.25, -0.5, -1.25,-1; 1.25, -1.75, -0.25, -0.75];

    >> B=[4, 6; 2, 4; 2, 2; 0, 2];

    >> C=[0, 0, 0, 1; 0, 2, 0, 2];

    >> D=zeros(2,2);

    >> G=ss(A,B,C,D)

  • 7/30/2019 Control&Simulink

    10/53

    10

    Transformation of System Model

    [A,B, C,D] = tf2ss (num, den)

    [num , den] = ss2tf (A,B, C,D)

    DuCxy

    BuAxx.

    DBASICden

    num

    su

    sY

    1)(

    )()(

  • 7/30/2019 Control&Simulink

    11/53

    Zero-pole-gain Description

    >> KGain=6;

    >> Z=[-1.9294; -0.0353+0.9287j; -0.0353-0.9287j];

    >> P=[-0.9567+1.2272j; -0.9567-1.2272j; 0.0433+0.6412j; +0.0433-

    0.6412j];

    >> G=zpk(Z,P,KGain)

    11

  • 7/30/2019 Control&Simulink

    12/53

    12

    step responses

    >> step (num,den)

    >> step (A,B,C,D)

    for find:

    MP

    Rise time Fall time

    Over shoot

  • 7/30/2019 Control&Simulink

    13/53

    Form 3:

    >> [y,x,t] = step (num,den,t)

    >> plot(t,y)

    13

  • 7/30/2019 Control&Simulink

    14/53

    14

    impulse responses

    For impulse responses:

    R(s)=1

    Step ( s G(s) )

    11

    )()(

    ssRsC

    11

    )(

    )(

    1)

    1(

    1

    1)()(

    s

    s

    ssu

    sC

    ss

    s

    ssGsC

  • 7/30/2019 Control&Simulink

    15/53

    impulse responses

    >> impulse (num, den)

    15

  • 7/30/2019 Control&Simulink

    16/53

    Ramp responses

    Step ( G(s)/S )

    16

  • 7/30/2019 Control&Simulink

    17/53

    17

    Feedback

    >> Gt=feedback(G,H)

    >> syms g1 g2 % declare symbolic variables>> Gt=feedback(g1,g2,1); %Defult: negative feedback

    >> pretty(Gt)

  • 7/30/2019 Control&Simulink

    18/53

    Example:

    >> G1=tf(1,[1,2,1]);

    >> G2=tf(1,[1,1]);>> G=feedback(G1,G2) %for negative feedback

    >> G=feedback(G1,G2,+1) % for positive feedback

    18

  • 7/30/2019 Control&Simulink

    19/53

    19

    >>[r, p, k] = residue(num, den)

  • 7/30/2019 Control&Simulink

    20/53

    20

    Root Locus Plots

    [r, k] = rlocus (num, den)

    [r, k] = rlocus (num, den, k)

    [r, k] = rlocus (A,B, C,D)

    [r, k] = rlocus (A,B, C,D, K)

  • 7/30/2019 Control&Simulink

    21/53

    21

    Example

    >> num = [0 0 0 1];

    >> den = [1 5 9 0];

    >> rlocus(num, den);

  • 7/30/2019 Control&Simulink

    22/53

    22

    Bode Diagrams

    bode(num, den)

    bode(num, den, W)

    bode(A,B, C,D) (3.36)

    bode(A,B, C,D, W)

    [mag, phase, w] = bode (num, den)

    [mag, phase, w] = bode (num, den, w)

    [mag, phase, w] = bode (A, B, C, D)[mag, phase, w] = bode (A, B, C,D, w)

    [mag, phase, w] = bode (A, B, C, D, iu, w)

  • 7/30/2019 Control&Simulink

    23/53

    23

    Example

    >> %Bode diagram

    >> num= [29.125 33.2025 9.4627];

    >> den= [0 1 0];

    >> bode (num, den)

  • 7/30/2019 Control&Simulink

    24/53

    24

    Nyquist Plots

    nyquist (num, den, w)

    nyquist (A,B, C,D)

    nyquist (A,B, C,D, w)

    nyquist (A,B, C,D, iu, w)

    [re, im, w] = nyquist (num, den)

    [re, im, w] = nyquist (num, den, w)

    [re, im, w] = nyquist (A,B, C,D)[re, im, w] = nyquist (A,B, C,D, w)

    [re, im, w] = nyquist (A,B, C,D, iu, w)

  • 7/30/2019 Control&Simulink

    25/53

    25

    Example

    >>z = [13 + 7*i37*i];

    >>p = [1353 + 7*i37*i];

    >> k= 30;

    >> nyquist (num, den)

  • 7/30/2019 Control&Simulink

    26/53

    26

    What Is Simulink?

    Simulink is a software package formodeling, simulating, and analyzingdynamical systems.

    It supports linear and nonlinear systems,modeled in continuous time, sampled time,

    or a hybrid of the two.

  • 7/30/2019 Control&Simulink

    27/53

    27

    How to open simulink

    Click on this item

  • 7/30/2019 Control&Simulink

    28/53

    28

    create a model

    To create the model, first

    type simulink in the MATLAB

    command window. On

    Microsoft Windows, the

    Simulink Library Browserappears.

  • 7/30/2019 Control&Simulink

    29/53

    29

    Open new window

    Simulink opens a new model window.

    Click on NewModel button

  • 7/30/2019 Control&Simulink

    30/53

    30

    Model Editor

  • 7/30/2019 Control&Simulink

    31/53

    31

    View Command History

    Back =(Displays theprevious view in theview history.Forward )

    forward=(Displaysthe next view in theview history.Go ToParent )

    Go To Parent=Opens, if

    necessary, the parent of thecurrent subsystem andbrings its window to the topof the desktop.

  • 7/30/2019 Control&Simulink

    32/53

    32

    Building a Simple Model

    This example shows you how to build a model using

    many of the model building

    commands and actions you will use to build your own

    models

    The model integrates a sine wave and displays the

    result, along with the sine wave. The block diagram of

    the model looks like this

  • 7/30/2019 Control&Simulink

    33/53

    33

    Create example model

    To create this model, you will need to copy blocks into

    the model from the following Simulink block libraries:

    1. Sources library (the Sine Wave block)

    2. Sinks library (the Scope block)

    3. Continuous library (the Integrator block)

    4. Signals & Systems library (the Mux block)

  • 7/30/2019 Control&Simulink

    34/53

    34

    first expand the LibraryBrowser tree to display theblocks in the Sourceslibrary. Do this by

    clicking first on theSimulink node to displaythe Sources node

    Sources node to displaythe Sources library blocks.

    Finally right click on the

    Sine Wave node to selectthe Sine Wave

  • 7/30/2019 Control&Simulink

    35/53

    35

    Copy the rest of the

    blocks in a similar

    manner from their

    respective libraries into

    the model window

  • 7/30/2019 Control&Simulink

    36/53

    36

    With all the blocks copied into the model window, the model should

    look

    something like this.

    Now its time to connect the blocks.

    Hold down the mouse button and move the cursor to the top input

    port of the Mux block. Notice that the line is dashed while the mouse

    button is down and that the cursor shape changes to double-lined

    cross hairs as it approaches the Mux block.

  • 7/30/2019 Control&Simulink

    37/53

    37

    Now release the mouse button. The blocks areconnected

    Press and hold down the Ctrl key. Press the mousebutton, then drag the pointer to the Integrator blocksinput port or over the Integrator block itself.

  • 7/30/2019 Control&Simulink

    38/53

    38

    Finish making block connections. When youre done,

    your model should look something like this.

  • 7/30/2019 Control&Simulink

    39/53

    39

  • 7/30/2019 Control&Simulink

    40/53

    40

    Now, open the Scope block to view the simulation output. Keepingthe Scope

    window open, set up Simulink to run the simulation for 10 seconds.

    the simulation parameters by choosing Parameters from theSimulation menu. On

    the dialog box that appearsnotice that the Stop time

    is set to 10.0

    (its default value)

  • 7/30/2019 Control&Simulink

    41/53

    41

    Choose Start from the Simulation menu and watch thetraces of the Scope blocks input.

  • 7/30/2019 Control&Simulink

    42/53

    42

    Model Viewing Shortcuts

  • 7/30/2019 Control&Simulink

    43/53

    43

    Zooming Block Diagrams

    Select Zoom In from the View menu (or type r) to enlarge theview.Select Zoom Out from the View menu (or type v) to shrink

    the view.

    Select Fit System To View from the View menu (or press the space

    bar) to fit the diagram to the view. Select Normal from the View menu

    (or type 1) to view the diagram at

    actual size.

  • 7/30/2019 Control&Simulink

    44/53

    44

    colors

    Simulink allows you to specify the foreground and

    background colors of any block

    select Screen color from the Simulink Format menu

  • 7/30/2019 Control&Simulink

    45/53

    45

    Connecting Blocks Connecting Two Blocks To auto connect two blocks: Select

    the source block. Hold down Ctrl and left-click the destination block.Simulink

    connects the source block to the destination block

    When connecting two blocks, Simulink draws as manyconnections as possible between the two blocks as illustrated

    in the following example.

  • 7/30/2019 Control&Simulink

    46/53

    46

    Connecting Groups of Source Blocks

    Simulink can connect a group of source blocks to a destination block

    or a source block to a group of destination blocks.To connect a

    group of source blocks to a destination block:

    Select the source blocks.

    Hold down Ctrl and left-click the destination block.

    bl k f

  • 7/30/2019 Control&Simulink

    47/53

    47

    connect a source block to a group of

    destination blocks

    Select the destination blocks.

    Hold down Ctrl and left-click the source block.

  • 7/30/2019 Control&Simulink

    48/53

    48

    Moving a Line Segment

    To move a line segment: Position the pointer on the segment you want to move.

    Press and hold down the left mouse button.

    Drag the pointer to the desired location.

  • 7/30/2019 Control&Simulink

    49/53

    49

    Inserting Blocks in a Line

    To insert a block in a line:

    Position the pointer over the block and press the left mouse button.

    Drag the block over the line in which you want to insert the block.

    Release the mouse button to drop the block on the line.

    Simulink inserts the block where you dropped it.

  • 7/30/2019 Control&Simulink

    50/53

    50

    Disconnecting Blocks

    To disconnect a block from its connecting

    lines, hold down the Shift key, then drag

    the block to a new location.

  • 7/30/2019 Control&Simulink

    51/53

    51

    Creating Subsystems

    As your model increases in size and complexity, you

    can simplify it by grouping blocks into subsystems.

    Using subsystems has these advantages:

    It helps reduce the number of blocks displayed in

    your model window.

    It allows you to keep functionally related blocks

    together

    C ti S b t b Addi th

  • 7/30/2019 Control&Simulink

    52/53

    52

    Creating a Subsystem by Adding the

    Subsystem Block

    To create a subsystem before adding the blocks

    Copy the Subsystem block from the Ports & Subsystems

    library into your model.

    Open the Subsystem block by double-clicking it. In the empty Subsystem window, create the subsystem.

    For example, the subsystem shown includes a Sum block

    and inport and Outport blocks to represent input to and

    output from the subsystem.

    C ti S b t b G i

  • 7/30/2019 Control&Simulink

    53/53

    53

    Creating a Subsystem by Grouping

    Existing Blocks If your model already contains the blocks you want to convert to a

    subsystem, you can create the subsystem by grouping those blocks:

    Enclose the blocks and connecting lines that you want to include in

    the subsystem within a bounding box. You cannot specify the blocks

    to be grouped by selecting them individually or by using the Select

    All command.

    Choose Create Subsystem from the Edit menu.

    If you open the Subsystem block, Simulink displays the underlying

    system, as shown below.