Académique Documents
Professionnel Documents
Culture Documents
Agenda
900 - 1015
Function Quiz!
Memory Considerations
-
Container overhead
1015 - 1045
1045 - 1200
Function Quiz
Primary functions
Subfunctions
Nested functions
Function handles
Anonymous functions
5
>> getXLSData
= @(worksheet)
Solving differential
equationsxlsread('records.xls', worksheet);
>> myData = getXLSData('Sheet1');
Numerical integration
Plotting
MATLAB Digest
Dynamic Function Creation with Anonymous and Nested Functions
http://www.mathworks.com/company/newsletters/digest/2005/sept/dynfuncti
ons.html
Examples
Anonymous functions
http://www.mathworks.com/products/matlab/demos.html?file=/products/dem
os/shipping/matlab/anondemo.html
Nested Functions
http://www.mathworks.com/products/matlab/demos.html?file=/products/dem
os/shipping/matlab/nesteddemo.html
Agenda
900 - 1015
Function Quiz!
Memory Considerations
-
Container overhead
1015 - 1045
1045 - 1200
% Double array
% Cell array
% Struct array
whos
10
Container Overhead
Numeric Array
Cell Array
Structure
Total Used:
76 + 16 = 92
136 + 76 = 212
Total Reported:
16 + 16 = 32
76 + 76 = 152
12
% each 1x3
im2{1,1} = [redPlane(1) greenPlane(1) bluePlane(1)];
im2{2,1} = [redPlane(2) greenPlane(2) bluePlane(2)];
...
im2{m,n} = [redPlane(m*n) greenPlane(m*n) bluePlane(m*n)];
13
im1copy
im1
Change
one pixel
14
im1copy
im1
Change
one pixel
im2
[
[
[
[
]
]
]
]
im2copy == im2;
>>>>
im2copy{1}
[0 0 0];
[
[
[
[
]
]
]
]
[
[
[
[
]
]
]
]
im2copy
15
16
In-place Optimizations
When does MATLAB do calculations in-place?
function inplaceOptimization
x = randn(3e7,1);
y = myfunc(x);
% No.
x = myfuncInPlace(x); % Yes!
x = myfunc(x);
% No.
function y = myfunc(x)
y = sin(2*x.^2+3*x+4);
function x = myfuncInPlace(x)
x = sin(2*x.^2+3*x+4);
17
Recorded Webinar:
Handling Large Data Sets Efficiently in MATLAB
mathworks.com -> Recorded Webinars
18
Agenda
900 - 1015
Function Quiz!
Memory Considerations
-
Container overhead
1015 - 1045
1045 - 1200
19
Agenda
900 - 1015
Function Quiz!
Memory Considerations
-
Container overhead
1015 - 1045
1045 - 1200
20
Processes
Time
Time
21
11 26 41
11 26 41
12 27 42
12 27 42
13 28 43
13 28 43
14 29 44
14 29 44
15 30 45
15 30 45
16 31 46
16 31 46
17 32 47
17 32 47
17 33 48
17 33 48
19 34 49
19 34 49
20 35 50
20 35 50
21 36 51
21 36 51
22 37 52
22 37 52
22
Computer Cluster
MATLAB Distributed Computing Server
CPU
Worker
CPU
Worker
TOOLBOXES
Parallel
Computing
Toolbox
Scheduler
CPU
Worker
BLOCKSETS
CPU
Worker
23
Toolbox Support:
Optimization Toolbox
Statistics Toolbox
SystemTest
Global Optimization Toolbox
Simulink Design Optimization
Bioinformatics Toolbox
Model-Based Calibration Toolbox
Trivial changes
parfor
Distributed Arrays, spmd
GPUArrays
Extensive changes
Worker
Worker
Worker
TOOLBOXES
Worker
Worker
Worker
BLOCKSETS
Worker
Worker
1
2
23 3 4 4 55 6 6
8 8 9 910 10
Worker
myInput = 0.1:0.1:1;
myOutput = zeros(10, 1);
parfor k = 1:10
x = myInput(k);
y = myFunction(x);
myOutput(k) = y;
end
myOutput
x = myInput(k);
y = myFunction(x);
myOutput(k) = y;
Worker
x = myInput(k);
y = myFunction(x);
myOutput(k) = y;
Worker
x = myInput(k);
y = myFunction(x);
myOutput(k) = y;
Worker
x = myInput(k);
y = myFunction(x);
myOutput(k) = y;
}5
m &x& + b{ x& + k{ x = 0
1, 2 ,...
m
b
1, 2 ,...
x ' (0 ) = 1
1.2
1
Displacement (x)
0.8
0.6
0.4
m = 5, b = 2, k = 2
0.2
0
2.5
m = 5, b = 5, k = 5
-0.2
2
-0.4
1.5
10
15
20
25
Time (s)
1
0.5
0
Damping (b)
4
3
2
6
Stiffness (k)
27
28
11 26 41
12 27 42
13 28 43
14 29 44
15 30 45
16 31 46
TOOLBOXES
17 32 47
17 33 48
BLOCKSETS
19 34 49
20 35 50
21 36 51
22 37 52
Distributed Array
Lives on the Cluster
29
Distributed Array
Worker
Worker
Column 1:3 of y
Column 4:6 of y
y = distributed(rand(10));
Worker
Column 7:8 of y
Worker
Column 9:10 of y
Demo:
- Handle large data sets
31
32
Interactive to Scheduled
Interactive
Great for prototyping
Immediate access to MATLAB workers
Scheduled
Offloads work to other MATLAB workers (local or on a cluster)
Access to more computing resources for improved performance
Frees up local MATLAB session
>> batch('myScript')
33
parallelism on multicore
machines
Rapidly develop parallel
power
No separate computer cluster
required
34
Computer cluster
Parallel
Computing
Toolbox
CPU
Worker
CPU
Worker
Scheduler
CPU
Worker
CPU
Worker
35
* Parallel Computing Toolbox requires NVIDIA GPUs with Compute Capability 1.3 or greater, including
NVIDIA Tesla 10-series and 20-series products. See http://www.nvidia.com/object/cuda_gpus.html
for a complete listing
36
Ease of Use
Greater Control
37
38
Agenda
900 - 1015
Function Quiz!
Memory Considerations
-
Container overhead
1015 - 1045
1045 - 1200
39
Governing equation:
x(0) = 0
x' (0) = 1
Numeric:
Symbolic:
x(t)
0.1
0.099
0.2
0.193
0.3
0.283
0.4
0.364
0.5
0.437
x (t ) =
e
t b b 2 4 km
2m
b 2 4km
t b + b 2 4 km
2m
b 2 4km
Benefits
1. Insight into how parameters affect solution
2. Often more efficient than numeric implementation
40
From MATLAB:
Sharing
Differentiation
Integrals (definite, indefinite)
Jacobian
Taylor series
Limits
Solving Equations
Algebraic Equations
Ordinary Differential
Equations
Fourier transform
Laplace transform
Z-transforms
Linear Algebra
Operations
Eigenvalues
Special Functions
2-D
3-D contour, surface, mesh,
movies
Simplification
Expansion of polynomials
Substitution
42
Key Takeaways
1. Integrated numerics and graphics
Notebook interface
43
44
Products
www.mathworks.com
Training
www.mathworks.com/training
45