1
00:00:03,900 --> 00:00:09,630
In this video, we are going to look at the simulation of this great time and continuous time models.

2
00:00:11,180 --> 00:00:17,150
In order to solve the differential equations with respect to time, the integral of the equations need

3
00:00:17,150 --> 00:00:18,050
to be computed.

4
00:00:18,890 --> 00:00:24,530
This process is called integration and in simulation, it is usually carried out numerically because

5
00:00:24,530 --> 00:00:27,620
an exact analytical solution cannot usually be found.

6
00:00:28,460 --> 00:00:35,330
In the previous video, we presented the result for the analytical solution for the continuous time

7
00:00:35,570 --> 00:00:37,960
time invariant linear system.

8
00:00:38,570 --> 00:00:40,730
But this is only a very specific case.

9
00:00:40,910 --> 00:00:47,480
A analytical solution can be found in general, and analytical solution is usually pretty hard to find

10
00:00:47,480 --> 00:00:48,560
and cannot be found.

11
00:00:50,210 --> 00:00:56,120
The simulation on numerical integration of continuous systems and discrete systems will be explained

12
00:00:56,120 --> 00:00:56,950
in this video.

13
00:00:58,390 --> 00:01:05,710
So let's first consider the continuous time simulation, continuous time simulation solves this differential

14
00:01:05,710 --> 00:01:06,430
equation here.

15
00:01:06,460 --> 00:01:12,700
So this is the state's best representation, a continuous time, non-linear states based system.

16
00:01:14,790 --> 00:01:21,480
So if we break this down and have a look at the state X with respect to time as shown in this graph

17
00:01:21,480 --> 00:01:25,190
here, it has some trajectory or profile.

18
00:01:25,830 --> 00:01:27,670
So let's consider this time point here.

19
00:01:27,690 --> 00:01:34,800
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

20
00:01:34,800 --> 00:01:36,940
the state is as sometime in the future.

21
00:01:37,590 --> 00:01:41,910
So the first step in this process is to look at the derivative.

22
00:01:41,910 --> 00:01:47,500
So the derivative or the rate of change of the state X respectively is a slope of this graph.

23
00:01:48,240 --> 00:01:52,830
Now, the slope of this graph at this point here is exactly the solution here.

24
00:01:52,840 --> 00:01:56,250
So this is the derivative of the state respective time.

25
00:01:57,580 --> 00:02:02,110
So what we would like to do is to look at the state at some time in the future.

26
00:02:02,590 --> 00:02:09,370
So let's say we want to propagate the time to a very small time in the future of Delta T. So we want

27
00:02:09,370 --> 00:02:14,500
to step forward by dignity to work out the state at time T plus Delta T..

28
00:02:15,400 --> 00:02:22,120
So if we assume that this directive is concerned over this time period date here, all we have to do

29
00:02:22,120 --> 00:02:26,420
is just propagate this derivative up to this point over here.

30
00:02:26,890 --> 00:02:27,880
So we look at this.

31
00:02:27,880 --> 00:02:34,090
We can use our gradient rule and just say that decks of ADT times date.

32
00:02:34,780 --> 00:02:38,580
The dates here are going to cancel out, leaving UTX or Delta X.

33
00:02:38,590 --> 00:02:43,220
So this is going to tell us how much X has changed over this time period here.

34
00:02:44,170 --> 00:02:52,120
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

35
00:02:52,120 --> 00:02:55,110
T or we write this in equation form.

36
00:02:55,450 --> 00:03:00,760
We can say that the value of the state at time t possibility is equal.

37
00:03:00,760 --> 00:03:07,930
The value of the state, AT&T T plus the derivative of the state at 20 times the ability.

38
00:03:08,650 --> 00:03:12,700
So this is a first order approximation of the system dynamics.

39
00:03:13,390 --> 00:03:19,150
This basically steps forward a small amount of time, assuming that the state right is content to work

40
00:03:19,150 --> 00:03:22,300
out the new type to work out new state at the new timestep.

41
00:03:24,100 --> 00:03:30,730
So this is known as our first order integration, so we can say here that we use the dynamics of the

42
00:03:30,730 --> 00:03:37,450
system to work out our state rights or extort, then we can use our other integration, which basically

