In this example we will solve a 2.order differential equation with simulink. The method described in this example may be used to solve higher order ODEs simply by adding equally many integrator components (3.order would need 3 integrators). 

The spesific equation for this example is: The initial conditions for this case isOne could easily change the constants or the right hand side of the equation to solve an infinite amount of equations. To solve the equation we rearrange the equation so the highest order of derivative is alone on L.H.S

The problem at hand is a 2.order ODE an following it makes sense that you need to integrate twice to get a equation for y.

  • Add two integrator boxes by pressing the button above tab and start typing "integrator". Repeat to add the second one
  • By clicking the boxes we can edit them. Here you may change the initial condition for the equation. In our case y(0) and y'(0) is both zero so there is no need to edit the integrator

The standard library for Simulink contains boxes for most ordinary mathematical operations. Gain is for multiplication and sum is for addition/subtraction. 

  • Add a sum box either by using the library or searching like previously described.
  • Double click the sum box to configure inputs. From equation (2) we see that we need to subtract two of the inputs and add the constant.  For this example the sum box is configured to "- + -". The order of the symbols dictate the layout of the input ports. 
  • Add a gain block after each integrator, this is to multiply the constants to each part of the equation. You may flip the blocks (Ctrl + I


Simulink provides with several blocks for input. Examples are pulse-generator, sine-wave and step. The simplest type of input is the constant. It as the name implies supplies a constant number input to the model. 

  • Add a constant from the block library. Double click the box to rename and change value. 

The easiest way to display the output in Simulink is by using an Scope-block. After running the simulation (Ctrl + T), double click the scope-block to open up a result window. Other options include a dashboard scope, an embedded version of the regular scope.  

After following these steps, the result should be something like this:

In the scope (or dashboard scope) you may click the connection between the first and the second integrator to add a graph of the first derivative (dashed-orange). The solid blue line describes y. Screenshot from the dashboard scope is plottet below

The model used for this example is available for download (here ODE.slx). You may experiment with uncommenting the sine wave source for a more interesting solution.  

Page content



  • No labels