Section 6.8 Matlab apps for interactive learning

Virtual laboratories which have simple GUI interfaces so students can select buttons and sliders to observe the behaviour of some authentic scenarios and see how different parameter choices affect behaviour. Each virtual laboratory comprises two files which run independently: i) the mlapp file which is the laboratory itself and ii) a partner livescript file which acts like a concise manual giving context, illustrative MATLAB source code and some technical background. 

The resources/toolbox developed here are now most easily used from within MATLAB by downloading the control 101 toolbox; see section 6.11 for more details.

More information and guidance on each app is available in videos on a youtube playlist. Apologies but problems with youtube mean that the playlist is not currently ordered so please search the whole playlist.

Alternatively, the source files are available on the following google folder. A summary is given below for completeness and the links take you lower on the page where more detailed summary information is available.

Naming conventions are largely self-evident. For example, a typical naming convention for the paired app files is: mixingtank_and_behaviour.mlapp & mixingtank_and_behaviour_manual.mlx.

TABLE OF CONTENTS FOR THIS PAGE BELOW

Illustration of running an app

Ensure the file is on the search path or, better still, ensure  Matlab is the same folder as the app (type "what" to see which files are in the current folder) and simply type the name in the command window

The figure here shows how to run the app "masspringdamper.mlapp".

The videos listed above also demonstrate that use of the APPs is largely intuitive thereafter.

1st order model behaviour characterisation

A simple interface emphasis the core role of the time constant and gain parameters in the step response behaviour and convergence.

Allows the user to vary the model parameters and initial condition and visualise the core invariance aspects in the response and how these relate to time constant and gain. User simply moves the sliders and the figure updates.

1st order modelling from responses

A simple interface to practice estimation of time constant and gain from a step response for a 1st order model. The app supports students in being able to make quick and accurate estimates of the time constant and gain and to check the accuracy of their estimates against the true answers. 

The figure keeps track of multiple attempts so students can iterate intelligently and thus improve their understanding.

Mixing tank behaviour

We consider a tank with inlet and outlet pipes and a constant flow rate. The inlet concentration is not the same as the outlet concentration and thus, assuming good mixing, the tank will gradually change concentration (colour). 

A typical model is given as: V (dC/dt) + F C = F Cin  where V is the tank volume, F is the flow rate, C is the concentration in the tank and  Cin is the concentration of the inlet flow.

In practice there may also be a reaction taking place within the tank that affects concentration dynamics and also disturbances to the inlet concentration.

Tank level behaviour

How quickly and where does the level in a tank settle given a fixed in flow, and variable area/outlet resistance? The figure gives a visualisation of the tank attributes so users can: i) manually (through yellow sliders) change the area/outlet resistance and in-flow; ii) modify the environment/disturbances (green sliders) and iii) simulate to see the actual behaviour, time constant and gain.

The lower right figure store previous simulations so the user can observe trends and understand design principles. Animation effects in the top figure bring some life and visualisation to the app. The bottom left figure focuses on an analysis of the time constant and gain.

Tank level control with PI

Investigate the depth level control of a tank with a PI design,  Use sliders to select PI values and the dimensions of the tank. 

Uncertainty is included in two forms:

The lower figures store previous simulations so the user can observe trends and understand design principles. Animation effects in the top figure also bring some life and visualisation to the app.

Tank level story file

This file takes a user through the entire process of modelling, analysing, controller design and final evaluation, for a tank level system, in the presence of multiple forms of uncertainty. Different tabs move the user along the storyline. The first tab explores open-loop behaviour and the impact of flow disturbances and blockages to the outlet pipe. The second tab focuses on modelling in time constant form. The third tab covers manual control subject to uncertainty. The fourth tab introduces PI design and the fith tab is an opportunity to evaluate the final PI design, subject to more varied uncertainty, so including sensor delays and measurement noise.         

For tabs 1, 3 and 4, the top right figure store previous simulations so the user can observe trends and understand design principles; use refresh if  this is unhelpful. The bottom right figure forms a different role in each tab so is automatically refreshed for each simulation. Animation effects in the top figure also bring some life and visualisation to the app.

Heat exchanger behaviour

We consider a heat exchanger with inlet and outlet pipes and a constant flow rate. The inlet temperature is not the same as the outlet temperature due to supplied heating and thus, assuming good mixing, the inlet flow will gradually change temperature, represented by colour, in the tank. In practice there may also be a disturbances to the inlet temperature and flow rate, as well as changes in tank volume and heating; users can investigate the associated behaviours with this app. 

