Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Yunkai Liu Assistant Professor Computer Science Department University of South Dakota
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.
History of MATLAB
Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems Developed primarily by Cleve Moler in the 1970s
History of MATLAB
In 1970, Cleve Moler, the chairman of the computer science department at University of New Mexico, designed MATLAB to give his students to access LINPACK and EISPACK without requiring knowledge of Fortran
It soon spread to other universities and found a strong audience within the applied mathematics community. In1984, Jack Little, Cleve Moler and Steve Bangert rewrote MATLAB in C with more functionality (such as plotting routines).
MATLAB
MATLAB is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++, and Fortran.
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 userdefined plot types
Strengths of MATLAB
MATLAB is relatively easy to learn. MATLAB code is optimized to be relatively quick when performing matrix operations. MATLAB may behave like a calculator or as a programming language. MATLAB is interpreted, errors are easier to fix. Although primarily procedural, MATLAB does have some object-oriented elements.
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 and languages, such as C, C++, Fortran, Java, COM, and Microsoft Excel
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 scientific computation and is not suitable for some things (such as parsing text).
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.
Licenses
MATLAB @ home
Standard edition
Student edition
Available for roughly one hundred dollars. Some limitations, such as the allowable size of a matrix or some toolboxes.
MATLAB @USD
Art & Science Building 16 B
MATLAB @ SDSU
Solberg 1st floor
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.
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)
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
>>
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/
Matrix Operators
Indexing Matrices
Indexing
submatrices using vectors of row and column indices >> A([2 3],[1 2])
Ordering
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
Matrix Functions
Elementary functions are often overloaded >> help elmat >> sin(A)
Specialized matrix functions and operators >> As=sqrtm(A) >> As^2 >> A.*A Note: in general, .<operator> is elementwise operation
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 >> xlabel(x); ylabel(y=sin(x));
solid
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)
Graphics
Three-dimensional
>>
change lightning and material properties >> cameramenu >> material metal
Graphics
Bitmap images can also be visualized >> load mandrill >> image(X); colormap(map) >> axis image off
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
For Loops
Case statements
Syntax
switch switch_expr case case_expr statement,...,statement case {case_expr1,case_expr2,case_expr3,...} statement,...,statement ... otherwise statement,...,statement end
End