Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

 

Student Center

Model a simple control system


The following exercise demonstrates some of the functionality within MATLAB and Simulink:

  1. How to model a simple control system within Simulink
  2. How to modify Simulink model elements from the MATLAB command prompt
  3. How to simulate from the MATLAB command prompt
  4. How to view and modify the outputs from a Simulink model within the Simulink viewer (Scope block)

Observe the responses of the following systems to a unit step change (at t=5 ) when operating in a closed loop. You may want to use these systematic simulations to help explain why each system reacts as it does, and how to differentiate it from the others.

  1. Num = [1] and Den = [1 0.25]
  2. Num = [1] and Den = [1 2]
  3. Num = [1] and Den = [1 0 1]
  4. Num = [1] and Den = [1 1 5]
  5. Num = [1] and Den = [1 6 2 0]

Solving the problem:

We will solve this problem set using the SIM command, as well as the GET_PARAM and SET_PARAM functions.
Lets first create the model:

  1. Open a new Simulink model
  2. Drag and drop in a Step block, a Transfer Function block, a Sum block and a Scope block. Connect the signals, and fill in the appropriate values for the first example.
  1. Double-click on the Step Input block to specify the time of the step change. Select a unit step change from 0 to 1 to occur at time = 5.
  2. Double-click on the transfer function block and enter the numerator and denominator coefficients, which represent the systems defined above. For the first system, the numerator should be equal to [1] and the denominator should be [1 0.25]. The coefficients are entered in descending powers of s. Click on OK when the coefficients have been entered.
  3. The sum block merely sums its inputs and will be used as the comparator. Double-click on this block to change the list of signs to read:
    |+-
    This block will now take two inputs and will subtract the second input (the feedback constituent) from the first input (the "set-point" or reference input).
  4. For this example, it is necessary to plot both the input value and the output value. You must change the Scope block to accept two inputs. Double-click on the Scope block. The second button from the left is called "Parameters". Click here, and then change the “Number of axes”' to 2 and click on OK. Please note, within this parameter block, you can also modify the Scope block's Data History. You can control the amount of data that the Scope stores and displays by setting fields on the Data History pane. You can also choose to save data to the workspace in this tab. You apply the current parameters and options by clicking the Apply or OK button. The values that appear in these fields are the values that are used in the next simulation.
    Once you have connected all of the blocks correctly, the system should look like something this:

    figure 1
  5. Now we are ready to simulate the first step response. Let's set the simulation time to 15 seconds. In your model, go to Simulation ->Simulation parameters and set the Stop time to 15. Click OK and then use the Start Simulation menu button to run the simulation. (This button looks like an arrow). Once the Simulation is complete, double-click on the Scope to see the results. You can use the Autoscale button within the menu bar of the scope to clarify the results:

    figure 2
  6. For the next simulation, we will need to change the numerator and denominator values for the transfer function block. To do so, we can either double-click on the block to enter the values (as we did for the first simulation), or we have the option to change the values from the command line, using the GET_PARAM and SET_PARAM functions. Let's take a look at this process:

    1. After making the Transfer Function block current within the model (by single-clicking on the block), return to the MATLAB command prompt. Type the following:

      get_param(gcb, 'objectparameters')
      The 'gcb' is an acronym which stands for "Get Current Block." You could also have used the following:

      get_param('mymodelname/Transfer Function', 'objectparameters')
  7. You will see the following in the command window:
ans=
Orientation:
ForegroundColor:
BackgroundColor:
DropShadow:
NamePlacement:
ShowName:
Priority:
AttributesFormatString:
AncestorBlock:
ReferenceBlock:
UserDataPersistent:
UserData:
RTWdata:
Diagnostics:
DialogParameters:
CompiledSampleTime:
InputSignalNames:
OutputSignalNames:
ModelParamTableInfo:
CopyFcn:
DeleteFcn:
UndoDeleteFcn:
LoadFcn:
ModelCloseFcn:
PreSaveFcn:
PostSaveFcn:
InitFcn:
StartFcn:
StopFcn:
NameChangeFcn:
ClipboardFcn:
DestroyFcn:
OpenFcn:
CloseFcn:
ParentCloseFcn:
MoveFcn:
BlockType:
BlockDescription:
LinkStatus:
PortConnectivity:
PortHandles:
CompiledPortWidths:
CompiledPortDimensions:
CompiledPortDataTypes:
CompiledPortComplexSignals:
CompiledPortFrameData:
DataTypeOverride_Compiled:
MinMaxOverflowLogging_Compiled:
ExtModeUploadOption:
ExtModeLoggingSupported:
ExtModeLoggingTrig:
FontName:
FontSize:
FontWeight:
FontAngle:
Selected:
Numerator:
Denominator:
AbsoluteTolerance:
MaskType:
MaskDescription:
MaskHelp:
MaskPromptString:
MaskStyleString:
MaskTunableValueString:
MaskCallbackString:
MaskEnableString:
MaskVisibilityString:
MaskToolTipString:
MaskVarAliasString:
MaskVariables:
MaskInitialization:
MaskDisplay:
MaskSelfModifiable:
MaskIconFrame:
MaskIconOpaque:
MaskIconRotate:
MaskIconUnits:
MaskValueString:
MaskRunInitForIconRedraw:
Mask:
MaskEditorHandle:
MaskCallbacks:
MaskEnables:
MaskNames:
MaskPropertyNameString:
MaskPrompts:
MaskStyles:
MaskTunableValues:
MaskValues:
MaskToolTipsDisplay:
MaskVisibilities:
MaskVarAliases:
MaskWSVariables:
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]
[1x1 struct]

These are all of the editable properties for this particular block. You can find out what each parameter specifies for a particular block by modifying the usage of the GET_PARAM command. For example, we are interested in the Numerator and Denominator parameters. So type the following:

get_param('mymodelname/Transfer Function', 'Numerator')

ans =

[1]
get_param('mymodelname/Transfer Function', 'Denominator')

ans =

[1 0.3333]

  1. We now need to set the new values for these parameters. Type the following at the MATLAB command prompt:

    set_param('mymodelname/Transfer Function', 'Numerator', '[1]')

    set_param('mymodelname/Transfer Function', 'Denominator', '[1 2]')


    In this case, we did not need to reset the Numerator, as the existing value was the same for the following simulation; however, it is shown here for your future assistance.

    You can confirm the changes to your model, made from the command line, by double-clicking on the Transfer Function block within the model.
  2. We now have set the new values in the model. To run the simulation, again, we have two choices. We could simply use the "Start Simulation" menu button to run the simulation, as we did for the first simulation. OR, we can also run the simulation from the command line, using the SIM command:

    1. To simply run the simulation, type the following:

      sim('mymodelname')
      If you return to the model and open the scope block, you can see the new results:

      figure 3
    2. We can repeat steps 4 and 5 above for each of the required simulations.
    3. Note, if you would also like to plot the error of this system, you would again need to change the Scope block to accept three inputs.
      1. Double-click on the Scope block. Click on the "Parameters" button (second button from the left), and now change the "Number of axes" to 3 and click on OK. You should then modify your signal connections to display neatly within your model, as shown in the figure below:

        figure 4

        Here is the final plot, with the error shown within the middle axes:

        figure 5

 :

Contact sales
Software evaluation for instructors
Free technical kit
E-mail this page

MATLAB & Simulink Student Version

Includes full-featured versions of both MATLAB and Simulink

From School To Industry

"The only limit to MATLAB is your imagination."
Carl Klopstein
Radar Systems Engineer