Car speed behaviour

This app allows users to investigate the dependence of a car speed behaviour on simple parameters such as car mass, friction, engine power, road slope and wind.

It also has a figure to emphasise the computation of an equivalent first order model in time constant form.

The lower figures store previous simulations so the user can observe trends and understand design principles. Animation effects in the top figure also bring some life and visualisation to the app.

Cruise control with PI

We consider a car can be represented as a simple mass-damper model, the damping representing friction which is assumed proportional to velocity and throttle position gives effective force on the road. We wish to control the speed of the car and also, subject to wind and slope variations so a PI compensator is adopted.

This app allows the user to explore the impact on closed-loop behaviour of variations in the car and PI parameters and disturbances.

House temperature and thermal system behaviour

Allows the user to investigate the behaviour of a thermal system, here represented by a simple house heating model. The user can change the size of the house (thermal capacity), wall thickness/insulation (heat loss), heat supply, external temperature and initial condition. 

This app allows the user to explore/overlay the impact of different choices on the behaviour. Red represents hot and blue represents cold.

House temperature story line app

This file takes a user through the entire process of modelling, analysing, controller design and final evaluation, for a thermal system, in the presence of multiple forms of uncertainty. Different tabs move the user along the storyline. The first tab explores open-loop behaviour and the impact of external temperature disturbances and wind chill. The second tab focuses on modelling in time constant form. The third tab covers manual control subject to uncertainty. The fourth tab introduces PI design and the fith tab is an opportunity to evaluate both the final PI design and on-off control, subject to more varied uncertainty, so including sensor delays and measurement noise.     

Red represents hot and blue represents cold and green arrows represent the wind chill.  For tabs 1, 3 and 4, the top right figure store previous simulations so the user can observe trends and understand design principles.

DC servo modelling and control

We consider a DC servo driving a simple passenger on a seat along a track. This app allows the user to investigate both open-and closed-loop behaviour. 

Mass-spring-damper systems and landing aircraft behaviour

Allows the user to investigate the behaviour of 2nd order mass-spring-damper systems through the example of the suspension unit under and landing aircraft. 

This app allows the user to explore/overlay the impact on landing behaviour and passenger comfort (oscillation and acceleration) of variations in the suspension parameters and plane mass. 

Inverted pendulum and human in the loop control

Allows the user to investigate the impact of real environmental issues on the control of an inverted pendulum. For example:

This app allows the user to explore/overlay the impact on closed-loop behaviour of variations in the the choices above.

Behaviours of linear models

Allows the user to investigate the impact of pole positions on linear system behaviour. Allows real, complex and unstable poles. Three different tabs:

The user can also use the mouse to 'move/change' pole and  zero positions using the bottom right hand picture.

Predator - prey Models

Predator prey models are an example of a non-linear ystem. Non-linear systems have far more complex and sometimes complicated behaviour compared to linear systems and at times appear to behave in a somewhat chaotic fashion.  This scenario also implicitly contains feedback between the different model states. The scenarios and choices in the app allow for relatively simple changes in the parameters, but these are enough for users to observe and understand the associated complexity of the behaviours. 

PI tuning practice

Allows the user to practice doing some PI designs on a range of simple systems with fixed dynamics. The closed-loop has a simple standard block diagram as shown, with C(s) the compensator and G(s) the system.

The custom tab allows the user to enter a system of their own choice.

PID tuning methods

Allows the user to practice using some standard PID tuning methods on a range of simple systems with fixed dynamics. Inlcudes Ziegler Nichols, Cohen Coon, Amigo, One third, Skogestad and Lambda tuning. More detailed technical and analytical background is provided  in the partner livescript file pidtuningrules_manual.mlx and pid_tuning_methods.mlx. The latter file also includes some simple MATLAB code snippets than can be used for equivalent analysis.

Frequency response

This is a simple interface to understand the concept of frequency response in a time domain scenario.  Users can excite a variety of lienar systems with a sinuosidal input and view the system responses. The figures are presented in such a way that users can infer the implied gain and phase shifts of the output relative to the input. Numerical calculations are also provided. More detailed technical and analytical background is provided  in the partner livescript file frequency_response_time_behaviour_manual.mlx. This file also includes some simple MATLAB code snippets than can be used for equivalent analysis.

Proportional design using frequency domain methods and a phase margin criteria

