MATLAB Workshop for Engineering Applications
-
Upload
ashish-chandiok -
Category
Documents
-
view
226 -
download
1
Transcript of MATLAB Workshop for Engineering Applications
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 1/34
MATLAB Workshop for
Engineering Applications
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 2/34
Table of Contents ± Day One
� Overview
� Basic Interfaces
� Arrays, Matrices, Operators
� Programming
� Data I/O connection
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 3/34
Table of Contents ± Day Two
� Basic Data Analysis
� Numerical Analysis
� Graphics, Data Visualization, Movies� Inter-language Programming
� Control System and matlab
application
� Image Processing
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 4/34
Overview
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 5/34
Matlab
� MATLAB-³MATrix LABoratory´
� Powerful, extensible, highly integrated
computation, programming, visualization,and simulation package
� Widely used in engineering, mathematics,
and science
� Why?
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 6/34
MATLAB¶s Offers
� Interactive code development proceeds
incrementally; excellent development and rapid
prototyping environment
� Basic data element is the auto-indexed array
� This allows quick solutions to problems that can be formulated in vector or matrix form
� Powerful GUI tools
� Large collection of toolboxes: collections of
topic-related MATLAB functions that extend the
core functionality significantly
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 7/34
MATLAB Toolboxes
Math and AnalysisOptimization
Requirements ManagementInterface
Statistics
Neural Network
Symbolic/Extended Math
Partial DifferentialEquations
PLS Toolbox
Mapping
Spline
Data Acquisition and ImportData Acquisition
Instrument Control
Excel Link
Portable Graph Object
Signal & Image Processing
Signal Processing
Image Processing
Communications
Frequency Domain System
IdentificationHigher-Order Spectral Analysis
System Identification
Wavelet
Filter Design
Control Design
Control System Fuzzy Logic
Robust Control
-Analysis and Synthesis
Model Predictive Control
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 8/34
Matlab Web Link!
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 9/34
Matlab Programming
system� Language: arrays and matrices, controlflow, I/O, data structures, user-defined functions and scripts
� Working Environment: editing, variable
management, importing and exporting data,debugging, profiling
� Graphics system: 2D and 3D datavisualization, animation and custom GUIdevelopment
� Mathematical Functions: basic (sum , sin,«)
to advanced (fft, inv, Bessel functions,«)
� API: can use MATLAB with C, Fortran, and Java, in either direction
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 10/34
Matlab tutorial and
help web sites� www.mathworks.com/
� www.mathtools.net/MATLAB
� www.math.utah.edu/lab/ms/matlab/matlab.html
� web.mit.edu/afs/athena.mit.edu/software/matlab/
� www.utexas.edu/its/rc/tutorials/matlab/
� www.math.ufl.edu/help/matlab-tutorial/
� www.indiana.edu/~statmath/math/matlab/links.html
� www-h.eng.cam.ac.uk/help/tpl/programs/matlab.html
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 11/34
Basic Interfaces
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 12/34
Main MATLAB
Interface
Command window
Workspace &Current directory
CommandHistory
Menu bar
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 13/34
MATLAB Development
Windows� Command Window: where you enter commands
� Command History: r unning history of commands which is preserved
across MATLAB sessions
� Current directory: Default is $matlabroot/work
� Workspace: GUI for viewing, loading and saving MATLAB variables� Array Editor : GUI for viewing and/or modifying contents of MATLAB
variables (openvar varname or double-click the array¶s name in the
Wor kspace)
� Editor/Debugger : text editor, debugger; editor wor ks with file types in
addition to .m (MATLAB ³m-files´)
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 14/34
MATLAB Editor
Window
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 15/34
MATLAB Help
Window
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 16/34
Command-Line Help
>> help
HELP topics:
My Documents\MATLAB - (No table of contents file)
matlab\general - General purpose commands.
matlab\ops - Operators and special characters.
matlab\lang - Programming language constructs.
matlab\elmat - Elementary matrices and matrix manipulation.
matlab\elfun - Elementary math functions.
matlab\specfun - Specialized math functions.
matlab\matfun - Matrix functions - numerical linear algebra.
matlab\datafun - Data analysis and Fourier transforms.
matlab\polyfun - Interpolation and polynomials.
matlab\funfun - Function functions and ODE solvers.
matlab\sparfun - Sparse matrices.
matlab\timefun - Time and dates.
matlab\datatypes - Data types and structures.
matlab\verctrl - Version control.
matlab\codetools - Commands for creating and debugging code.
matlab\helptools - Help commands.
matlab\winfun - Windows Operating System Interface Files (COM/DDE)
matlab\demos - Examples and demonstrations.
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 17/34
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 18/34
Command-Line Help
>> help figure
FIGURE Create figure window.
FIGURE, by itself, creates a new figure window, and returns
its handle.
FIGURE(H) makes H the current figure, forces it to become visible,
and raises it above all other figures on the screen. If Figure H
does not exist, and H is an integer, a new figure is created with
handle H.
GCF returns the handle to the current figure.
Execute GET(H) to see a list of figure properties and
their current values. Execute SET(H) to see a list of figure
properties and their possible values.
See also subplot, axes, gcf, clf.
Reference page in Help browser
doc figure
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 19/34
V ariables (Arrays) and
Operators
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 20/34
Variable defination
mixed data types
semi-colon suppresses output of the calculation¶s result
>> 16 + 24
ans =
40
>> product = 16 * 23.24
product =
371.84
>> product = 16 *555.24;>> product
product =
8883.8
No declaration needed
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 21/34
>> clear
>> product = 2 * 3^3;>> comp_sum = (1 + 4i) + (1 - 4i);
>> show_i = i^2;
>> save three_things
>> clear
>> load three_things
>> who
Your variables are:
comp_sum product show_i
>> product
product =
54>> show_i
show_i =
-1
Remove all variables
Save wor kspace variables
Load variables
Show variables
Answer for variables
Define variables
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 22/34
Matlab data type
� The basic data type used in MATLAB is the double precision array
� No declarations needed: MATLAB automatically allocates requiredmemory
� Resize arrays dynamically
� To reuse a variable name, simply use it in the left hand side
� of an assignment statement
� MATLAB displays results in scientific notation ± Use File/Preferences and/or format function to change default� short (5 digits), long (16 digits)
� format short g; format compact (my preference)
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 23/34
Variable names are case sensitive and over-written when re-used
Basic variable class:Auto-Indexed Array
Allows use of entire arrays (scalar, 1-D, 2-D, etc«) as
operands
Vectorization:Always use array operands to get bestperformance (see next slide)
Terminology: ³scalar´ (1 x 1 array), ³vector´ (1 x N array), ³matrix´
(M x N array)
Special variables/functions: ans, pi, eps, inf, NaN, i, nargin,nargout, varargin, varargout, ...
Commands who (terse output) and whos (verbose output) show
variables in Workspace
Matlab data type
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 24/34
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 25/34
t =1:10
t =1 2 3 4 5 6 7 8 9 10
k =2:-0.5:-1
k =2 1.5 1 0.5 0 -0.5 -1
B = [1:4; 5:8]
x =1 2 3 4
5 6 7 8
Long Array, Matrix
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 26/34
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 27/34
Creating Matrices using built in
function
zeros(m, n): matrix with all zeros
ones(m, n): matrix with all ones.
eye(m, n): the identity matrix
rand(m, n): uniformly distributed randomrandn(m, n): normally distributed randommagic(m): square matrix whose elements
have the same sum, along the row,
column and diagonal.
pascal(m) : Pascal matrix.
x = zeros(1,3)
x =
0 0 0
x = ones(1,3)
x =
1 1 1
x = rand(1,3)
x =
0.9501 0.2311 0.6068
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 28/34
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 29/34
Matrix Index
A=[1,2,5;4,6,3;3,6,9]
A =
1 2 54 6 3
3 6 9
A(7)ans =
5
A(3,2)
ans =
6A(2,:)
ans =
4 6 3
A(1:3,3)
ans =5
3
9
A(1,1:3)
ans =1 2 5
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 30/34
Matrix Concatenation
x=[1 4 3]
x =
1 4 3
y=[2 6 3]
y =
2 6 3
z=[0 0 0]
z =
0 0 0
[x y z]
ans =
1 4 3 2 6 3 0 0 0
[x;y;z]
ans =
1 4 3
2 6 30 0 0
Coloumn concatenation
Row concatenation
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 31/34
Matrix Operations
+ addition
- subtraction
* multiplication
/ division
^ powerµ conjugate transpose
A=[1 2 3;8 7 4;2 4 5]
A =
1 2 38 7 4
2 4 5
B=[1 9 6;3 5 2;4 5 9]
B =
1 9 63 5 2
4 5 9
X=A+B
X =2 11 9
11 12 6
6 9 14
Y=A-B
Y =0 -7 -3
5 2 2
-2 -1 -4
Z=A*B
Z =19 34 37
45 127 98
34 63 65
A/Bans =0.1084 -0.072 0.277-0.765 2.343 0.4330.1867 0.042 0.421
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 32/34
Operators
(Element by Element).* element-by-element multiplication
./ element-by-element division
.^ element-by-element power
A = [1 2 3; 5 1 4; 3 2 1]
A =
1 2 3
5 1 4
3 2 -1
x = A(1,:)
x=
1 2 3
y = A(3 ,:)
y=
3 4 -1
b = x .* y
b=
3 8 -3
c = x . / y
c=
0.33 0.5 -3
d = x .^2
d=
1 4 9
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 33/34
>> hi = ' hello';
>> class = 'MATLAB';
>> hi
hi =hello
>>
classclass =
MATLAB
>> greetings = [hi class]
greetings =
helloMATLAB
>>
vgreetings = [hi;class]vgreetings =
helloMATLAB
Character Strings
8/7/2019 MATLAB Workshop for Engineering Applications
http://slidepdf.com/reader/full/matlab-workshop-for-engineering-applications 34/34
Matrix sum
sumcol=sum(A)
sumcol =
11 13 12
A=[1 2 3;8 7 4;2 4 5]
A =
1 2 3
8 7 42 4 5
sumrow= sum(A')'
sumrow =6
19
11
sumdiag= sum(diag(A))
sumdiag =
13
sumotherdiag= sum(diag(fliplr(A)))
sumotherdiag =
12