MATLAB Basics and Advanced Techniques
MATLAB Basics and Advanced Techniques
ENG1060 Notes
Contents
Part A – Understanding MATLAB • Logical function and operators 16
• If statements 17
• Variables 2
• For loops 18
• Warnings 2
• While loops 18
• In-built functions 2
• Break and continue commands 19
o Who
• Switch 20
o Whos
• Find 20
o Dir
o Colon operator : • Pseudocode 21
o Linspace • Variable scope 21
o Logspace • Function handles 21
o Max and min • Sub-functions 22
o Sum • Nested functions 22
o Input • Data types 23
o Pause • Efficient coding 23
o Display • Good programming practice 23
o Exist • Format command 23
o fzero
Part B – Using MATLAB
o Trig functions
o Mod • Root finding 24
o Rem o Bracketing methods
o Round/ceil/floor o Open methods
o Rand o MATLAB methods
o Unique • Curve fitting 29
o Sign o Coefficient of determination
o Sort o Non-linear regression
o Binary and decimal o In-built MATLAB functions
• Limitations 7 • Integration 32
• Keyboard shortcuts 8 o Trapezoidal rule
• Matrices 8 o Simpson’s 1/3rd rule
• Plotting data 9 o Simpson’s 3/8th rule
• Functions 11 o MATLAB functions
• Strings 12 • ODE’s 36
• fprintf 12 o Euler’s method
• sprint 13 o Heun’s method
• Saving data and documents 13 o Midpoint method
• Importing 13 o MATLAB ODE solvers
• Exporting 14 • Linear systems 38
• Relational operators 15 • Common mistakes 39
1
Author: Spencer Haymes
Part A
Variables
Warnings
• Unsuppressed outputs
• Undefined variables
• Pre-allocating (matrix changing size)
• Polyfit degree too high
In-built functions
2
Author: Spencer Haymes
Colon operator :
• Creates a vector with equally spaced values using a specified spacing step
•
• Limitations
o
• To create column vectors
o
• Using negatives
o
Linspace
• Creates a vector with equally spaced values using a specified number of points
•
• Using negatives
o
Logspace
• Similar to linspace
•
• Default of 50 points if not specified
•