ODE Solvers in the Control System Toolbox Matlab Help

ODE Solvers in the Control System Toolbox

Many of the functions of the Control System toolbox can be used to solve linear. time-invariant (constant-coefficient) differential equations. They are sometime more convenient to use and more powerful than the ODE solvers discussed th far, because general solutions can be found for linear, time-invariant equation
Here we discuss several of these functions. These are summarized in Table 8.7-1 The other features of the Control System toolbox require advanced methods an will not be covered here.
Model Forms The ODE solvers in the Control System toolbox can’accept various descriptio of the equations to be solved. Version 4 of the Control System toolbox introduce the LT/ object, which describes a linear, time-invariant equation, or sets of equ –
tions, here referred to as the system. An LTI object can be created from differe . descriptions of the system; it can be analyzed with several functions; and it c be accessed to provide alternative descriptions of the system. For example, the equation
LTIOBJECT
2i +3i + 5x = f(t) . (8.7-1
is one description of a particular system. This description is called the reduced form. The standard arrangement of the reduced form has the forcing function on the right-hand side of the equals sign, and all the functions of the dependent variable on the left-hand side. This distinction is important when using the function
The following is a state-model description of the same system:
/ Ix = Ax +Bu

LTI object functions

LTI object functions

where XI = X, X2 = x, U = f(t),
A = [-~ -n (8.7-3)
B = [!] (8.7-4)
and
x = [~~] (8.7-5)
Both model forms contain the same information. However, each form has its own advantages, depending on the purpose of the analysis. Because there are two or more state variables in a state model, we need to be able to specify which state variable, or combination of variables, constitutes the output of the simulation. For example, model (8.7-2) through (8.7-5) can representthe motion of a mass, with XI the position, and X2 the velocity of the
mass. We need to be able to specify whether we want to see a plot of the position, or the velocity, or both. This specification of the output, denoted by the vector y, is done in general with the matrices C and D, which are defined as follows:
y = Cx-l-Du (8.7-6)
Continuing the previous example, if we want the output to be the position X =XI, .
then y =XI; and we would select
C = [1 0]
D=O
Thus, in this case, (8.7-6) reduces to y = XI.
To create an LTI object from the reduced form (8.7-1), you use the
t f (right, left) function and type
»sysl = tf (I, [2, 3, 5]);
where the vector right is the vector of coefficients of the right side of the . equation, arranged in descending derivative order, and left is the vector of coefficients of the left side of the equation, also arranged in descending derivative order. The result sysl is the LTI object that describes the system in the reduced form, also called the transfer-function form. (The name of the function t f stands for transfer function, which is an equivalent way of describing the coefficients on the left and right side of the equation.) Here is another example. The LTI object sys2 in transfer-function form for the equation

Capture

is created by typing
»sys2 = tf([3, 9, 2), [6, -4, 7, ?J)i
To create an LTI object from a state model, you use the s s (A, B, C, D) function, where s s stands for staff! space. The matrix arguments of the function are the matrices in the following standard form of a state model:
x = A” + lu
y = Cx+Du
(8.7-8)
(8.7-9)
where x is the vector of state variables, u Is m~vector of input functions, and y is the vector of output variables. For example, to create an LTI object in state-model form for the system described by (8.7-2) through (lU-5), you type
»A [0, 1; -5/2, -3/2);
»B [0;1/2);
»C [1, 0);
»D 0; \
»sys3 =ss(A,B,C,D);
An LTI object defined ‘using the t f function can obtain an equivalent statemodel description of the system. To create a state model for the system described by the LTI object sys1 created previously in transfer-function form you type ss (sys1). You will then see the resulting A, B, C; and D matrices on the screen. To extract and save the matrices, use the ss data function all follows:
»[A1, B1, C1, D1)
= ssdata (sysll

The results are

Capture

When using s sdata to convert a transfer-function form into a state model, note that the output y will be a scalar that is identical to the solution variable of the reduced form; in this case the solution variable of (8.7-1) is the variable x. To interpret the state modeJ, we need to. relate its state variables XI and X2 to x. The values of the matrices CI and DI tell us that the output variable is y =_P.5X2.
Because the output y is the same as x, we then see that X2 = 2x. The other state variable X, is related to X2 by X2 = 2XI. Thus Xl = X.
To create a transfer-function description of the system sys3, previously created from the state model, you type t f sys3 = t f (·sys3 ) t . To extract and

save the coefficients of the reduced form, use the tfdata function as follows: »[right, left) =tfdata(sys3, , “v”) i
For this example, the ‘vectors returned are right = 1 and left = [1,’
1 . 5 , 2. 5) . The optional parameter ‘ v ‘ -tells MATLAB to return the coefficients as vectors; otherwise, they are returned as cell arrays. These functions are summarized in Table 8.7-1.

Te.t Your Understanding
T8.7-1 Obtain the state model for the reduced-form model
5i +7i +4x ;:::J(t) Then convert the state model back to reduced form and see whether you get the original reduced-form model.

ODE Solvers
The Control System toolbox provides several solvers for linear models. These solvers are categorized by the type of input function they can accept: zero input, impulse input, step input, and a general input function. These are summarized in Table 8.7-2. The initial Function: The initial function computes and plots the free response of a state model. This response is sometimes called the initial condition response or the undriven response in the MATLAB documentation. The basic syntax is ini t ial (sys, xO), where sys isthe LTI object in statemodel form and xOis the initial condition vector. The time span and number of” solution points are chosen automatically. For example, to find the free response of the state model (8.7-2) through (8.7-5), for XI (0) = 5 and X2(0) = -2, first

Free response of the model given by (8.7-2) through (8.7-5) for x,(O) = 5 and X2(O) = -2.

Free response of the model given by (8.7-2) through (8.7-5) for
x,(O) = 5 and X2(O) = -2.

sys3. Then use the initial function as follows:
»initial(sys3, [5, -2]) The plot shown in Figure 8.7-1 will be displayed on the screen. To specify the final time t f. use the syntax ini t ial (sys ,xO, t f) . To specify a vector of times of the form t = [ 0 : d t : t f J , at which to obtain the solution, use the syntax ini t ial (sys, xOr t). When called with left-han arguments, as [y, t , x] = initial (sys ,xO, … ), the function returns the output response y, the time vector t used for the simulation, and the state vector x evaluated at those times. The columns of the matrices y and x are the outputs and the states, respectively. The number of rows in y and x equals length(t). No plot is drawn. The syntax initial (sysl,’sys2 xOr t) plots the free response of multiple LTI systems on a single plot The time vector t is optional. You can specify line color, line style, and marker for each system; for example, initial (sysl, “r ‘ ,sys2, ‘ysys3 ‘gx’ ,xO). The impulse Function: The impulse function plots the unit-impulse response for each input-output pair of the system, assuming that the initial conditions are zero. (If you are unfamiliar with the impulse input, see Chapter 10.

Section 10.5.) The basic syntax is impulse (sys), where sys is the LTI object. Unlike the ini t ial function, the impul se function can be used with either a state model or a transfer-function model. THe time span and number of solution points are chosen automatically. For example, the impulse response of (8.7-1) is found as follows:
»sysl = tf(1,[2, 3, 5)); »impulse (sysl) To specify the final time t f ,use the syntax imp”u 1s e (sy s r t f ) .To specify a vector of times of the form t = [0: dt : t f 1, at which to obtainjhesolution, use the syntax impu 1se (sys r t) . When called with left-hand arguments, as [y, t 1 = impulse (sys, … ), the function returns the output response
y and the time vector t used for the simulation. No plot is drawn. The array y is p x q x m, where p is length (t ), q is the number of outputs, and I1l is the number of inputs. To obtain the state vector solution, use the syntax [y, t , x ) = impulse(sys, … ). The syntax impul se (sys 1, sys2, … , t) plots the impulse response of multiple LTI systems on a single plot. The time vector t is optional. You can specify line color, line style, and marker for each system; for example, impulse (sysl, ‘r’, sys2, ‘y–‘, sys3, ‘gx’). The step Function: The step function plots the unit-step response for each input-output pair of the system, assuming that the initial conditions are zero. (If you are unfamiliar with the step function, see Chapter 10, Section 10.5.) The basic syntax is step (sy s) where sy s is the LTI object. The step function can be used with either a state model or a transfer-function model. The time span and number of solution points are chosen automatically. To specify the final time t f , use the syntax step (sys , t f ) . To specify a vector of times of the form t = [0: dt : t f l , at which to obtain the solution, use the syntax step (sys, t). When called with left-hand arguments, as [y, t 1 = step (sys, … ), the function returns the output response y and the time vector t used for the simulation. No plot is drawn. The array y is p x q X 111, where p is length (t) , q is the number of outputs, and I1l is the number of inputs. To obtain the state vector solution for state-space models, use the syntax [y, t , x ] = step(sys, … ). The syntax step (sysl, sys2, … , t) plots the step response of multipIe LTI systems on a single plot. The time vector t is optional. You can specify line color, line style, and marker for each system; for example, step (sysl, ‘r’ , sys2, ‘Y>’:’ , sys3, ‘gx’ ). To find the step response, for zero initial conditions, of the state model (8.7-2) through (8.7-5), and the reduced-form model 5i + 7x + 5x = 5j + f (8.7-10) the session is (assuming sys3 is still available): . »sys4 = tf ( [5, 1J, [5, 7, 5J ) ;. »step(sys3, ‘b’,sys4,

7-~Step response of the model given by (8.7-2) through (8.7-5) and the model (8.7-10), for zero initial conditions.

7-~Step response of the model given by (8.7-2) through (8.7-5) and the
model (8.7-10), for zero initial conditions.

The result is shown ill Figure 8.7-2. Thesteady-state response is indicated by the horizontal dotted line. Note flow the steady-state response and the time to reach that state are automatically determined. The lsirn Function; The lsirn function plots the response of the system to an arbitrary input. The basic syntax for zero initial conditions is lsirn (sys I U ,t) ,where sys is the LTI object; t is a time  ector having regular spacing, as t = [ 0.: dt ! t f 1; and u is a matrix with as many columns as inputs and whose ith row specifies the value of the input at time t (i) . To specify nonzero initial conditions for a state-space model, use the syntax 1s im (sys I u , t .xo) . When called with left-hand arguments, as [y, t 1 :::1s irn (sys, u, … ) the function returns the output response y and the time vector t used for the simulation. The columns of the matrix,yare the outputs, and the number of its rows equals length (t). No plot isdrawn, To obtain thestate vector solution for state-space models, use the syntax [y, t·,. x l = lsirn (sys, u The syntax 1s irn (sys 1,sys2,; … ,U, t, x O)’plots the free response of’rnultiple LTI systems on a single plot. The initial condition vector xO is needed only if the initial conditions are nonzero. You can specify line cclor.-llne style,
and marker for each system; for example, 1s im (sy s 1I I r ‘ ,sy s 2.I ‘Y I I sys3, ‘gx’ ,U,t). .
We will see an example of ~he1s im function shortly.

LTI Viewer: The Control System toolbox has the LTI Viewer to assist in the analysis of LTI systems. It provides an interactive user interface that allows you to switch between different types of response plots and between the analysis of different systems. The viewer is invoked by typing 1t i view. See MATLAB help for more information.
Predefined Input Functions
Youcan always create any complicated input function to use with the ODE solvers ode xxx or Lsimby defining a vector containing the input function’s values at specified times. However, MATLAB provides several predefined functions that you might find easier to use. These are described in the following paragraphs, and are summarized in Table 8.7-3. The function step fun (t. I to) returns a vector the same length as t with zeros where t-< to and ones where t ~ to. The vector t must have monotonically increasing elements. The function square (t) returns a vector the same length as t corresponding to a square wave of period 2rr. The function square (t) is similar to sin (t), with extreme points at ±l, except that the wave is square. The syntax square (t I duty) generates a square wave with a duty cycle specified by duty, which is the percentage of the period over-which the function is positive. The function sawtooth (t) returns a vector the same length as t corresponding to a sawtooth wave of period 2rr. The function sawtooth (t) is similar to sin (t), with extreme points at ±l, except that the wave shape is a

Capture

triangle. The syntax sawtooth (t, width) generates a’ modified sawtooth wave where width determines the fraction between 0 and 2rr at which the maximum occurs (0 ::::width:::: I). The function [u, t) = gensig (type, period) generates a periodic input of a specified type type, having a period period. The following types are available: sine wave (type = ‘sin’), square wave (type = ‘square’), and narrow-width periodic pulse (type = ‘pulse’). The vector t contains the times, and the vector u contains the input values at those times. All generated inputs have unit amplitudes. The syntax [u, t) = gensig (type, period, t f ,dt) specifies the time duration t f of the input and the spacing dt between the time instants. For example, suppose a square wave with period 5 is applied to the following reduced-form model.
.t + 2x +4x = 41 (8.7-11)
To find the response for zero initial conditions, over the interval 0 ::::t ::::10 and using a step size of 0.0 I, the session is
»sys4 = tf(4, [1,2,4));
»[u, t) = gensig(‘square’ ,5,10,0.01);
»(y, tJ = lsim(sys4,u,t);plot(t,y,t,u) ,axis([O 10 -0.5 1.5)), …
xlabel(‘Time’) ,ylabel(‘Response’)
The result is shown in Figure 8.7-3.

Square-wave response of the model x + 2.i +4x = 4f.

Square-wave response of the model x + 2.i +4x = 4f.

Posted on July 30, 2015 in Numerical Calculus And Differential Equations

Share the Story

Back to Top
Share This