Accelerating the pace of engineering and science

# Documentation

## Anatomy of the Control System Model

### Overview of the Example Model

The model for this example is called sldemo_househeat. It models the heating system and thermodynamics of a house.

1. Start MATLAB®, and then in the MATLAB Command Window, enter

`sldemo_househeatsldemo_househeat`

The Simulink® Editor opens with the example model.

The sldemo_househeat model defines the dynamics of the outdoor environment, the thermal characteristics of the house, and the house heating system. It allows you to simulate how the thermostat setting and outdoor environment affect the indoor temperature and cumulative heating costs.

The example model includes many of the same blocks you used to create the simple model in Create a Simple Model. These blocks include:

• A Scope block (labeled PlotResults) on the far right — displays the simulation results.

• A Mux block at the bottom right — combines the indoor and outdoor temperature signals for the Scope.

• A Sine Wave block (labeled Daily Temp Variation) at the bottom left — provides one of three data sources for the model.

In the model, the thermostat is set to 70 degrees Fahrenheit. Fluctuations in outdoor temperature are modeled by applying a sine wave with amplitude of 15 degrees to a base temperature of 50 degrees.

The three data inputs (sources) are provided by two Constant blocks (labeled Set Point and Avg Outdoor Temp), and the Sine Wave block (labeled Daily Temp Variation). The Scope block labeled PlotResults is the one output (sink).

### Subsystems in the Example Model

A subsystem is a hierarchical grouping of blocks encapsulated by a single Subsystem block. The sldemo_househeat model uses subsystems to:

• Simplify the appearance of the block diagram

• Create reusable components

• Customize the appearance of blocks

The example model uses the following subsystems: Thermostat, Heater, House, Fahrenheit to Celsius, and Celsius to Fahrenheit.

1. In the MATLAB Command Window, enter

`sldemo_househeat`

The example model opens in the Simulink Editor model window.

 Tip   You can use content preview to display a representation of the contents of a subsystem, without opening the subsystem. Content preview helps you to understand at a glance the kind of processing performed by the subsystem. For details, see Preview Content of Hierarchical Items.
2. Subsystems can be complex and contain many blocks that might otherwise clutter a diagram. For example, to open the House subsystem, double-click the House Subsystem block.

The House subsystem receives heat flow and external temperature as inputs, which it uses to compute the current room temperature. You could leave each of these blocks at the top level of the main sldemo_househeat model, but combining them as a subsystem helps to simplify the block diagram.

3. A subsystem can also be simple and contain only a few blocks. For example, to open the Thermostat subsystem:

1. Display the sldemo_househeat top model. To do so, in the tabs at the top of the model window, ( ), click sldemo_househeat. The sldemo_househeat model appears in the model window.

2. Double-click the Thermostat Subsystem block.

This subsystem models the operation of a thermostat, determining when the heating system is on or off. It contains only one Relay block, but logically represents the thermostat in the block diagram.

The sldemo_househeat model contains two instances of identical subsystems named Fahrenheit to Celsius. These subsystems convert the inside and outside temperatures from degrees Fahrenheit to degrees Celsius.

1. Display the sldemo_househeat model, by selecting sldemo_househeat in the tabs at the top of the Simulink Editor model window.

2. Double-click the Fahrenheit to Celsius masked Subsystem block. The custom dialog box for the F2C block opens.

Click OK.

3. To view the underlying blocks in the Fahrenheit to Celsius conversion subsystem, select the Fahrenheit to Celsius Subsystem block and then select Diagram > Mask > Look Under Mask.

### Creating a Subsystem

Subsystems allow you to group related blocks into one block. They are also reusable, enabling you to implement an algorithm once and use it multiple times.

1. Display the sldemo_househeat model, by selecting sldemo_househeat in the tabs at the top of the Simulink Editor model window.

2. In the model window, click and drag a bounding box around the Set Point and Fahrenheit to Celsius blocks.

3. From the Simulink Editor menu, select Diagram > Subsystem & Modeling Reference > Create Subsystem from Selection. The blocks are combined into one subsystem block.

You can customize the appearance of a subsystem by using a process known as masking. Masking a subsystem allows you to specify a unique icon and dialog box for the Subsystem block. For example, the House and Thermostat subsystems display custom icons that depict physical objects, while the conversion subsystems display custom dialog boxes when you double-click the blocks.

1. In the model window, right-click the new subsystem block (as described in Creating a Subsystem). In the context menu, select Mask > Create Mask. The Mask Editor dialog box opens.

2. At the bottom of the Mask Editor dialog box, expand the Command list. Select disp (show text in center of block). The dialog box displays the syntax for this command below the list.

3. In the Icon Drawing commands field, enter disp('Select Temperature').

4. Click OK. The subsystem block displays the text that you entered.

To see the full text in the block icon, select a corner of the block and drag to expand the size of the block.