Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Simulating the Model

Running the Simulation

Simulating the model allows you to observe how the thermostat setting and outdoor environment affect the indoor temperature and the cumulative heating cost.

To run the simulation:

  1. In the demo model window, double-click the Scope block named PlotResults.

    The software opens a Scope window that contains two axes with the labels "HeatCost" and "Temperatures."

  2. Select Simulation > Start in the model window.

    The software simulates the model. As the simulation runs, the cumulative heating cost appears on the "HeatCost" graph at the top of the Scope window. The indoor and outdoor temperatures appear on the "Temperatures" graph as yellow (top) and magenta (bottom) signals, respectively.

Modifying Simulation Parameters

One of the most powerful benefits of modeling a system with Simulink is the ability to interactively define the system inputs and observe changes in the behavior of your model. This allows you to quickly evaluate your model and validate the simulation results. This section describes:

Changing the Thermostat Setting

Change the thermostat setting to 68 degrees Fahrenheit and observe how the model responds.

To change the thermostat setting:

  1. Double-click the Set Point block in the model window.

    The Source Block Parameters dialog box appears.

  2. Enter 68 in the Constant value field.

  3. Click OK.

    The software applies your changes.

  4. Select Simulation > Start to rerun the simulation.

    The software simulates the model.

    Notice that a lower thermostat setting reduces the cumulative heating cost.

Changing the Average Outdoor Temperature

Change the average outdoor temperature to 45 degrees Fahrenheit and observe how the model responds.

To change the average outdoor temperature:

  1. Double-click the Avg Outdoor Temp block.

    The Source Block Parameters dialog box appears.

  2. Enter 45 in the Constant value field.

  3. Click OK.

    The software applies your changes and closes the dialog box.

  4. Select Simulation > Start to rerun the simulation.

    The software simulates the model.

    Notice that a colder outdoor temperature increases the cumulative heating cost.

Changing the Daily Temperature Variation

Decrease the temperature variation to see how the model responds.

  1. Double-click the Daily Temp Variation block.

    The Source Block Parameters dialog box appears.

  2. Enter 5 in the Amplitude field.

  3. Click OK.

    The software applies your changes and closes the dialog box.

  4. Select Simulation > Start to rerun the simulation.

    The software simulates the model.

    In the Scope window, notice that a more stable outdoor temperature alters the frequency with which the heater operates.

Importing Data from the MATLAB Workspace

Simulink also allows you to import data from the MATLAB workspace to the model's input ports. This allows you to import actual physical data into your model. (For information about other data import capabilities, see Importing Data from a Workspace in the Simulink User's Guide.)

To import data from the MATLAB workspace:

  1. In the MATLAB Command Window, create time and temperature data by entering the following commands:

    x = (0:0.01:4*pi)';
    y = 32 + (5*sin(x));
    z = linspace(0,48,1257)';
  2. In the Simulink model window, select the Avg Outdoor Temp block, then press the Delete key to delete it.

  3. Delete the following items from the model in the same way:

    • Daily Temp Variation block

    • Two input signal lines to the Sum block

    • Sum block

    The model should now look similar to the following figure. Notice that the output signal from the Sum block changes to a red, dotted line, indicating that it is not connected to a block.

  4. If the Simulink Library Browser is not open, select View > Library Browser in the model window to open it.

  5. Select the Sources library in the Simulink Library Browser.

  6. Select the In1 block in the Simulink Library Browser, then drag it to the model window.

    An In1 block appears in the model window.

  7. Connect the dotted line (originally connected to the Sum block) to the In1 block.

  8. Select Simulation > Configuration Parameters in the model window.

    The Configuration Parameters dialog box appears.

  9. Select Data Import/Export in the menu on the left side of the dialog box.

    The Data Import/Export pane appears.

  10. Select the Input check box in the Load from workspace section.

  11. Enter [z,y] in the Input field.

  12. Click OK.

    The software applies your changes and closes the dialog box.

  13. Select Simulation > Start to rerun the simulation.

    The software simulates the model.

    In the Scope window, notice that the model ran using the imported data, showing colder temperatures and higher heat use.

Exporting Simulation Data to the MATLAB Workspace

Once you have completed a model, you may want to export your simulation results to MATLAB for further data analysis or visualization. (See Exporting Data to the MATLAB Workspace for information about additional data export capabilities.)

To export the HeatCost data from the model to the MATLAB workspace:

  1. Select the Sinks library in the Simulink Library Browser.

  2. Select the Out1 block in the Simulink Library Browser, then drag it to the top right of the model window.

    An Out1 block appears in the model window.

  3. Draw a branch line from the HeatCost signal line to the Out1 block. For more information, see Drawing a Branch Line.

  4. Select Simulation > Configuration Parameters in the model window.

    The Configuration Parameters dialog box appears.

  5. Select Data Import/Export in the menu on the left side of the dialog box.

    The Data Import/Export pane appears.

  6. Select the Time check box in the Save to workspace section.

  7. Select the Output check box in the Save to workspace section.

  8. Click OK.

    The software applies your changes and closes the dialog box.

  9. Select Simulation > Start to rerun the simulation.

    The software simulates the model and saves the time and HeatCost data to the MATLAB workspace.

    Notice that the tout and yout variables now appear in the MATLAB workspace.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS