Programming With MATLAB
Programming With MATLAB
Loren Shure
2
Demo: Assessment of Wind Turbine Locations
Approach:
– Interactively explore data and develop analysis approach
Load and preprocess data from observation towers
Fit wind speed probability distribution
Estimate average power
– Automate to run on data from other locations
3
Calculating Average Turbine Power
𝑣𝑚𝑎𝑥
𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝑃𝑜𝑤𝑒𝑟 = 𝑓 𝑣 ∗ 𝑊 𝑣 𝑑𝑣
𝑣𝑚𝑖𝑛
4
Wind Turbine Power Curve
5
Demo Summary
MATLAB language
– High-level
– Matrix-based
– No need for low-level administrative tasks
6
Range of Programming Techniques
value
variable
structure
function
script
command line
7
Demo: Virus Dynamics Modeling
Goal: Modify the code for a working model of virus dynamics to make
it more maintainable, reusable, and robust
Approach:
– Organize code by using different function types
– Add error checking to validate inputs
– Allow different calling syntaxes to support
different use cases
8
Mathematical Model of Virus Dynamics
𝑑𝑇
𝑑𝑡 = −𝛽 𝑇 𝑉
𝑑𝐼
𝑑𝑡 =𝛽𝑇𝑉 − δ𝐼
𝑑𝑉
𝑑𝑡 =𝑝𝐼 −c𝑉
𝑇 – target (uninfected cells)
I – infected cells
V – free virions (virus particles)
Model parameters:
𝛽 - infection rate of uninfected cells
δ - death rate for infected cells
𝑝 𝛽 𝑇𝑜 If R>1,
𝑅= infection can
𝑝 - production rate of virus particles 𝑐𝛿 be established.
𝑐 - clearance rate of virus particles
9
Demo Summary
value
variable
structure
Manage larger,
complex applications
Organize data and
algorithms
function
script
command line
11
What is a program?
Data
x = 12
while (x < 100)
x = x+1
x = 12
if (x == 23)
while (x < 100)
x = x+1 disp('Hello')
end
if (x == 23)
end
disp('Hello')
end
end
Assignment
Looping Test
Increment
Test to Act
Take Action
Code End
End
Algorithm 12
Range of Programming Techniques
value Data
variable
structure
(properties)
class
(methods)
function
script
command line
Algorithm
13
Object-Oriented Terminology
Class
– Outline of an idea
– Properties (data)
– Methods (algorithms)
– Instance
Defined set – class
Example: Polygons
14
Object-Oriented Programming with MATLAB
15
Packaging and Sharing MATLAB Apps
Packaging Tool:
– Automatically includes all necessary files
– Documents required products
16
Sharing Results from MATLAB
Package as an app
17
Deploying to Other Environments
18
Demo: Lane Marking System
Approach:
– Deploy full application as a stand-alone
executable
– Generate stand-alone C code for underlying video
processing algorithm
19
Sharing Standalone Applications
MATLAB + Toolboxes
MATLAB
Runtime
MATLAB Compiler
20
Deploying Applications with MATLAB
MATLAB
MATLAB MATLAB
Compiler Compiler SDK
MATLAB
Standalone Excel Production
Application Add-in Hadoop C/C++ Java .NET Python
Server
Royalty-free distribution
21
Demo: Lane Marking System
Approach:
– Deploy full application as a stand-alone
executable
– Generate stand-alone C code for underlying video
processing algorithm
22
Why translate MATLAB to C?
23
MATLAB Compiler and MATLAB Coder
.exe Excel .c
MATLAB
Runtime .exe .lib .dll
24
MATLAB Compiler and MATLAB Coder
MATLAB
Runtime .c
25
Summary – MATLAB for Programming
High-level language
– Matrix-based
– Math and graphics functions
– Traditional programming language features
26
Summary
MATLAB Development Environment
Command Window
– Provides immediate results by interactively executing commands
Data visualization
MATLAB Editor
– Debugger
– Code Analyzer
MATLAB Profiler
doc
help <name>
28
Resources
Webinars
– Object-Oriented Programming in MATLAB
– MATLAB for C/C++ Programmers
– MATLAB to C Made Easy
MATLAB Central
– Open exchange for the MATLAB
and Simulink user community
29
© 2016 The MathWorks, Inc.
30