In this tutorial, we explain how to simulate ordinary differential equations in Simulink. The YouTube tutorial accompanying this webpage is given below.
Example and Preparation Steps
We explain the simulation process by using a particular example.
Problem: Simulate ordinary differential equation
(1)
where
The Simulink model is shown in the figure below.
The simulated solution
In the sequel, we explain how to create this model.
Before we start with the Simulink modeling, we first need to transform our equation into the appropriate form. The transformation process consists of the following steps.
STEP 1: In this step, we want to express the first derivative of
(2)
STEP 2: In this step, we eliminate the first derivative by using the fact that the first derivative of
(3)
STEP 3: Similarly to STEP 1, we move the variable
(4)
The term
(5)
is an integrator. It is modeled as an integrator block in Simulink.
Now, we are ready to construct the Simulink block diagram.
Simulink Implementation
First, we create a new MATLAB script and define the variables
(6)
We load these variables in the MATLAB workspace. The Simulink workspace is able to directly read these variables from the MATLAB workspace.
Next, we construct the expression in the brackets
(7)
The Simulink block diagram is shown below.
Next, we include the constant
Finally, we add the feedback and the scope. This is shown in the figure below.