43
00:03:37,450 --> 00:03:39,540
propagates forward in small chunks of time.

44
00:03:40,000 --> 00:03:43,690
So we have the current state, AT&T, plus our state.

45
00:03:43,690 --> 00:03:46,760
Right at times our timestep here.

46
00:03:47,080 --> 00:03:51,270
This is going to work out in our new state at some small time step in the future.

47
00:03:51,790 --> 00:03:55,870
And what we want to do is that we want to select a timestep that is very small.

48
00:03:56,020 --> 00:04:01,240
The smaller that this state is here, the better solution is, the more that it approximates the real

49
00:04:01,450 --> 00:04:02,800
time, the main solution.

50
00:04:04,010 --> 00:04:08,230
So what we do is we first assume an initial condition, so X of naught.

51
00:04:08,450 --> 00:04:13,820
So this is our starting condition, our starting state, then we use this to calculate the state right

52
00:04:13,820 --> 00:04:14,320
equation.

53
00:04:14,330 --> 00:04:19,850
So we feel in this equation here and evaluate it using the current state, the current input to work

54
00:04:19,850 --> 00:04:22,760
out how quickly the state is changing for the current time.

55
00:04:23,480 --> 00:04:29,900
Then we can integrate the timestep using our first order integration, using this equation here to work

56
00:04:29,900 --> 00:04:34,970
out the new state at the time step in the future and then we can probably get the time forward by small

57
00:04:34,970 --> 00:04:38,230
DETI and all we do is just be continuing.

58
00:04:38,750 --> 00:04:45,590
We continuously repeat steps two and three as needed until we get to the end time of the simulation

59
00:04:45,590 --> 00:04:46,070
that we want.

60
00:04:46,990 --> 00:04:49,870
Now, all our integration is a seamless integration method.

61
00:04:49,900 --> 00:04:55,810
There is, however, it is the least accurate, the time step must be small to capture the dynamics

62
00:04:55,810 --> 00:04:57,190
of the nonlinear system.

63
00:04:58,090 --> 00:05:00,150
It can also be numerically unstable.

64
00:05:00,160 --> 00:05:00,730
The solution?

65
00:05:00,730 --> 00:05:04,180
Accuracy gets exponentially, exponentially worse with time.

66
00:05:04,570 --> 00:05:05,680
And this can be a problem.

67
00:05:06,960 --> 00:05:13,210
How about this is the most simplest form of numerical integration and it's easy to understand.

68
00:05:13,230 --> 00:05:14,400
So it's worth considering.

69
00:05:15,450 --> 00:05:21,480
So now let's consider a second order mechanical system and specifically, let's consider the enforced,

70
00:05:21,480 --> 00:05:27,300
which means zero input, second order mass, bring down the system as shown on the slide here.

71
00:05:27,930 --> 00:05:32,120
So this system has a mass that can freely move in and out, back and forth.

72
00:05:32,550 --> 00:05:35,430
It is attached to a spring and a daffner.

73
00:05:35,820 --> 00:05:40,700
And what we want to do, the states of the system are going to be x the position and the velocity.

74
00:05:40,710 --> 00:05:42,630
So how quickly is moving back and forth?

75
00:05:43,500 --> 00:05:47,310
Now, this spring here, it's going to resist any displacement.

76
00:05:47,310 --> 00:05:51,960
So the amount of force that's applied to this mass here is going to be a function of displacement.

77
00:05:51,960 --> 00:05:57,930
So the displacement X Tomsky is going to give you the amount of restoring full force.

78
00:05:58,740 --> 00:06:01,950
This Depner over here is going to resist the velocity.

79
00:06:02,280 --> 00:06:07,980
So the velocity times is Dettman coefficient B is going to give you how much force is being applied

80
00:06:07,980 --> 00:06:08,700
by the dapena.

81
00:06:09,240 --> 00:06:14,890
And the state space system can be represented as a linear first order system as shown here.

82
00:06:15,510 --> 00:06:22,680
So we have the state's velocity and position and this is the system dynamics with the spring coefficient.

83
00:06:22,680 --> 00:06:25,740
We have the Dutney coefficient and we have the mass of the object.

