In this part of the tutorial, we will quickly go over the Simulink Model. The Simulink Model is of a mass-spring-damper system, which is a simple 2nd order system. The following is a free body diagram of the mass-spring-damper system.

Mass Spring Damper System

It is assumed here that you know how to use Simulink and understand the basic theory of the mass-spring-damper system, so I will not go into any detail on how the model was generated or how equations were derived. If you are clueless on using Simulink, this is a good place to visit.

  1. First, download the sample files provided here. Unzip the files and place them wherever you please. The zip file includes 4 files: simulink_gui.fig, simulink_gui.m, simulateButton.m, and mass_spring.mdl.

  2. The following is a diagram of the Simulink Model for the above system.

    Simulink Model

  3. Notice that the Gain blocks use variables instead of number values: 1/m, c/m, and k/m. To simulate this system from the command line, we use the sim command. Since the Simulink Model is linked to the main workspace by default, the parameters m,c and k must be defined within the main workspace in order for the sim command to work properly. Otherwise, an error will result. There are ways to get around this using the command simset, and we will discuss this in the next section.

  4. Thus, if the variables m,c, and k are not defined in the main workspace and we try to use a function like the one listed below, an error would result!

    function runSimulinkModel(m,c,k)
    sim('mass_spring');
  5. This can be especially troublesome if you are trying to interface your Simulink Model into a GUI because GUIs store all their information outside from the main workspace. In the next section, we will discuss two ways to resolve this problem.

Pages: 1 2 3 4