Simulating Larger Systems

Introduction

Getting State Equations
A More Complex System
The 4th Order Runge-Kutta In Mathcad

Why Simulate?

       Earlier you learned why you need to do simulations, and how to simulate a first order linear system. In this lesson we will examine simulating systems that are more complex than first order systems.  Here are our goals for the lesson.

    Given a higher order system in a standard form
    Be able to simulate the system using the packaged integration algorithms.
    Be able to choose a good time interval for calculation using that algorithm.

Getting State Equations

        To simulate higher order systems you will need a set of state equations.  That's not a single differential equation, it is a set of first order differential equations.  Here is a system that we will use to illustrate one way - out of several - that you can get a set of state equations for a system.

        This system looks imposing when you first encounter it.  But, consider the output of the system which is also the output of a block that integrates.  (That's not an unusual occurrence.  That is a typical representation for a system that has a motor and you are concerned about angular position.  The motor's angular position is the integral of velocity.)  Let us take the output to be the first state:

x1(t) = Output

        The second part of the system - the block in red - has a differential equation that relates the input and the output of that block.  Actually, we know that that subsystem is a first order system and that we can represent it with a state representation like this.

dx2(t)/dt = - x2(t)/t1 + Gdc,1u2(t)/t1

We are thinking ahead here, calling this state x2(t).  However, it is a state, and it is also the output of that block - the red block.  We've called the input to this block u2(t) and we will just let it at that for now.  In a little while we will come back to this signal to see what it really is.  We do know, however, that Gdc,1 is 1.0.  Let's focus on x2(t).

        Interestingly, x2(t) is also the input to the integrator block.  That means we have:

dx1(t)/dt = x2(t)

Thus, as we have stumbled around in this system we have come up with two state equations.  The third one shouldn't be hard after that.

        Consider the third part of the system, the block colored blue.  We know that this system also has a state representation.

dx3(t)/dt = - x3(t)/t2 + Gdc,2u3(t)/t2

Again, we are thinking ahead and calling x3(t) a third state.  Now we know that u2(t) is really x3(t), so we have that straightened out.  We also know - from the block diagram - that Gdc,2 is what is labelled K in the diagram.  The only problem is u3(t) - the input to the blue block.  However, looking at the block diagram we can see that u3(t) is just the difference between the input and the output.  Call the input u(t), and remember that the output is x1(t), so we have:

dx3(t)/dt = - x3(t)/t2 + K[u(t) - x1(t)]/t2

We now have our three state equations.  Here they are:

dx1(t)/dt = x2(t)

dx2(t)/dt = - x2(t)/t1 + x3(t)/t1

dx3(t)/dt = - x3(t)/t2 + K[u(t) - x1(t)]/t2

        If you want to use these state equations for a numerical simulation you again have a choice of programming venues.

Mathcad
 
 


A More Complex System

        We used a very ad-hoc approach to getting state equations for this system, and to be perfectly honest, we were quite lucky that the method worked.  What helped in this example was that all the poles were real, and there were no zeroes in the system.  For other systems you may want a more systematic approach.  Here is a system that is just complex enough to require a more sophisticated approach.

        The reasons this system is a little bit tougher to simulate are:

We are going to go at this system by first considering this system.

This system is a little different.  We have removed the "numerator dynamics', i.e. the system does not have a zero.  We have also changed our terminology a little bit.  In the original system, we called the output y(t).  In this system the output is called x1(t).  If you guessed that that means that the output of this system is a state, you are right.

        Let's consider the differential equation that is satisfied by this system.  Here is the differential equation that relates x1(t) and u(t).

This is a second order differential equation, and the coefficients in the differential equation are the coefficients in the denominator of the system.


PROBLEM:  Verify that the system in the block diagram above satisfies the differential equation above.

        Next we can generate a set of state equations for the system with no numerator dynamics.  The problem with the differential equation is that it has a second derivative.  We define the second state to be the derivative of the first state - and when we do that we will eventually get rid of that pesky second derivative.

By defining the second state that we get a state equation by turning the definition around.  Here is the derivative of the first state in terms of all the states - actually only the second state.

Now, let's rearrange that differential equation.  Put everything except the second derivative on the right hand side.

This may not look like a state equation, but we're almost ther.  Remember that we defined the second state to be the derivative of the first above, so we can now say:

That's our second state equation.  Here are both of them together.


        We now have state equations for the second order system with no numerator dynamics.  We still need to figure out how to set up state equations for the system that has a zero in the numerator.  We'll go at that gradually.  Consider this system.

This system is very similar to the system with no numerator dynamics.  The difference in this system is the s term in the numerator.  Consider the difference the s term in the numerator makes.  One way to visualize the difference is to break the system into two parts as shown below.