84
00:06:26,370 --> 00:06:28,710
And over here we have the state rates of the system.

85
00:06:28,720 --> 00:06:34,950
So we have velocity dot also known as acceleration and Eckstut also known as velocity.

86
00:06:36,470 --> 00:06:42,650
So these equations here, we can work out the enforced response to the system, the enforced response

87
00:06:42,650 --> 00:06:45,520
just looks at the system dynamics without any input.

88
00:06:45,860 --> 00:06:47,690
So we consider this system over here.

89
00:06:47,720 --> 00:06:55,400
This is a mess that the system we move the mess and amount of X, and from here we let go and it should

90
00:06:55,400 --> 00:06:57,410
spring back to its initial position.

91
00:06:57,770 --> 00:07:03,530
And what we want to do is we want to look at how the position and velocity evolve with time as it's

92
00:07:03,530 --> 00:07:04,070
released.

93
00:07:05,980 --> 00:07:12,040
So using the system dynamics, we can generate the simulated response for a given configuration, so

94
00:07:12,040 --> 00:07:18,550
we'll assume a massive one kilogram adapting coefficient of one, a spring coefficient of 10, we will

95
00:07:18,550 --> 00:07:24,530
assume that the initial velocity zero and we'll give an initial displacement or point two meters.

96
00:07:24,820 --> 00:07:31,090
So that's basically saying we move this mess out here by point ten meters, we hold a stationary and

97
00:07:31,090 --> 00:07:31,840
then we let go.

98
00:07:31,840 --> 00:07:34,030
And then we look at the response of the system.

99
00:07:34,030 --> 00:07:39,910
So we simulate what is going to look like and we can see what the response is over on the results of

100
00:07:39,910 --> 00:07:41,870
the simulation over here, dysgraphia.

101
00:07:42,340 --> 00:07:44,050
So this top graph is a position.

102
00:07:44,590 --> 00:07:46,090
This graph here is a velocity.

103
00:07:46,090 --> 00:07:51,760
So you can see at time zero, we have a displacement or point two and we have a zero velocity.

104
00:07:52,480 --> 00:07:57,810
And as we let it go, the system springs back towards its zero position is neutral position.

105
00:07:58,390 --> 00:08:00,850
So initially we have zero velocity.

106
00:08:00,850 --> 00:08:01,450
We let go.

107
00:08:01,450 --> 00:08:05,950
It starts to accelerate backwards and then it oscillates back and forth.

108
00:08:06,400 --> 00:08:11,080
So we can see here also back and forth, but eventually it converges and dies out.

109
00:08:13,350 --> 00:08:18,480
So this system, the response here was done using all our integration with a really small timestep,

110
00:08:18,480 --> 00:08:26,100
you can see it here is a very small fraction of a second, but this system here can be very susceptible

111
00:08:26,100 --> 00:08:27,620
to the timestep size.

112
00:08:27,630 --> 00:08:33,360
So you can see here, if we use the timestep of point one seconds, we get a totally different spring

113
00:08:33,360 --> 00:08:34,020
response.

114
00:08:34,540 --> 00:08:40,170
So this is because the systems will inherently spring systems, spring damper systems are very stiff,

115
00:08:40,890 --> 00:08:43,010
so they're very susceptible to the timestep.

116
00:08:43,500 --> 00:08:48,140
So if we use a timestep, appoint one second, you can see that they get a very different response.

117
00:08:48,150 --> 00:08:51,850
We actually get a A system that just keeps oscillating back and forth.

118
00:08:52,320 --> 00:08:53,840
So this is incorrect.

119
00:08:54,090 --> 00:08:56,450
This is not a good simulation of the system.

120
00:08:56,460 --> 00:08:58,620
This is because the timestep is too large.

121
00:08:59,280 --> 00:09:05,040
So it is important to select a timestep that small enough to capture all the dynamics when we're using

122
00:09:05,040 --> 00:09:06,870
others first order integration.

123
00:09:07,350 --> 00:09:12,440
And if we were to use a time set even larger, we might actually get an unstable response, which we're

124
00:09:12,720 --> 00:09:17,460
talking about before, which just means that the position and velocity might distort oscillating and

125
00:09:17,460 --> 00:09:19,950
increasing larger and larger and larger in time.

