Modelling and control by Anthony Rossiter

# MATLAB BASICS

This is a brief section on how to use MATLAB. It introduces the basic interface, variable types, efficient computation and solution display through m-files, potential uses. The focus is on a beginner who needs to be able to use the software to support simple undergraduate engineering problem solving, rather than on an advanced user. The first resource in Basics 2 gives a rapid introduction to the potential and is less a learning tool than for motivation. After this each resource is focussed on just one aspect at a time.

 It is implicit in several of these chapters that students have core competence in any related mathematical or engineering topics. This chapter contains the topics listed below. Under each topic there are hardcopy (pdf) notes, m-files and a video talk through with key illustrations done real time on MATLAB.

## Matlab Basics 2 - introduction to simple calculations and use

Demonstrates the potential of MATLAB and hopefully enthuses viewers to learn the details given in later resources. Shows how to do simple mathematical computations in MATLAB and that these are far easier than on a conventional hand calculator, especially where expressions are long or complicated. Demonstrates how expressions can be saved or recalled and editted to make error correction and repeated computation efficient. Demonstrates with live MATLAB usage. Some aspects such as symbolic variables and script files are introduced very concisely to demonstrate the power and potential of MATLAB but viewers should use the later resources for a slower and more careful explanation of these aspects.

## Matlab Basics 3 - matrices, vectors and arrays

Introduces the main variable type in MATLAB which is the matrix. Shows how numerical values are stored, accessed (or indexed), editted and created. Demonstrates with live MATLAB usage. To keep the lengths reasonable, comprises two separate videos covering vectors and then matrices; ideally these are viewed in order.

## Matlab Basics 4 - script files

Many engineering algorithms require a number of steps, done in a specific sequence. This resource demonstrates how a sequence commands can be stored in a m-file and then executed with a single button press, thus being very efficient. Also demonstrates with live MATLAB usage how errors can be captured and corrected very efficiently.

## Matlab Basics 5 - variable types

Different types of problems require different types of variable (real number, complex number, integer, transfer function, matrix, string, etc.). This resource introduces a number of different variable types available on MATLAB and briefly demonstrates their use with some real time illustrations. As this resource covers a broad range of variables, the intention is not to give a comprehensive training in the different variable types, but rather to raise user awareness of the possibilities so they know where to look should the need arise.

• A summary of underlying powerpoint file is here pdf file.
• A talk through video is on youtube.
• The m-files mentioned in the video are available here for download: matlab_basics5.

## Matlab Basics 6 - plotting

Display of information is a core communication tool for engineers. This resource introduces the plot command in MATLAB and shows how easily plots can be created, modified, saved and exported for use in other software. Gives a number of live demonstrations and some supporting code for students to access and use as a template.

(i) Simple lines plots are around 2-4 min; (ii) Colours and line types are 4-6min; (iii) Labels, titles and legends 6-9min; (iv) Overlaying numerous plots 9-14min; (v) property editor 14-15min; (vi) subplots 15-17min; (vii) exporting to word processors 17min and (viii) live demonstrations 18-22min.

## Matlab Basics 7 - symbolic variables

Many engineering problems require algebraic manipulation, differentiation, roots solving and so on, all of which are tedious on pen and paper. This resource shows how MATLAB supports basic algebra and also, allows the algebra to be converted to numerical values where required. Differentiation and integration is around 2-5 min, Tangents around 6min, Taylor series around 8min, live demonstrations 11-18 min (with a focus on subs.m around 14.30 and 17.20).

## Matlab Basics extra - interface and window sizing

Demonstrates the basic MATLAB interface and the different windows which open. Discusses different screen layouts and how one can exploit these to ensure the layout is the most efficient one for the given task. This can be skipped by users who feel the content is largely intuitive or obvious

## Matlab Basics 8 - conditionals

A typical engineering algorithm or procedure will involve some decision making process, for example if it is hot, turning the central heating off. This resource shows how MATLAB enables decision making to be embedded efficiently and intuitively in any sequences of commands. Four videos look at four mains concepts: the use of if - else - end statements, the use of while - end statements, the use of switch - case - end statements and the use of logical variables.

• If statements (video, powerpoint, matlab_basics8a.m, matlab_basics8b.m, matlab_basics8c.m, matlab_basics8d.m, matlab_basics8e.m)
• While statements (video, powerpoint, matlab_basics8f.m,matlab_basics8bg.m)
• Switch statements (video, powerpoint, matlab_basics8h.m)
• Logical variables in conditional statements (video, powerpoint, matlab_basics8j.m, matlab_basics8k.m)
• ## Matlab Basics 9 - loops.

There are numerous occasions where the same sequence of commands needs to be executed on several different values (such as when generating a plot or table). MATLAB provides a loop structure for supporting this. This resources demonstates the for loop structure and provides several m-files for students to use as templates to practice with.

## Matlab Basics 10 - function files

A core requirement in the long term is to save validated code for reuse later. In order to ensure this code cannot interfere with other code and computations, the recommended format is a function file which takes given inputs, executes a specifed sequence of commands (algorithm) on these, and produces the required output. This resource introduces the function file syntax and provides several illustrations and exemplars.

## Matlab basics 11 - producing figures for reports

Many students use MATLAB to produce figures for reports, presentations and posters, but do this poorly. This video gives some simple hints on how to ensure the image that appears in your report is easy to read, well produced and with appropriately sized fonts throughout.