• No results found

Miscellaneous simulation issues

Analytical tools

6.4 Miscellaneous simulation issues

the trim process. Next, the minimisation routine which searches for those values of x and u that minimise the cost function J will be started. The elements of these vectors, which are adjusted by either the minimisation routine or the constraints, are updated for each iteration step.

The state equations are then evaluated for the new values of u and x to find the time-derivative of the state-vector, ˙x. Substituting the results in equation (6.53) yields the new value of J, which is returned to the minimisation routine. A stop criterion that depends upon the change of J between two iterations is used to decide when to finish the minimisation procedure. Also, the maximum number of iterations is limited so the process will stop if the solution does not converge.

6.4 Miscellaneous simulation issues

In the previous sections, we have discussed most analytical functions from figure 6.1, focussing on numerical integration, linearisation and trimming methods. In this sec-tion, some other issues which may be encountered during numerical nonlinear sim-ulations will be highlighted. These topics are relevant for the FDC toolbox, because they shed some light on the practical difficulties one may encounter, and provide background information for some analytical functions. The information from sec-tion 6.4.2 has been applied in practice to create some FDC submodels.

6.4.1 Algebraic loops

Continuous systems are often expressed as block diagrams, which divide the sys-tem into logical modules, and suggest a certain order of computations. The latter, though convenient for digital simulations, is not in accordance with reality: in the actual system, all variables will change simultaneously, not sequentially. A suitable calculation sequence is needed for digital simulations, but we should realize that this is an artificial construct – a sequential representation of what is, in effect, a parallel system.

If feedback is applied to a system, it may not be possible to find a suitable compu-tation sequence for digital simulations. This situation generally occurs when blocks having direct feedthrough of their input signals form a feedback-loop: the block out-puts cannot be computed without knowing the values of the signals entering the blocks, while the block inputs cannot be computed without knowing the signals leav-ing the blocks. This is called an algebraic loop.

A simple example of this situation can be seen in figure 6.8, which shows a sys-tem consisting of a gain K with negative unity feedback. Mathematically, this loop implies that the output of the summation junction is an algebraic state e, constrained to equal the first input u minus the output y, which equals K·e:

y=K·e =K(u−y) (6.54)

The solution of this simple loop is:

y=

 K

1+K



u (6.55)

but most algebraic loops cannot be solved so easily [4].

94 Chapter 6. Analytical tools

u e K y

+_

Figure 6.8:Gain with unity feedback: an algebraic loop

0 1 2 3 4 5

-2 -1 0 1 2 3 4

t [ s ] y( t

) / K

Input: unit step at t = 0

K = 1.5 K = 1.0 K = 0.5

Figure 6.9:Dynamics, introduced by the algebraic loop from figure 6.8

Algebraic Equations

x ALB g(x)

Figure 6.10:Iterative solution of an algebraic loop

6.4. Miscellaneous simulation issues 95

It is interesting to see what will happen if we try to integrate this system with a numerical integration method, using a step-size hn, by introducing an artificial com-putation sequence as follows:

en = un−yn1

yn = Ken = K(un−yn1) (6.56)

where yn ≡ y(n·hn)and yn1 ≡ y((n−1)·hn1)for an integer value n. Taking the Z-transform of these equations yields:

Y(z)

U(z) = Kz

z+K (6.57)

which indicates that inadvertent additional dynamics have been introduced as a con-sequence of trying to calculate the responses of a parallel system using sequential cal-culations. Figure 6.9 visualizes unit step-responses for the Z-transfer function (6.57) for several values of the gain K.

When SIMULINKdetects an algebraic loop it will calls a loop solving routine at each time step. The loop solver tries to determine a solution by means of Newton-Rhapson iterations [4]. First, a new block ALB is added to the system containing the implicit algebraic equations from the algebraic loop, see figure 6.10. This block has an input g(x) and an output x. The block attempts to find a value of x such that g(x) =x, which means that it tries to solve the following nonlinear equation:

G(x) ≡g(x) −x=0 (6.58)

This is done by applying the Newton-Rhapson method [8]:

xi+1 =xiG(xi)

G0(xi) (6.59)

where:

G0(xi) = G(xi+∆x)

∆x (6.60)

for small values of∆x. The subscript i in these equations denotes the iteration num-ber, not the time-step. In some situations, this method will not converge to a solution within a reasonable number of iterations. SIMULINKwill display an error message if it is unable to solve the algebraic loop within 200 iterations (it is possible and recom-mended to specify an initial guess; see ref.[4] for more information).

