So now let's have a look at the pendulum, the system, a simple pendulum system has a mass that suspended
from a pivot point that allows it to freely swing back and forth.
Breaking the system down, that's a shame that we have a weight of mass m at the end of this weightless
arm of length L from a pivot point, the angle that the arm is can be described by the angle theta and
its velocity is described by the angular right theta dot.
The forces tau can be applied to the system as the input or just left as zero for the free response
or unforced response of the system.
The equation of motion, of the angle of motion can be derived from the forces and inertia which results
in the nonlinear differential equations that describe the motion of the dynamic system as shown here.
You can see from the equation that is a non-linear due to this time here, ordinary differential equation.
So the first step in modeling this system is to break it down into the state's best representation of
two first order systems.
So the states X1 and x2 of the system become theta and theta dot with the state right dynamics for X1
and x2 described by using these equations here.
Now, if we assume that our state X1 or Theta is always going to be a small angle, so say within 15
degrees, then we can approximate this sine Theta X here using this small angle approximation and we
just can approximate it to be theta or X1.
So the system expressed in the linear continuous space form is approximately given by this linear states
based system here.
So we can say we replace the sign X with just X or Theta and we've ended up with this date space from
here.
Now we can turn this continuous linear system into a discrete form using the matrix exponential relationship
for filtering an estimation as we've done in the past.
So let's build a path, a model for the non-linear and linear approximation of the system and simulate
the dynamics of both systems and see the responses.
So here we have the Python script called Assignment to underscore Sim's Peiyi.
Now this simulation script simulates a free or unforced response of the linear and nonlinear versions
of the pendulum dynamic system.
So we have a look at the code here, we can see.
We first set up the simulation properly, so we set up a time set up date of our point, zero one seconds,
a simulation time of 10 seconds.
So we're going to simulate the dynamics for over ten seconds.
We set up our system properties for the pendulum.
So we define our gravitational constant being a nine point eight one, we have the length of the pendulum
pain point five meters.
And then we also set up the initial theta for the initial condition of the pendulum.
And we've said it to be ten degrees.
This part of the curve here, this is where we define the linear system.
So this is the linear approximation and on the system and we use the continuous form to work out the
straight matrix using our matrix exponential.
And then lower in the code, we can actually see where we do the integration.
So this is a simulation code that steps through time.
We work at the linear system dynamics by basically propagating our X linear state, using our F matrix
multiplied by our current X matrix.
Our nonlinear equations are calculated here.
So we work out our theta acceleration and we integrate that to get our theta dot.
And then we do the same thing for Theta and then we have some code down here that just does animation.
So let's run this simulation as is.
So we're starting off our simulation with the pendulum being at 10 degrees.
So let's run this.
So you can see we have an animation pop up and there's actually a red line and a blue line in this animation,
the red line is the linnaeus' system, the blue line is the nonlinear system.
So we can see when we started this simulation off at 10 degrees, both systems are fairly well aligned.
They both agree there's not too much variation between the two different systems.
So we'll run us again.
So you can see that both of the non-linear and linear responses pretty much track each other.
So there's little error between the two.
Now, if we were to run this with a different initial angle, so let's say instead of 10 degrees, we
set this to be 45 degrees.
Now I angle of 45 degrees is going to be definitely outside the linear zone of the sine function.
So it will be a bad approximation to use a small angle approximations on angles such as 45 degrees.
So now let's run the simulation.
OK, now we're getting a very big difference between a linear system and nonlinear system.
So, again, the red line here is the linear system.
The blue line here is the nominee system.
So you can see quite a dramatic difference between the two.
And the longer you run, this is just going to continuously be out of phase and offset and drift.
So we have to be careful when we're using a litany, linear approximation of a nominee system.
We have to make sure that we are operating inside the linear range for the linear approximation to be
valid.
So when we use a common Thawra to estimate our angle theta, we just have to be wary of these limitations.