Introduction to Literate Programming in Matlab 2WN50 – Week programming-in-matlab.pptx?dl=0
2 Assignment: implement Regula Falsi Explore the following problem (i.e. graphs, tables) and implement it in Matlab
3 Matlab: command window
4 Command window
5 Matlab: command window Command window Files in current folder Variables that are currently defined
6 Matlab basics: the command window
7
8
9
10 Matlab basics: arrays
11 Matlab basics: arrays
12 Matlab basics: arrays
13 Matlab basics: arrays
14 Matlab basics: arrays
15 Matlab basics: arrays
16 Matlab basics: arrays++
17 Matlab basics: arrays++
18 Matlab basics: arrays++ Operations on arrays are much faster than for- loops!
19 Matlab basics: arrays++
20 Matlab basics: arrays++
21 Assignment: implement Regula Falsi Explore the following problem (i.e. graphs, tables) and implement it in Matlab Exercise 1: Plot this function with 65 points on the given interval.
22 Matlab basics: arrays++
23 Matlab basics: functions
24 Matlab: command window Command window Files in current folder Variables that are currently defined Editor
25 Matlab: command window Command window Files in current folder Variables that are currently defined Editor ➊ ➋
26 Matlab basics: functions
27 Matlab basics: functions
28 Matlab basics: functions
29 Matlab basics: functions
Function can be Made as external m-file o Document/comment in-between steps o Function can have ‘side-effects’ (e.g. make a plot) o Suitable for functions that do “complex” operations Check arguments Need to use if/for etc Define inline o Short notation o Refer to coefficients in the current scope o Suitable for functions in mathematical sense. Direct mapping of output to input 30 Matlab basics: functions
31 Matlab basics: exercise 2
32 Matlab basics: programming
33 Matlab basics: programming
34 Matlab basics: programming
35 Matlab basics: programming
36 Matlab basics: programming
CELL based editing o Collect commands rather than type them in command window o Adjust order, adjust form E.g. plots you want to change title, labels, add elements iteratively o Execute small pieces of code rather than whole file o Code is publishable to a readable format 37 Matlab basics: programming
38 Matlab basics: literate programming
39 Matlab basics: literate programming
40 Matlab basics: literate programming PUBLISH publishing.html#btj5jsh-1
41 Matlab basics: programming
42 Assignment: implement Regula Falsi Explore the following problem (i.e. graphs, tables) and implement it in Matlab Exercise 3: Implement REGULA FALSI in a cell based script. Write introduction with problem statement in LaTeX.
43 Assignment: implement Regula Falsi (alt.) Explore the following problem (i.e. graphs, tables) and implement it in Matlab BONUS: Why is this formulation better?
44 Sample implementation
Refer to an m-file as function object e.g. Arguments are passed as copies, so changing the value of arguments inside a function does not change it outside of the function. Include m-files in published document with % myfunc.m 45 Addenda
Short Matlab introduction – Language basics – Programming concepts – Literate programming The assignments (2WN52) are to be implemented and handed in as a document published with Matlab. 46 Summary