126
00:09:21,380 --> 00:09:26,540
So it is important to select the correct integration method, and if we're using other integration,

127
00:09:26,540 --> 00:09:32,600
it is important to select a very small time period such that we can capture all the system dynamics.

128
00:09:33,940 --> 00:09:40,450
This allows us to be certain that the simulation results are a good approximation of the actual continuous

129
00:09:40,450 --> 00:09:42,210
time dynamics of the system.

130
00:09:44,030 --> 00:09:47,660
Now, in the previous example, we looked at the continuous time simulation.

131
00:09:47,720 --> 00:09:54,050
Now we're going to look at the discrete time simulation since the system dynamics is already in discrete

132
00:09:54,050 --> 00:09:57,080
time, the simulation of the model is very straightforward.

133
00:09:57,350 --> 00:09:59,750
We don't need to do any numerical integration.

134
00:10:00,110 --> 00:10:05,720
We only need to use the recursive solution to step forward in time from the start of the simulation

135
00:10:05,900 --> 00:10:08,390
to the end time or the desired time.

136
00:10:09,330 --> 00:10:15,360
To do this, we first assume an initial condition for the state are ignored and then we step to the

137
00:10:15,360 --> 00:10:18,560
solution using the discrete time equation of the system.

138
00:10:19,230 --> 00:10:26,550
So using our ethanol, we substitute in for X, OK, we substitute in for input at this time, set to

139
00:10:26,550 --> 00:10:30,430
get at our new time step solution for the time set in the future.

140
00:10:30,870 --> 00:10:32,190
We also propagate forward.

141
00:10:32,240 --> 00:10:35,540
Okay, so initially K is going to be equal to zero.

142
00:10:35,550 --> 00:10:36,870
So this is be ignored.

143
00:10:37,410 --> 00:10:40,750
This will be, you know, and we calculate what our X1 is.

144
00:10:41,040 --> 00:10:47,060
We also say X, we also say that K goes from zero to one and then repeat the solution again.

145
00:10:47,170 --> 00:10:48,420
Now we have X one.

146
00:10:48,630 --> 00:10:56,720
You want to work out what our x2 is and we probably get Foord K, so K goes from one plus one to two

147
00:10:56,730 --> 00:10:59,280
and we just keep repeating this step forward in time.

148
00:11:00,930 --> 00:11:05,550
So, again, if we look at the same second order mechanical system as we did for the continuous system,

149
00:11:06,330 --> 00:11:12,570
using our conversion from continuous time to discrete time, using a timestamp or point, one gives

150
00:11:12,570 --> 00:11:14,820
us this value for the F matrix here.

151
00:11:15,630 --> 00:11:22,470
So this basically is a system that it works out how we work out the new velocity and position, given

152
00:11:22,470 --> 00:11:24,330
the current velocity and position.

153
00:11:24,990 --> 00:11:30,990
And if we step forward in time and simulate it, we get a response that looks like this, which is very

154
00:11:31,170 --> 00:11:36,690
which is exactly what we got, or looks very similar as what we got in the continuous time solution.

155
00:11:36,930 --> 00:11:40,950
Except at this time, we're not we're not using a very small time set.

156
00:11:40,950 --> 00:11:42,780
We're just using TimeStep 0.01.

157
00:11:42,780 --> 00:11:50,220
So we get a solution at zero point one point two point three all the way up in this case to ten seconds.

158
00:11:51,870 --> 00:11:56,710
So in this example, we've used a time, seven point five, and we end up with a different F matrix.

159
00:11:57,510 --> 00:12:01,960
This is because we evaluated the Matrix exponential using a different Delta team.

160
00:12:02,670 --> 00:12:04,750
And again, we get a response that looks like this.

161
00:12:05,490 --> 00:12:11,790
Now, this looks now this does not look as similar as a continuous time system as we've had in the past,

162
00:12:12,180 --> 00:12:18,000
but it's still very valid, is still the perfect representation of the continuous time system, except

163
00:12:18,000 --> 00:12:22,750
that we're only calculating the solution at point five increments in time.

164
00:12:23,160 --> 00:12:25,050
So we have a solution for zero seconds.

165
00:12:25,050 --> 00:12:28,300
Point five one one point five two.

