Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Additional Exercise - Supplementary Material


Simple Euler Integration

Consider the following simple ordinary differential equation (ODE):

This is an example of an Initial Value Problem (IVP) that may easily be solved using any number of numerical integration techniques, the simplest of which is Euler's method. Here, continuous time is approximated by a discrete, sampled signal where each sample is seperated by a constant timestep

i.e. Now, if we assume that the derivative is constant across each sampling interval, the

trajectory can be found by solving

for all This is known as Eulers forward integration method and works well for small


Implementation

Eulers integration can be implemented within MATLAB in several diffrent ways, the one shown here is possibly one of the simplest.

First, from the IVP definition above, it is clear that we need to define the initial condition vector We also need to define the parameter values that constrain the trajectory of the ODE. Therefore, the first stage of our code should perform initialisation as follows:

As we can see in the initialisation block, definition of the constant parameters is trivial but some consideration is necessary to determine which method of initialisation of the variables is appropriate.

The key piece of information that informs this decision is whether the simulation has a fixed, known end-time from the outset, or if it is an event driven simulation, where the simulation terminates when some specific condition is met. As pre-allocating memory is much more efficient computationally, we can say

that

•   If end-time is known - pre-allocate.

•   if end-time is unknown - use append array method

When using the append array method, we typically use either the inital condition values to define the   matlab variables or an empty array '[ ]'. This second approach is typically used for defining storage for intermediate variables whose values are not known until the time loop begins.

Each iteration consists of the same two steps, first calculate the current derivative vector and once this is done, use Eulers method to integrate the state.As we have pre-allocated the time vector, we can use a for loop to increment time samples. Notice that the loop iterator variable is used to index the time vector.

To display the results, we can use the MATLAB plot command.