Programming With MATLAB
Programming With MATLAB
Sean de Wolski
Application Engineer
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 Products Used
MATLAB
MATLAB language
– High-level
– Matrix-based
– No need for low-level
administrative tasks
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 Products Used
MATLAB
Curve Fitting Toolbox
10
Range of Programming Techniques
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
if (x == 23)
x = 12 disp('Hello')
while (x < 100) end
x = x+1 end
if (x == 23)
disp('Hello')
end Assignment
end Looping Test
Increment
Test to Act
Code Take Action
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, states)
– Methods (algorithms, behavior)
Object
– Specific example of a class
Element of the set – object
– Instance Example: Triangle
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
Deploying Applications with MATLAB
Toolboxes
1 MATLAB End-User
Desktop Machine
MATLAB Compiler
3
.exe
20
Deploying Applications with MATLAB
MATLAB Compiler
Share applications
with end users who MATLAB MATLAB MATLAB
Builder EX Builder JA Builder NE
do not need MATLAB
– Stand-alone
executables
– Shared libraries
.dll
– Software components .exe .lib
Excel Java Web .NET
Royalty-free distribution
21
Summary – MATLAB for Programming
High-level language
– Matrix-based
– Math and graphics functions
– Traditional programming
language features
26
Summary
Multiple Ways to Get Help
doc
help <name>
Function Browser,
function hints,
tab completion
29
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
30
MATLAB Central
File Exchange
– Download free files
– Over 19000K available – including functions,
apps, examples, and models
MATLAB Answers
– Ask programming questions
– Search 70000K+ existing answers
Cody
– Challenge and expand your
knowledge of MATLAB
Blogs
– Read commentary from MathWorks engineers who
design, build, and support MATLAB and Simulink
31
© 2013 The MathWorks, Inc.
35