In this video, we are going to look at the simulation of this great time and continuous time models.
In order to solve the differential equations with respect to time, the integral of the equations need
to be computed.
This process is called integration and in simulation, it is usually carried out numerically because
an exact analytical solution cannot usually be found.
In the previous video, we presented the result for the analytical solution for the continuous time
time invariant linear system.
But this is only a very specific case.
A analytical solution can be found in general, and analytical solution is usually pretty hard to find
and cannot be found.
The simulation on numerical integration of continuous systems and discrete systems will be explained
in this video.
So let's first consider the continuous time simulation, continuous time simulation solves this differential
equation here.
So this is the state's best representation, a continuous time, non-linear states based system.
So if we break this down and have a look at the state X with respect to time as shown in this graph
here, it has some trajectory or profile.
So let's consider this time point here.
So this time for time, T is going to have a value of X of T, and now we would like to work out what
the state is as sometime in the future.
So the first step in this process is to look at the derivative.
So the derivative or the rate of change of the state X respectively is a slope of this graph.
Now, the slope of this graph at this point here is exactly the solution here.
So this is the derivative of the state respective time.
So what we would like to do is to look at the state at some time in the future.
So let's say we want to propagate the time to a very small time in the future of Delta T. So we want
to step forward by dignity to work out the state at time T plus Delta T..
So if we assume that this directive is concerned over this time period date here, all we have to do
is just propagate this derivative up to this point over here.
So we look at this.
We can use our gradient rule and just say that decks of ADT times date.
The dates here are going to cancel out, leaving UTX or Delta X.
So this is going to tell us how much X has changed over this time period here.
So if we do that, we can propagate our X value for up to here to work out our X at time T plus Delta
T or we write this in equation form.
We can say that the value of the state at time t possibility is equal.
The value of the state, AT&T T plus the derivative of the state at 20 times the ability.
So this is a first order approximation of the system dynamics.
This basically steps forward a small amount of time, assuming that the state right is content to work
out the new type to work out new state at the new timestep.
So this is known as our first order integration, so we can say here that we use the dynamics of the
system to work out our state rights or extort, then we can use our other integration, which basically
propagates forward in small chunks of time.
So we have the current state, AT&T, plus our state.
Right at times our timestep here.
This is going to work out in our new state at some small time step in the future.
And what we want to do is that we want to select a timestep that is very small.
The smaller that this state is here, the better solution is, the more that it approximates the real
time, the main solution.
So what we do is we first assume an initial condition, so X of naught.
So this is our starting condition, our starting state, then we use this to calculate the state right
equation.
So we feel in this equation here and evaluate it using the current state, the current input to work
out how quickly the state is changing for the current time.
Then we can integrate the timestep using our first order integration, using this equation here to work
out the new state at the time step in the future and then we can probably get the time forward by small
DETI and all we do is just be continuing.
We continuously repeat steps two and three as needed until we get to the end time of the simulation
that we want.
Now, all our integration is a seamless integration method.
There is, however, it is the least accurate, the time step must be small to capture the dynamics
of the nonlinear system.
It can also be numerically unstable.
The solution?
Accuracy gets exponentially, exponentially worse with time.
And this can be a problem.
How about this is the most simplest form of numerical integration and it's easy to understand.
So it's worth considering.
So now let's consider a second order mechanical system and specifically, let's consider the enforced,
which means zero input, second order mass, bring down the system as shown on the slide here.
So this system has a mass that can freely move in and out, back and forth.
It is attached to a spring and a daffner.
And what we want to do, the states of the system are going to be x the position and the velocity.
So how quickly is moving back and forth?
Now, this spring here, it's going to resist any displacement.
So the amount of force that's applied to this mass here is going to be a function of displacement.
So the displacement X Tomsky is going to give you the amount of restoring full force.
This Depner over here is going to resist the velocity.
So the velocity times is Dettman coefficient B is going to give you how much force is being applied
by the dapena.
And the state space system can be represented as a linear first order system as shown here.
So we have the state's velocity and position and this is the system dynamics with the spring coefficient.
We have the Dutney coefficient and we have the mass of the object.
And over here we have the state rates of the system.
So we have velocity dot also known as acceleration and Eckstut also known as velocity.
So these equations here, we can work out the enforced response to the system, the enforced response
just looks at the system dynamics without any input.
So we consider this system over here.
This is a mess that the system we move the mess and amount of X, and from here we let go and it should
spring back to its initial position.
And what we want to do is we want to look at how the position and velocity evolve with time as it's
released.
So using the system dynamics, we can generate the simulated response for a given configuration, so
we'll assume a massive one kilogram adapting coefficient of one, a spring coefficient of 10, we will
assume that the initial velocity zero and we'll give an initial displacement or point two meters.
So that's basically saying we move this mess out here by point ten meters, we hold a stationary and
then we let go.
And then we look at the response of the system.
So we simulate what is going to look like and we can see what the response is over on the results of
the simulation over here, dysgraphia.
So this top graph is a position.
This graph here is a velocity.
So you can see at time zero, we have a displacement or point two and we have a zero velocity.
And as we let it go, the system springs back towards its zero position is neutral position.
So initially we have zero velocity.
We let go.
It starts to accelerate backwards and then it oscillates back and forth.
So we can see here also back and forth, but eventually it converges and dies out.
So this system, the response here was done using all our integration with a really small timestep,
you can see it here is a very small fraction of a second, but this system here can be very susceptible
to the timestep size.
So you can see here, if we use the timestep of point one seconds, we get a totally different spring
response.
So this is because the systems will inherently spring systems, spring damper systems are very stiff,
so they're very susceptible to the timestep.
So if we use a timestep, appoint one second, you can see that they get a very different response.
We actually get a A system that just keeps oscillating back and forth.
So this is incorrect.
This is not a good simulation of the system.
This is because the timestep is too large.
So it is important to select a timestep that small enough to capture all the dynamics when we're using
others first order integration.
And if we were to use a time set even larger, we might actually get an unstable response, which we're
talking about before, which just means that the position and velocity might distort oscillating and
increasing larger and larger and larger in time.
So it is important to select the correct integration method, and if we're using other integration,
it is important to select a very small time period such that we can capture all the system dynamics.
This allows us to be certain that the simulation results are a good approximation of the actual continuous
time dynamics of the system.
Now, in the previous example, we looked at the continuous time simulation.
Now we're going to look at the discrete time simulation since the system dynamics is already in discrete
time, the simulation of the model is very straightforward.
We don't need to do any numerical integration.
We only need to use the recursive solution to step forward in time from the start of the simulation
to the end time or the desired time.
To do this, we first assume an initial condition for the state are ignored and then we step to the
solution using the discrete time equation of the system.
So using our ethanol, we substitute in for X, OK, we substitute in for input at this time, set to
get at our new time step solution for the time set in the future.
We also propagate forward.
Okay, so initially K is going to be equal to zero.
So this is be ignored.
This will be, you know, and we calculate what our X1 is.
We also say X, we also say that K goes from zero to one and then repeat the solution again.
Now we have X one.
You want to work out what our x2 is and we probably get Foord K, so K goes from one plus one to two
and we just keep repeating this step forward in time.
So, again, if we look at the same second order mechanical system as we did for the continuous system,
using our conversion from continuous time to discrete time, using a timestamp or point, one gives
us this value for the F matrix here.
So this basically is a system that it works out how we work out the new velocity and position, given
the current velocity and position.
And if we step forward in time and simulate it, we get a response that looks like this, which is very
which is exactly what we got, or looks very similar as what we got in the continuous time solution.
Except at this time, we're not we're not using a very small time set.
We're just using TimeStep 0.01.
So we get a solution at zero point one point two point three all the way up in this case to ten seconds.
So in this example, we've used a time, seven point five, and we end up with a different F matrix.
This is because we evaluated the Matrix exponential using a different Delta team.
And again, we get a response that looks like this.
Now, this looks now this does not look as similar as a continuous time system as we've had in the past,
but it's still very valid, is still the perfect representation of the continuous time system, except
that we're only calculating the solution at point five increments in time.
So we have a solution for zero seconds.
Point five one one point five two.
So forth.
All the way up to 10.
So this is a perfectly valid representation of the continuous time system, but just in discrete form,
we only care about the solution at point five second increments.
And if we could take it to even more extreme, so if we just criticize the system using a date of two
seconds, we end up with this matrix here.
And this is the response we get when we use the recursive recursive solution and step forward in time.
So we have a solution at zero at two, four, six, eight, 10.
And again, you might look at this and say this looks like nothing like the continuous time solution,
but in fact, it is a perfect representation of the continuous time solution we're only looking at at
different time points.
So if we go back and overlay the continuous time solution on the solution, we end up with a graph that
looks like this.
So the blue line is the continuous time solution.
You can say it's nice and smooth.
The orange line here is the discrete solution with a time set of two.
And what you can see here is that at the zero two four six eight 10, the value of the continuous time
and discrete time system perfectly match.
This is because when we work out this F matrix, we're using the Matrix exponential or the integration.
It perfectly captures all the dynamics in between here.
But we don't need to use all our integration and simulate all the individual points.
We can just jump from one time into the next time and into the next time.
So this is the power of representing things as a discrete system.
It means that we don't have to consider all the intermediate points.
We can just consider the output or the state of the system at a time steps that we actually want to
do something with.
So whether this is looking at calculating a control solution or doing some data fusion, we don't need
to know the continuous system dynamics.
We only need to know the dynamics or the state of the system at certain points in time, which makes
perfect sense to represent the system in discrete form because this is how it's actually going to get
implemented in real life.
So we've covered a very basic introduction into how to simulate continues and simulate discrete systems,
you can see that using the this great system, it perfectly represents the continuous dynamics, except
instead of having to integrate the system with a very small time set, we can capture all that dynamics
inside the state transition matrix, the F and G matrixes.
And we can calculate the system for a given times in the future and we can just step forward in discrete
chunks of time without worrying about all the intermediate time points.
This is the power of discrete time representation and it is the most natural way of representing a system
when we want to do something with it, whether it's control or filtering or anything to do with the
actual implementation in a real world system.