This resource provides an interactive app file (MATLAB virtual laboratory) which demonstrates how to perform a simple lag compensator feedback design using Bode diagrams with a phase margin and low frequency gain criteria. The app includes a number of pre-coded examples and allows the user to investigate both how to meet the requirements and the impact of this on closed-loop behaviour. The manual and app also give guidance on a mechanistic design to achieve the specified criteria. The low frequency gain criteria takes two alternative forms depending upon whether the system includes and integrator or not. For completeness the behaviour with the lag compensator is compared with a simple gain design, so the differences can be evaluated. 

Lag compensator design using frequency domain methods with phase margin and low frequency gain criteria

This resource provides an interactive app file (MATLAB virtual laboratory) which demonstrates how to perform a simple lag compensator feedback design using Bode diagrams with a phase margin and low frequency gain criteria. The app includes a number of pre-coded examples and allows the user to investigate both how to meet the requirements and the impact of this on closed-loop behaviour. The manual and app also give guidance on a mechanistic design to achieve the specified criteria. The low frequency gain criteria takes two alternative forms depending upon whether the system includes and integrator or not. For completeness the behaviour with the lag compensator is compared with a simple gain design, so the differences can be evaluated. 

Lead compensation design

This resource provides an interactive app file (MATLAB virtual laboratory) which demonstrates how to perform a simple lead compensator feedback design using Bode diagrams with a phase margin and bandwidth criteria. The app includes a number of pre-coded examples and allows the user to investigate both how to meet the requirements and the impact of this on closed-loop behaviour. The manual and app also give guidance on a mechanistic design to achieve the specified criteria. For completeness the behaviour with the lag compensator is compared with a simple gain design, so the differences can be evaluated.

Lead-lag compensation design

This resource provides an interactive app file (MATLAB virtual laboratory) which demonstrates how to perform a simple lead-lag compensator feedback design using Bode diagrams with a phase margin, bandwidth and low frequency gain criteria. The app includes a number of pre-coded examples and allows the user to investigate both how to meet the requirements and the impact of this on closed-loop behaviour. The manual and app also give guidance on a mechanistic design to achieve the specified criteria. The low frequency gain criteria takes two alternative forms depending upon whether the system includes and integrator or not. For completeness the behaviour with the lead-lag compensator is compared with a simple gain design and a lead only design, so the differences can be evaluated.

Compensator design using criteria

The apps above establish that proportional, lag, lead and lead-lag design can be tied explicitly to the design criteria of phase margin, bandwidth and offset. Consequently, fix the criteria and the design is also fixed. This app allows users to compare and contrast the behaviour and performance of different compensators arising from such a criteria based design approach and indeed, to observe that criteria are not always achievable.

Aeroplane roll control with lead compensation

Allows the user to investigate the efficacy of simple lead compensation for controlling the roll angle of a simple aircraft.

The app shows the Bode diagrams with core attributes of the compensator and compensated cross-over frequencies/margins to help the user make sensible choices. 

The bottom figure will store previous designs to allow a compare and contrast investigation.

OLDER FILES for those who may want access

Recently MATLAB moved GUIs to a new app format. Just the mlapp file is needed to run the APP.  A summary of the EARLY apps is given below FOR COMPLETENESS along with outline instructions for their usage.   These can be downloaded from the zip file here and videos  illustrate the basic APP usage for four of the examples below: tank level, car velocity, mixing tankhouse temperature.

These apps are gradually being modernised and standardised as part of the toolbox project outlined in section 6.10. More recent files are available from the google folder and overviewed higher on this page.

 Available apps cover topics such as those listed here; more detail is lower on this page:

Resistance of an electrical circuit: resistorcircuit.mlapp

Students can investigate parallel  (closed switch) and series (open switch) arrangements; the switch indicates the arrangement but the figure shows data for both regardless. 

When the resistances R2 and/or R3 are changed the figure adds a new point so that trends can be observed.

1st order responses and basic analysis: modelparameters.mlapp

Used to test student ability to determine the time constant and gain of a 1st order model from a step response. Assumes the input is one. 

STEP 1: Each time you select the yellow button, a new example is generated.

STEP 2: Enter your estimates in light brown boxes.

STEP 3: Press "test my results" to check for accuracy and compare your guess with the  correct results (shown with dashed lines on plot and numbers in blue boxes).

1st order responses and basic analysis: modelparameters2.mlapp

Determine the time constant from limited data. Assumes the input is one. Each time you select the yellow button, a new example is generated which contains 3 values: i) initial condition; ii) asymptotic value and iii) a single intermediate value (see below marked with a cross). From these students estimate the time constant. The test results button overlays the student ‘model’ with the correct answer.