166
00:12:28,560 --> 00:12:29,190
So forth.

167
00:12:29,190 --> 00:12:30,220
All the way up to 10.

168
00:12:31,710 --> 00:12:37,200
So this is a perfectly valid representation of the continuous time system, but just in discrete form,

169
00:12:37,410 --> 00:12:41,940
we only care about the solution at point five second increments.

170
00:12:43,840 --> 00:12:50,050
And if we could take it to even more extreme, so if we just criticize the system using a date of two

171
00:12:50,050 --> 00:12:52,320
seconds, we end up with this matrix here.

172
00:12:52,600 --> 00:12:58,230
And this is the response we get when we use the recursive recursive solution and step forward in time.

173
00:12:58,750 --> 00:13:03,370
So we have a solution at zero at two, four, six, eight, 10.

174
00:13:04,120 --> 00:13:09,400
And again, you might look at this and say this looks like nothing like the continuous time solution,

175
00:13:10,000 --> 00:13:15,690
but in fact, it is a perfect representation of the continuous time solution we're only looking at at

176
00:13:15,700 --> 00:13:16,780
different time points.

177
00:13:17,350 --> 00:13:23,440
So if we go back and overlay the continuous time solution on the solution, we end up with a graph that

178
00:13:23,440 --> 00:13:24,120
looks like this.

179
00:13:24,580 --> 00:13:26,970
So the blue line is the continuous time solution.

180
00:13:26,980 --> 00:13:28,240
You can say it's nice and smooth.

181
00:13:29,140 --> 00:13:33,600
The orange line here is the discrete solution with a time set of two.

182
00:13:33,880 --> 00:13:41,890
And what you can see here is that at the zero two four six eight 10, the value of the continuous time

183
00:13:41,890 --> 00:13:44,270
and discrete time system perfectly match.

184
00:13:44,950 --> 00:13:50,410
This is because when we work out this F matrix, we're using the Matrix exponential or the integration.

185
00:13:51,160 --> 00:13:54,430
It perfectly captures all the dynamics in between here.

186
00:13:54,700 --> 00:13:59,380
But we don't need to use all our integration and simulate all the individual points.

187
00:13:59,710 --> 00:14:04,180
We can just jump from one time into the next time and into the next time.

188
00:14:04,630 --> 00:14:08,210
So this is the power of representing things as a discrete system.

189
00:14:08,680 --> 00:14:11,650
It means that we don't have to consider all the intermediate points.

190
00:14:11,920 --> 00:14:16,690
We can just consider the output or the state of the system at a time steps that we actually want to

191
00:14:16,690 --> 00:14:17,500
do something with.

192
00:14:18,250 --> 00:14:23,440
So whether this is looking at calculating a control solution or doing some data fusion, we don't need

193
00:14:23,440 --> 00:14:25,260
to know the continuous system dynamics.

194
00:14:25,270 --> 00:14:31,600
We only need to know the dynamics or the state of the system at certain points in time, which makes

195
00:14:31,600 --> 00:14:35,800
perfect sense to represent the system in discrete form because this is how it's actually going to get

196
00:14:35,800 --> 00:14:37,210
implemented in real life.

197
00:14:39,310 --> 00:14:44,950
So we've covered a very basic introduction into how to simulate continues and simulate discrete systems,

198
00:14:45,230 --> 00:14:51,220
you can see that using the this great system, it perfectly represents the continuous dynamics, except

199
00:14:51,220 --> 00:14:56,350
instead of having to integrate the system with a very small time set, we can capture all that dynamics

200
00:14:56,350 --> 00:14:59,920
inside the state transition matrix, the F and G matrixes.

201
00:15:00,370 --> 00:15:06,130
And we can calculate the system for a given times in the future and we can just step forward in discrete

202
00:15:06,130 --> 00:15:09,610
chunks of time without worrying about all the intermediate time points.

203
00:15:10,300 --> 00:15:16,840
This is the power of discrete time representation and it is the most natural way of representing a system

204
00:15:17,200 --> 00:15:21,460
when we want to do something with it, whether it's control or filtering or anything to do with the

205
00:15:21,460 --> 00:15:23,790
actual implementation in a real world system.

