Transient Response Assignment 2010

Embed Size (px)

Citation preview

  • 8/8/2019 Transient Response Assignment 2010

    1/6

    Assignment Part 2: Transient Response Analysis Assignment

    The first order system is given by:1

    )(+

    =Ts

    K sG

    Hence a user specifying:den = [2,5] num = 1 should represent:

    14.02.0

    521

    )(+

    =+

    = s s

    sG

    By dividing through by 5 (last term in denominator vector) to put it in the standardformat, the T = 0.4, and the gain term is 0.2.

    The time domain equation for the step response is given by:

    )1()( T t e K t c

    =

    Where t would be a user specified time range or a range generate within thefunction.

    The 2 nd order system is given by: 22

    2

    2)(

    nn

    n

    w sw s

    Kw sG

    ++=

    Hence a user specifying: den = [2,5,16], num = 10 should represent:

    85.2

    5

    1652

    10)( 22 ++

    =++

    = s s s s

    sG

    By dividing through by 2(first term in denominator vector) to make the coefficientof the s 2 term = 1, we obtain the general form of the expression, the damping ratio,damped and undamped natural frequency terms can be obtained:

    82 =nw ; 5.22 =nw ; and 52 =n Kw Therefore all three terms can be calculated. Thisis key to generate the correct second order plot.

    The time-domain equations for the three possible response of a second ordersystem are summarize as follows:

    The size of the damping ratio constant of the system determines the type of

    response:

    i) If the damping ratio is less than 1 then the response is underdamped:

    ( ) ( ) ( )t wew

    w K t w Ke K t c

    d

    t w

    d

    nd

    t w nn sincos 22

    =

    where (damped natural frequency)

    1

  • 8/8/2019 Transient Response Assignment 2010

    2/6

    ii) If the damping ratio is equal to one then the response is critical:

    ( ) ( ) t wn net w K K t c += 1

    iii) If the damping ratio is greater than one then the response is overdamped:

    )1()( 21t st s Be Ae K t c =

    where ( 121 = nw s and ( 122 += nw s

    12

    132

    2

    +=

    B and

    12

    31)1(

    2

    2

    ==

    B A

    Your major challenge will be entering the equations correctly so that they work.

    Develop a function that will use the basic plot command to generate thestep-response plot of a first or second order system based on the set of time domain equations provided. The function/script should use as inputarguments the user specified model parameters. The time range can alsobe specified as an input argument or be generated internally.

    Other useful commands available in Matlab:

    y = sin(x) returns sine of a scalar or the elements of a vector or matrix.

    y = exp(x) returns the exponential of a scalar or the elements of a vectoror matrix.

    y = cos(x) returns the cosine of a scalar or the elements of a vector ormatrix.

    2

  • 8/8/2019 Transient Response Assignment 2010

    3/6

    y = sqrt(x) returns the square root of a scalar or the elements of a vectoror matrix.

    Further useful scripting examples to review

    In this assignment you are require to apply the input command to request datafrom the user. General most basic format:NameOfVariable = input(User Prompt);User Prompt should be enter as shown in quotes and its a statement thatinstructs the user of what they are required to enter.NameofVariable this is the variable to which the user entry is stored. To use theusing entry further in your code, therefore, you would have to refers the namedvariable. Examples:>> rowvect = input('Please enter a row vector of 3 values, use [ and ] to encloseyour entry: ')

    Please enter a row vector of 3 values, use [ and ] to enclose your entry: [1,2,3,4]

    rowvect =

    1 2 3 4

    >>

    Note that the user didnt follow instructions and 4 values instead of 3 were enter,the following is an an example using the input command within a script (function)and writing the necessary code to ensure the user entry is correct:

    function [ydata, coeff] = testinput(xdata)%This functions plots a quadratic function that the user specifies userip= input( 'Please enter a row vector of 3 coefficient, use [ and ] to enclose your entry: ' );% the following code checks if the user enter the data correctly:n = length(userip); %could have used the 'size' command also if n > 3

    coeff = userip(1:3); %only use the first 3 values of the user vectorelseif n < 3 % prompt user to re-enter input

    maxattempt = 5; %this is number of times the user is allow to re-enter valueretry = 1;

    while n ~= 3 && retry

  • 8/8/2019 Transient Response Assignment 2010

    4/6

    rows = dim(1); cols = dim(2);ydata = a*xdata.^2 + b*xdata + c*ones(rows,cols); % first return argumentplot(ydata);

    Things to take note of the following:- .^2 this was used to avoid an error and to instruct matlab square

    the elements within the xdata matrix/vector and not attempt to multiple the matrix by itself.

    - The c coefficient was multiply by ones matrix of the samedimension as xdata. This is again done to avoid an error as thethree terms in the quadratic expression must be of the same

    matrix dimension in order for them to be added.- Example use of the while command

    - Example use of the if-then-else command

    - Example use of the length and size command for checking vectorand matrix dimension

    - Example use of the input command

    The command window testing:

    %In this first example the user enters 4 values but only 3 is return and isused to build the quadratic function

    >> xrange = 0:0.5:10;

    >> [yrange, quadcoef] = testinput(xrange)

    Please enter a row vector of 3 coefficient, use [ and ] to enclose your entry: [1,2,3,4]

    yrange =

    Columns 1 through 10

    3.0000 4.2500 6.0000 8.2500 11.0000 14.2500 18.0000 22.2500 27.000032.2500

    Columns 11 through 20

    38.0000 44.2500 51.0000 58.2500 66.0000 74.2500 83.0000 92.2500 102.0000112.2500

    Column 21

    123.0000

    4

  • 8/8/2019 Transient Response Assignment 2010

    5/6

    quadcoef =

    1 2 3

    >>

    0 5 10 15 20 250

    20

    40

    60

    80

    100

    120

    140

    In this second example the user enters 2 values instead of 3 values and sois re-prompted to re-enter vector:

    >> xrange = [0:0.5:10]'; %transpose to make a column vector instead of row

    >> [yrange, quadcoef] = testinput(xrange)

    Please enter a row vector of 3 coefficient, use [ and ] to enclose your entry: [2,4]

    Row vector should be of length 3, please re-enter vector: [2,4,1,5]

    Row vector should be of length 3, please re-enter vector: [2,4,1]

    yrange =

    1.0000

    3.5000

    7.0000

    11.5000

    .

    .

    219.5000

    50 5 10 15 20 25

    0

    50

    100

    150

    200

    250

  • 8/8/2019 Transient Response Assignment 2010

    6/6

    241.0000

    quadcoef =

    2 4 1

    Note that the return argument vector for the y-values is now a column vector of the same dimension as the x data values enter.

    An alternative to enter a vector would have been to ask the user to separately enterthe coefficients for a, b, and c:

    a = input(Input coefficient of square term: )

    b = input(Input coefficient for first order term: )

    c = input(coefficient of constant term: )

    Or finally this information could have been designed to be provided as input arguments tothe function:

    function [ydata, coeff] = testinput(xdata,a,b,c)

    6