STEP 1: Select the yellow button for a new example.

STEP 2: Enter your time constant estimate in blue box.

STEP 3: Press "test my results" to check for accuracy and compare your guess with the  correct results.

Second order dynamics and under-damping: secondorderbehaviours.mlapp

This app assumes a stable 2nd order system with a constant numerator and illustrates the conventional analysis of overshoot, oscillation and 1st peak overshoot time (half period).  Users can use random examples or enter the denominator coefficients directly to investigate the impact of varying damping and frequency.

Generic system behaviours: behaviours.mlapp

Allows students to randomly generate transfer functions of different orders, with or without complex poles and with or without unstable poles. Alternatively, enter the numerator and denominator parameters directly into the boxes. The right hand figure shows the pole and zero positions. "Test my results" shows the unit step response.

[Warning: random generation may include a pole on the origin which results in a step response with a ramp.]

Level response in a tank: tankbehaviour.mlapp and tankbehaviour2.mlapp

How quickly and where does the level in a tank settle given a fixed in flow, and variable area/outlet resistance? The figure gives a visualisation of the tank attributes so students can: i) manually (through brown boxes) change the area/outlet resistance; ii) update figure to visualise and iii) use test my results to see the actual behaviour, time constant and gain.

The 2nd APP allows overlaying of the behaviour as parameters change so that users can plan and observe trends, for example the impact of increasing cross-sectional area. Change sliders to the desired values and use "new simulation" to add a new line plot.  Refresh will clear the figures so you can begin observing a different set of trends. The box allows users to add and observe the impact of a disturbance inflow 'd'.

A  video giving some background and illustrations of usage is available here.

The speed of a car: carvelocity.mlapp and carvelocity2.mlapp

Investigate the speed response of a car modelled as a mass-damper system. The users change the car mass and friction (damping) and observe the change in speed response (time constant and gain). Results are overlaid so that trends can be observed - users can manually enter values in brown boxes to control this or get random new examples from the yellow box; use "test my results" to add  to the graph.

The 2nd app is similar but adds some dynamics to the app (the car moves and the graph updates slowly) and also has a few more parameters users can change (road slope, engine force).

A  video giving some background and illustrations of usage is available here.

Mixing tank: mixingtankbehaviour.mlapp

Some animation of line plots and colours in the tank illustration to show how the dynamics vary with the parameter choices.

Students can plan systematic studies of the impact of specific parameter changes due to the overlay in the bottom left figure of all results; press new simulation to add a plot with the current selections.

A  video giving some background and illustrations of usage is available here.

Temperature in a house: househeatingbehaviour.mlapp and housetemperaturebehaviour.mlapp

House is treated as a  thermal capacity with heat losses depending on insulation. As users change these two properties and update figure, the house changes to visualise what has happened. Expectations on the corresponding behaviour can then be validated through "test my results".

The 2nd app is similar but adds some animations to help with the visualisation, overlays plots so users can plan investigations of trends and also includes a greater variety of possible parameters. The thickness of the walls links to insulation and the redness to hotness.

A  video giving some background and illustrations of usage is available here.

Mass-spring-damper system: masspringdamper.mlapp

Users can create random parameter values through 'new example' or enter values directly in the brown boxes. Update figure gives a visualisation and "test my results" computes the core 2nd order dynamic values of interest (damping ratio, gain, time constant) so users can compare with their own computations.

Cruise control with PI: cruisecontrolapp.mlapp 

Investigate the speed response of a car with a PI compensator. User can change PI parameters, mass, target speed and road slope. New simulation adds line plot to the graphs so that the user can investigate and observe trends as given parameters are changed.

Animation allows user to see whether the target speed is achieved (black and red bollards move synchronously or not).

Control of tank level with PI compensation: tanklevel_and_pi.mlapp

Investigate the level control of a tank with a PI design,  Use sliders to select PI values and the dimensions of the tank. A disturbance inflow is added at 200 sec to illustrate whether the PI can reject this effectively.

The lower left figure stores previous simulations so the user can observe trends and understand design principles. Animation effects also bring some life to the app.

PI tuning practice: pi_tuning.mlapp 

Simple app to support practice with PI tuning using 4 low order models with relatively benign dynamics.  Also includes a disturbance to allow students to investigate how feedback caters for uncertainty.

Allows overlay with multiple different choices of tuning so users can investigate trends and patterns. Use of buttons and choices largely self-evident.