curso de introduccion al matlab2
TRANSCRIPT
-
7/28/2019 Curso de Introduccion Al Matlab2
1/36
Introduction to MATLAB
Yunkai Liu
Assistant Professor
Computer Science Department
University of South Dakota
-
7/28/2019 Curso de Introduccion Al Matlab2
2/36
What is MATLAB?
MATLAB (MATrix LABoratory)
MATLAB is developed by The MathWorks, Inc. MATLAB is a high-level technical computing
language and interactive environment for
algorithm development, data visualization, data
analysis, and numeric computation.
MATLAB can be install on Unix, Windows and
Mac.
-
7/28/2019 Curso de Introduccion Al Matlab2
3/36
History of MATLAB
Ancestral software to MATLAB
Fortran subroutines for solving linear (LINPACK)and eigenvalue (EISPACK) problems
Developed primarily by Cleve Moler in the 1970s
-
7/28/2019 Curso de Introduccion Al Matlab2
4/36
History of MATLAB
In 1970, Cleve Moler, the chairman of the
computer science department at University ofNew Mexico, designed MATLAB to give his
students to access LINPACK and EISPACK
without requiring knowledge of Fortran
-
7/28/2019 Curso de Introduccion Al Matlab2
5/36
History of MATLAB, cont: 2
It soon spread to other universities and found
a strong audience within the appliedmathematics community.
In1984, Jack Little, Cleve Moler and Steve
Bangert rewrote MATLAB in C with more
functionality (such as plotting routines).
-
7/28/2019 Curso de Introduccion Al Matlab2
6/36
MathWorks Product Overview
-
7/28/2019 Curso de Introduccion Al Matlab2
7/36
Distributed Computing @ matlab
-
7/28/2019 Curso de Introduccion Al Matlab2
8/36
MATLAB
MATLAB is a high-level language and
interactive environment that enablesyou to perform computationally intensive
tasks faster than with traditional
programming languages such as C, C++,
and Fortran.
-
7/28/2019 Curso de Introduccion Al Matlab2
9/36
Simulink- Simulation and Model-Based Design
Simulink is a platform for multidomain
simulation and Model-Based Design fordynamic systems. It provides an
interactive graphical environment and a
customizable set of block libraries, andcan be extended for specialized
applications.
-
7/28/2019 Curso de Introduccion Al Matlab2
10/36
Statistics Toolbox 5.1
Apply statistical algorithms and probability models
Key Features Calculation and fitting of probability distributions
Linear and nonlinear modeling
Multivariate statistics
Descriptive statistics
Analysis of variance (ANOVA)
Hypothesis testing
Industrial statistics (Statistical Process Control, Design ofExperiments)
Statistical plotting and data visualization
-
7/28/2019 Curso de Introduccion Al Matlab2
11/36
Bioinformatics Toolbox 2.2
Read, analyze, and visualize genomic, proteomic, andmicroarray data
Key Features
Genomic, proteomic, and gene expression file formats
Internet database access
Functions for pairwise and multiple sequence alignment
Sequence analysis tools
Phylogenetic tree analysis tools Capabilities for microarray data analysis and visualization
Support for mass spectrometry preprocessing and analysis
Statistical learning functionality
-
7/28/2019 Curso de Introduccion Al Matlab2
12/36
SimBiology 1
Model, design, and simulate biochemical pathways
Key Features Access to all functions via the command line and a graphical
user interface
Stochastic, stiff deterministic, and nonstiff deterministic solvers
Model components, including species, parameters, kinetic laws,
reactions, algebraic rules, and units Project files that store models with simulation settings and user-
defined plot types
-
7/28/2019 Curso de Introduccion Al Matlab2
13/36
Strengths of MATLAB
MATLAB is relatively easy to learn.
MATLAB code is optimized to be relativelyquick when performing matrix operations.
MATLAB may behave like a calculator or asa programming language.
MATLAB is interpreted, errors are easier tofix.
Although primarily procedural, MATLAB doeshave some object-oriented elements.
-
7/28/2019 Curso de Introduccion Al Matlab2
14/36
Other Features
2-D and 3-D graphics functions for
visualizing data Tools for building custom graphical user
interfaces
Functions for integrating MATLAB based
algorithms with external applications andlanguages, such as C, C++, Fortran, Java,
COM, and Microsoft Excel
-
7/28/2019 Curso de Introduccion Al Matlab2
15/36
Weaknesses of MATLAB
MATLAB is NOT a general purpose
programming language. MATLAB is an interpreted language (making
it for the most part slower than a compiled
language such as C++).
MATLAB is designed for scientificcomputation and is not suitable for some
things (such as parsing text).
-
7/28/2019 Curso de Introduccion Al Matlab2
16/36
The Latest Update
The latest version of MATLAB is 7.1.
Release 14 with Service Pack 3 (R14SP3),launched on September 1, 2005, provides
updates to MATLAB, Simulink, and 75 other
products.
-
7/28/2019 Curso de Introduccion Al Matlab2
17/36
Licenses
MATLAB @ home Standard edition
Available for roughly two thousand dollars Student edition
Available for roughly one hundred dollars.
Some limitations, such as the allowable size of a matrix orsome toolboxes.
MATLAB @USD
Art & Science Building 16 B
MATLAB @ SDSU
Solberg 1st floor
-
7/28/2019 Curso de Introduccion Al Matlab2
18/36
References
http://www.mathworks.com/products/matlab/i
ndex.html http://www.ccs.neu.edu/home/wmason/
Mastering MATLAB 7. Duane C. Hanselman,
Bruce L. Littlefield. Prentice Hall, 2004.
MATLAB: An Introduction with Applications.
Amos Gilat. Wiley, 2003.
http://www.mathworks.com/products/matlab/index.htmlhttp://www.mathworks.com/products/matlab/index.htmlhttp://www.ccs.neu.edu/home/wmason/http://www.amazon.com/exec/obidos/search-handle-url/index=books&field-author-exact=Duane%20C.%20Hanselman&rank=-relevance%2C%2Bavailability%2C-daterank/102-9677697-2559334http://www.amazon.com/exec/obidos/search-handle-url/index=books&field-author-exact=Bruce%20L.%20Littlefield&rank=-relevance%2C%2Bavailability%2C-daterank/102-9677697-2559334http://www.amazon.com/exec/obidos/search-handle-url/index=books&field-author-exact=Amos%20%20Gilat&rank=-relevance%2C%2Bavailability%2C-daterank/102-9677697-2559334http://www.amazon.com/exec/obidos/search-handle-url/index=books&field-author-exact=Amos%20%20Gilat&rank=-relevance%2C%2Bavailability%2C-daterank/102-9677697-2559334http://www.amazon.com/exec/obidos/search-handle-url/index=books&field-author-exact=Bruce%20L.%20Littlefield&rank=-relevance%2C%2Bavailability%2C-daterank/102-9677697-2559334http://www.amazon.com/exec/obidos/search-handle-url/index=books&field-author-exact=Duane%20C.%20Hanselman&rank=-relevance%2C%2Bavailability%2C-daterank/102-9677697-2559334http://www.ccs.neu.edu/home/wmason/http://www.mathworks.com/products/matlab/index.htmlhttp://www.mathworks.com/products/matlab/index.html -
7/28/2019 Curso de Introduccion Al Matlab2
19/36
Components of MATLAB Interface
Workspace
Current Directory Command History
Command Window
-
7/28/2019 Curso de Introduccion Al Matlab2
20/36
Interactive Calculations
Matlab is interactive, no need to declare variables
>> 2+3*4/2 >> a=5e-2; b=1; a+b
Most elementary functions and constants are already
defined >> cos(pi)
>> abs(1+i)
>> sin(pi)
-
7/28/2019 Curso de Introduccion Al Matlab2
21/36
Variable and Memory Management
Matlab uses double precision
>> format long (15 fixed point format)>> format compact (5 fixed point format)
All variables are shown with
>> who lists the variables currently in the workspace.>> whos whos is similar to who, but also gives size and storage information
Variables can be stored on file>> save filename>> clear>> load filename
-
7/28/2019 Curso de Introduccion Al Matlab2
22/36
The Help System
Search for appropriate function
>> lookfor keyword
Rapid help with syntax and function definition
>> help function
An advanced hyperlinked help system is launched by>> helpdesk
Complete manuals
http://www.mathworks.com/access/helpdesk/help/techdoc/
http://www.mathworks.com/access/helpdesk/help/techdoc/http://www.mathworks.com/access/helpdesk/help/techdoc/ -
7/28/2019 Curso de Introduccion Al Matlab2
23/36
Vectors and Matrices
Vectors (arrays) are defined as
>> v = [1, 2, 4, 5]
>> w = [1; 2; 4; 5]
Matrices (2D arrays) defined similarly >> A = [1,2,3;4,-5,6;5,-6,7]
-
7/28/2019 Curso de Introduccion Al Matlab2
24/36
Matrix Operators
All common operators are overloaded >> v + 2
Common operators are available >> B = A >> A*B >> A+B
Note: Matlab is case-sensitive
A and a are two different variables
-
7/28/2019 Curso de Introduccion Al Matlab2
25/36
Indexing Matrices
Indexing using parentheses
>> A(2,3)
Index submatrices using vectorsof row and column indices
>> A([2 3],[1 2])
Ordering of indices is important!>> B=[A(3,2),A(3,1);A(2,2), A(2,1)]
>> B=A([3 2],[2 1])
-
7/28/2019 Curso de Introduccion Al Matlab2
26/36
Indexing Matrices
Index complete row or column using
the colon operator
>> A(1,:)
Can also add limit index range
>> A(1:2,:)
>> A([1 2],:)
General notation for colon operator
>> v=1:5
>> w=1:2:5
-
7/28/2019 Curso de Introduccion Al Matlab2
27/36
Matrix Functions
Many elementary matrices predefined >> help elmat; >> I=eye(3)
Elementary functions are often overloaded >> help elmat >> sin(A)
Specialized matrix functions and operators >> As=sqrtm(A) >> As^2 >> A.*A Note: in general, . is elementwise operation
-
7/28/2019 Curso de Introduccion Al Matlab2
28/36
Numerical Linear Algebra
Basic numerical linear algebra >> z=[1;2;3]; x=inv(A)*z
>> x=A\zMany standard functions predefined >> det(A) -- determinant >> rank(A) matrix rank >> eig(A)--Eigenvalues and eigenvectorsThe number of input/output arguments can often be varied >> [V,D]=eig(A)
[V,D] = EIG(X) produces a diagonal matrix D of eigenvalues and a
full matrix V whose columns are the corresponding eigenvectors
so that X*V = V*D.
-
7/28/2019 Curso de Introduccion Al Matlab2
29/36
Graphics
Visualization of vector data is available
>> x=-pi:0.1:pi; y=sin(x);
>> plot(x,y) >> plot(x,y,s-) s means squre and means solid
>> xlabel(x); ylabel(y=sin(x));
Can change plot properties in Figure menu, or via handle
>> h=plot(x,y); set(h, LineWidth, 4);
Many other plot functions available
>> v=1:4; pie(v)
-
7/28/2019 Curso de Introduccion Al Matlab2
30/36
Graphics
Three-dimensional graphics>> A = zeros(32);>> A(14:16,14:16) = ones(3);>> F=abs(fft2(A));FFT2 Two-dimensional discrete Fourier Transform. FFT2(X) returns the two-dimensional Fouriertransform of matrix X.If X is a vector, the result will have the same orientation.
>> mesh(F) MESH 3-D mesh surface.>> rotate3d on
Several other plot functions available>> surfl(F)
Can change lightning and material properties>> cameramenu>> material metal
-
7/28/2019 Curso de Introduccion Al Matlab2
31/36
Graphics
Bitmap images can also be visualized
>> load mandrill
>> image(X); colormap(map)
>> axis image off
-
7/28/2019 Curso de Introduccion Al Matlab2
32/36
MATLAB Scripts
Scripts are MATLAB commands stored in
text files. When you type the name of the
script file at the MATLAB prompt the
commands in the script file are executed as if
you had typed them in from the keyboard.
Scripts end with the extension .m Referred to as M-Files
-
7/28/2019 Curso de Introduccion Al Matlab2
33/36
For Loops
Common to other programming languages
forvariable = expression
statement
...
statement
end
-
7/28/2019 Curso de Introduccion Al Matlab2
34/36
-
7/28/2019 Curso de Introduccion Al Matlab2
35/36
Case statements
Syntax
switch switch_expr
case case_expr
statement,...,statement
case
{case_expr1,case_expr2,case_expr3,...}statement,...,statement ...
otherwise
statement,...,statement end
-
7/28/2019 Curso de Introduccion Al Matlab2
36/36
E d
Another satisfied MATLAB user!