PROBLEM:  Why are the two systems above equivalent?  Why do they have the same output?

        Note, we are not suggesting that we actually have a differentiator.  This is just a way of visualizing the system and how it performs.  But is does permit us to view the system as a combination of our earlier system above - the one with no numerator dynamics - and a differentiator that supplies the s term in the numerator.  We know how to simulate the original system, so we can calculate that response and differentiate it.

        The real question is whether we need to differentiate the output.  Here is another strategy.

When we do the simulation we calculate both states, so we just need to take the other state and we have the derivative we want, and we shouldn't have any problem doing the simulation above.

        Now, consider the system we examined originally.  Have we any additional insight into this system now?

This system can be thought of as a combination of the two systems we have been examining.  Here is a way to do that.


PROBLEM:  Using standard block diagram algebra show that the system above has the transfer function of the system shown in the diagram just above it.

        Now, we can write a complete set of state equations for this system.  At this point, you need to remember - or learn - the standard form for state equations for linear, time-invariant systems - and all of the systems above fall into that category.  Usually state equations for linear, time-invariant systems are put into a vector matrix format.  First we wil define the terms for that format, and then show how the systems above can be put into the standard format.  We will assume that the system has only a single input and a single output.  All of the systems to this point are single input - single output systems, and the generalization to multi-input-multi-output systems is straightforward.

        The standard format for state equations is:

The dyamic equation
dx/dt = A x + b u
The output equation
y = cTx + d u
These terms are defined as follows:
x(t) is an n x 1 state vector, and there are n states in the system.

u(t) is the input to the system.

y(t) is the output of the system.

A is the incremental state transition matrix.

b, c and d are vectors that relate the input, output and states.

Now, let us revisit what we know about these systems and see how to fit what we know into this standard model.  We will start with the first second order system - the one with no numerator dynamics. First here is the system we want to consider.

This system had two state equations, given above and reproduced here.


It may not be obvious, but these state equations can be cast into the standard vector-matrix format.  First, define a state vector.

Then we have the equation for the state dynamics.

This dynamic equation can be put into a vector-matrix format.

This is the standard form for the equation for state dynamics, i.e.

dx/dt = A x + b u

Here, we have:

and:

We also need to find the components of the output equation:

y = cTx + d u

But, we know that the output, y(t), is just x1(t) for this system, so we can get the c vector and d:

Now, these state equations can be used in an integration algorithm to predict system behavior - and that is an important reason for trying to get the state equations of a system. If you want to jump to the point in the lesson that talks about using state equations, click here.  Otherwise, we are going to look at the other systems we considered - the ones with more interesting state equations.

        Recall that we also considered a system with a zero.  The system is shown below.

We also had a short discussion of how this system could be viewed as shown below.

Now, we are going to give you the state equations for this system, and then discuss how they come about.  Here are the state equations for the system.

The dyamic equation
dx/dt = A x + b u
The output equation
y = cTx + d u
with

and:

If you examine this carefully, you will see that there is only a slight difference between the vector-matrix description for the system with the zero and the original system with a constant numerator.  As a matter of fact, the A-matrix, b-vector and the scalar, d, are exactly the same.  However, the c-vector is different.  This makes sense if you think deeper about it.  Both systems really have the same dynamics, making the A-matrix and b-vector the same.  They have the same dynamics and that shows up in the same block with the same denominator polynomial in s.  The difference between the two systems is the the output is formed differently from the states - and that is really the only difference.

        Earlier, we considered a third order feedback system.  We can also put that system into the standard form.  Here are the state equations we had.

dx1(t)/dt = x2(t)

dx2(t)/dt = - x2(t)/t1 + x3(t)/t1

dx3(t)/dt = - x3(t)/t2 + K[u(t) - x1(t)]/t2

The A-matrix and b-vector are given by:



Here is the system this set of state equations represents.

And, we take the output to be the first state:

x1(t) = Output

That means that the c-vector and d are given by:

You can see that the process of getting state equations can be systematized.  However, there are different ways of getting state equations, and different methods might yield different - but equally valid - descriptions of the same system.

        In any event, once you obtain a set of state equations, you will probably want to use them with an integration algorithm so that you can compute the response of a system.  That's the next section.


Integration Algorithms

        In another lesson, we examined a simple integration algorithm - the Euler integration algorithm - and used that to calculate the response of a first order, linear system.  However, the Euler algorithm - while simple to implement - can be improved upon.  There are numerous integration algorithms that are more accurate than the Euler including the many versions of the Runge-Kutta, predictor-corrector methods and the Adams-Bashforth algorithm - to mention but a few.

        Describing the details of these algorithms will not be done here.  There are numerous good references on them, and the interested reader should browse the numerical analysis section of their university library.  For our purposes here we will simply use these algorithms and try to point out characteristics that are important.  We will focus on the fourth-order, Runge-Kutta algorithm for now.


The Fourth Order Runge-Kutta Integration Algorithm In Mathcad

        We begin with the second order system above.

Which has a state equation description:

and:

Next, we can express those state equations in Mathcad and use them in a Runge-Kutta integration algorithm.