Since the Newton-Rhapson iterations have to be carried out for every time-step, the presence of one or multiple algebraic loops will slow down simulations. One should try to avoid this whenever possible. An algebraic loop can be ‘broken’ by including an additional dynamic element in the feedback loop, e.g. a filter or an artificial time-delay. However, the effect of such measures needs to be weighted carefully – remember the inadvertent dynamics from figure 6.9.

Sometimes, it is possible to write out the system equations in an explicit form.

For instance, the algebraic loop from figure 6.8 can be eliminated by replacing this diagram with a single block representing equation (6.55). Another example was pro-vided in section 3.4, where an algebraic loop in the equation for the aircraft’s sideslip angle was averted by re-writing the differential equation in an explicit form.

96 Chapter 6. Analytical tools

Figure 6.11:Block-diagram equivalent of a transfer function

6.4.2 Obtaining state-models from transfer functions

Linear systems are often represented in terms of transfer functions, which can be im-plemented in SIMULINKblock-diagrams by means ofTransfer Fcnblocks. However, since the numerical integrators cannot be applied directly to such transfer functions, a conversion to state-space format is necessary. Obviously, SIMULINK will handle this conversion forTransfer Fcnblocks, but we will discuss this topic in a little more detail nevertheless, as this knowledge will prove to be useful for the implementation of transfer functions with non-constant coefficients.

There exist a variety of techniques to convert transfer functions into linear state models. Refs.[8, 33] and [36] contain some examples, and ref.[10] includes a more fundamental discussion of this topic. Regardless of the method, the resulting state models will not be unique, as they depend on the choice of state variables. Here we will focus on what is called the ‘controllable canonical form realisation’ [10], which will generally be adequate for our needs.

For a broad class of systems the dynamic behaviour of variations about operating point values can be approximated by an nth-order linear differential equation:

dny

6.4. Miscellaneous simulation issues 97

real constants, and m and n are scalars, representing the highest-order derivatives of the input and output signals, respectively (m ≤ n). The corresponding transfer function is:

H(s) ≡ Y(s)

U(s) = bms

m+bm1sm1+ . . . +b2s2+b1s+b0

sn+an1sn1+ . . . +a2s2+a1s+a0 (6.62) If there are no input derivatives present in the differential equation (i.e. if m=0), the task of finding a state representation is trivial: state variables can simply be assigned to the output y and its derivatives up to order n−1, and n state equations can be written down immediately.

To derive the state equations in the general case where input derivatives are present, we will first re-write this transfer function, introducing a help function V(s):

V(s) ≡ Y(s)

bmsm+ . . . +b1s+b0 = U(s)

sn+ . . . +a1s+a0 (6.63) This yields the following equations:

Y(s) = (bmsm+ . . . +b1s+b0) V(s) (6.64) snV(s) = U(s) −an1sn1V(s) − . . . −a1sV(s) −a0V(s) (6.65) These equations can be represented in a ‘simulation diagram’, as illustrated in fig-ure 6.11. This diagram is constructed from a series of cascaded first-order integrals (the 1s blocks) and simple gain blocks; V(s)is the output of the last integrator and the number of integrators is equal to the degree of the denominator polynomial of transfer function (6.62).

Equation (6.65) relates the input of the first integrator to the transfer function in-put U(s)and the feedback signals from later integrators. This equation corresponds to the lower half of figure 6.11. Equation (6.64) establishes the resulting output signal Y(s); the output connections have been drawn in the upper half of the figure. Notice that the figure assumes the highest order of the input and output derivatives to be equal, i.e. m=n. For m< n, some of the bi coefficients are zero.

If we now assign state variables to the integrator outputs, working from right to left and starting with the rightmost integrator, we can define the state vector for this transfer function block as:

By observing the simulation diagram, we can obtain the familiar linear state and output equations (taking notice of the fact that u and v are scalars, and x is a vector of length n):

˙x = Ax+bu

y = cx+ du (6.67)

98 Chapter 6. Analytical tools

The state matrices then become:

A =

This form of the system matrix A is known as a companion-matrix: all elements are zero, except for the superdiagonal 1’s and the nonzero bottom row. The simplicity of this form makes it useful for theoretical derivations, but its numerical computation properties are not particularly good. However, this is not a problem when dealing with systems of low order [33].

For the FDC toolbox, the structure from figure 6.11 has been applied for the imple-mentation of the Dryden turbulence filters, which are defined by transfer functions with airspeed-dependent coefficients, and for a filter in the Altitude Select mode of the Beaver autopilot, which also uses non-constant coefficients. Obviously, the stan-dardTransfer Fcnblock from SIMULINKis more convenient for the implementation of transfer functions with constant coefficients.

Chapter 7