Level one Matlab sessions in term 1 of 2015/6

Matlab labs Matlab coding style Miscellaneous

Matlab labs, groups C and D

Some instructions to quickly set-up your environment are available at the following link. click here.

Comments about getting the software are available at the following link. click here.

Main handout in the labs

Week: (PDFs of main handout used in a new window) 01 02 03 04 05 06

Any summary OHPs used in the labs

Week: (PDFs of any OHPs used in a new window) 01 02 03 04 05 06

2x2 version of OHPs for the printer

Week: (PDFs of any OHPs used in a new window) 01 02 03 04 05 06

Week-by-week brief detail

  • Week 01: Introduction to Matlab.
    Main handout in week 1 (with answers). Summary OHP in week 1, (2x2 version for printing).

    Customising the set-up with startup.m with the creation of H:\Matlab_Level1. Using Matlab as a calculator in the command window. Practice with forming expressions, the rules of precedence and the use of brackets. The scientific notation of numbers, e.g. -5.2e-6. Some the standard functions, e.g. sqrt, exp, sin, cos, tan and abs. The use of variables and assignment statements. Using the editor to create script files and practice in the cycle of creating a script, running the scripting, editing again, running again etc. Comment statements. A script to solve a quadratic equation.

  • Week 02: for, if, else, break.
    Main handout in week 2. Summary OHP in week 2, (2x2 version for printing).

    Examples of for loops to repeat statements. The syntax involving the colon for the list of values to use. Using the variable in the loop with examples using fprintf to neatly format the output. The for loop syntax. Examples to compute sums and products (the factorial). The if-statement and the if-else construction. The comparison operators, e.g. == etc. The use of the break statement to leave a loop before all values have been considered.

  • Week 03: Control statements and the creation of vectors.
    Main handout in week 3. Summary OHP in week 3, (2x2 version for printing).

    Recap of the syntax of a for--loop and a if--else block and an example of using break in the computation of factorials up to a certain size.

    Creating vectors by listing the entries between [ and ]. Row vectos, column vectors and the transpose. Creating vectors with equally spaced entries use the colon way, e.g. a:h:b, and also using linspace, e.g. linspace(a, b, n). Using the entries of a vector and changing individual entries and the index end for the last entry. Adding vectors and multiplying by a scalar. Examples of entry-wise operations and using the standard functions in a vectorised way.

  • Week 04: Creating two-dimensional plots.
    Main handout in week 4. Summary OHP in week 4, (2x2 version for printing).

    The use of plot in the plot(x, y) form and the use of figure to control the window in which the graphics is shown. The use of axes equal when plotting a circle. Two plots together and using a different line type. Adding labels, controlling the size of the font used, controlling the line width and adding a title. Using clf and the hold on and hold off mechanism to do things separately. Saving the plot as a PDF and also saving in other formats. The `copy figure' mechanism to paste into a Word document and comments about including a PDF in Word. Changing the size of the figure window.

  • Week 05: Introduction to using matrices in Matlab
    Main handout in week 5. Summary OHP in week 5, (2x2 version for printing).

    Constructing matrices by putting the entries between square brackets. Referring to entries and blocks of entries such as a row or a column and changing these entries with assignment statements. An example of swapping rows. Converting to a column vector storage of everything with a statement such as y=y(:). Brief mention of entry-wise operations. Matrix operations such as multiplying by a scalar and adding. The matrix product with examples of multiplying vectors and matrices of compatible sizes. Solving linear equations with the backslash operation, i.e. x=A\b. The functions zeros, ones and eye which create matrices. The functions size, det, inv and rref.

    Some of the examples in the session are taken from your MA1720 problems.

  • Week 06: Introduction to creating functions in Matlab
    Main handout in week 6. Summary OHP in week 6, (2x2 version for printing).

    One line functions.

    function m-files and the use with the following examples. The case of tan(x/4)-1 and discussion of the use of the function. A function to get all n roots of a complex number involving two input arguments and one output argument which is a vector. In this case the entries have type complex. A function get all solutions of a quadratic equation involving 3 input arguments and two output arguments.

    Adding comments which are displayed with the help and doc commands.

    The function file syntax in general.

    A function to implement the bisection method which involves a function as one of the arguments.

    Coding Style

    The following are links to different views on how you should layout your m-files.
  • The "MATLAB Programming Style Guidelines" from 2002 by Richard Johnson. Click here for the PDF.
  • The MATLAB Programming Style Guide Wiki Click here.

    Miscellaneous links

    Blackboard, webmail.
    Department of Mathematical, CEDPS, Brunel home page, Telephone directory, MOTD.
    Google, BBC Weather, Uxbridge Weather.
    BR, LT, Traveline, SE, Walkit,
    BBC travel, M25, Uxbridge,