Download presentation
Presentation is loading. Please wait.
Published byAbraham Skinner Modified over 9 years ago
1
Introduction to Literate Programming in Matlab 2WN50 – Week 1 https://www.dropbox.com/s/vvhp3ldlpfterna/ 01-programming-in-matlab.pptx?dl=0
2
2 Assignment: implement Regula Falsi Explore the following problem (i.e. graphs, tables) and implement it in Matlab
3
3 Matlab: command window
4
4 Command window
5
5 Matlab: command window Command window Files in current folder Variables that are currently defined
6
6 Matlab basics: the command window
7
7
8
8
9
9
10
10 Matlab basics: arrays
11
11 Matlab basics: arrays
12
12 Matlab basics: arrays
13
13 Matlab basics: arrays
14
14 Matlab basics: arrays
15
15 Matlab basics: arrays
16
16 Matlab basics: arrays++
17
17 Matlab basics: arrays++
18
18 Matlab basics: arrays++ Operations on arrays are much faster than for- loops!
19
19 Matlab basics: arrays++
20
20 Matlab basics: arrays++
21
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
22 Matlab basics: arrays++
23
23 Matlab basics: functions
24
24 Matlab: command window Command window Files in current folder Variables that are currently defined Editor
25
25 Matlab: command window Command window Files in current folder Variables that are currently defined Editor ➊ ➋
26
26 Matlab basics: functions
27
27 Matlab basics: functions
28
28 Matlab basics: functions
29
29 Matlab basics: functions
30
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
31 Matlab basics: exercise 2
32
32 Matlab basics: programming
33
33 Matlab basics: programming
34
34 Matlab basics: programming
35
35 Matlab basics: programming
36
36 Matlab basics: programming
37
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
38 Matlab basics: literate programming
39
39 Matlab basics: literate programming
40
40 Matlab basics: literate programming PUBLISH http://nl.mathworks.com/help/matlab/matlab_prog/marking-up-matlab-comments-for- publishing.html#btj5jsh-1
41
41 Matlab basics: programming
42
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
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
44 Sample implementation
45
Refer to an m-file as function object with @, e.g. fplot(@myfunc,[3,4]) 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
46
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.