Matlab - San Diego State University
Download
Report
Transcript Matlab - San Diego State University
Matlab
http://www.mathworks.com/academia/student_version/doc_r
14.html
Cost: $100
Available in labs on Windows and Unix machines.
What is Matlab?
• high-performance language for technical
computing. It integrates computation,
visualization, and programming in an
easy-to-use environment where problems
and solutions are expressed in familiar
mathematical notation.
Uses
•
•
•
•
•
•
•
Math and computation
Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical
user interface building
Basic Idea
• Particularly useful for problems that can be
cast into matrix, vector form
• MATLAB=Matrix Laboratory
• Starting matlab
– Windows: double click on icon
– Unix: type matlab at the prompt
Basics: Matlab
•
•
•
•
Use as a calculator
No compiling
Interactive or through an .m script
Direct access to the variables in memory:
who?
• Syntax
• Set work directory for m scripts.
Enter Matrices
•
•
•
•
Enter an explicit list of elements.
Load matrices from external data files.
Generate matrices using built-in functions.
Create matrices with your own functions in
M-files.
Durer’s matrix example
• Page 4-3
• How to enter matrix
• Matlab has built in function to manipulate
matrix
– Sum
– Diag
– Tranpose with prime
• Subsripts use
– Acces individual matrix elements
Expressions
•
•
•
•
“Variables” on page 4-10
“Numbers” on page 4-11
“Operators” on page 4-11
“Functions” on page 4-12
Variables and numbers
• Examples of number
Integer, real: 3
-99
0.0001
Scientific: 9.6397238 1.60210e-20
6.02252e23
Imaginary: 1i
-3.14159j
3e5i
• Like any other language matlab can
assign variables and change them
– N=32; M=N etc…..
Operators
•
•
•
•
•
+ Addition
- Subtraction
* Multiplication
/ Division
\ Left division (described in “Matrices and
LinearAlgebra” in the MATLAB documentation)
• ^ Power
• ' Complex conjugate transpose
• ( ) Specify evaluation order
Functions
• Many functions avaliable
– Sin,cos, tan
– Exp
– Bessel
– Help elfun
– Help specfun
– Help elmat
Working with Matrices
•
•
•
•
•
“Generating Matrices” on page 4-14
“The load Function” on page 4-15
“M-Files” on page 4-15
“Concatenation” on page 4-16
“Deleting Rows and Columns” on page 417
Linear Algebra
•
•
•
•
•
A=A+A’
Determinant: det(A)
Inverse: inv(A)
Eigenvalue eig(A)
Matrix-vector produce
– V=ones(4,1)
– A*v
Arrays
•
•
•
•
•
•
•
+ Addition
- Subtraction
.* Element-by-element multiplication
./ Element-by-element division
.\ Element-by-element left division
.^ Element-by-element power
.' Unconjugated array transpose
Graphics
• very important for visualization of results:
not available in any other tool.
• help graphics
• plot opens in figure
• edit with gui (5-15 and further)
• subplot
• plot to file
Basic plotting functions
•
•
•
•
•
•
•
•
•
•
•
“Creating a Plot” on page 5-38
“Multiple Data Sets in One Graph” on page 5-40
“Specifying Line Styles and Colors” on page 5-41
“Plotting Lines and Markers” on page 5-41
“Imaginary and Complex Data” on page 5-43
“Adding Plots to an Existing Graph” on page 5-44
“Figure Windows” on page 5-46
“Multiple Plots in One Figure” on page 5-46
“Controlling the Axes” on page 5-48
“Axis Labels and Titles” on page 5-49
“Saving Figures” on page 5-51
Mesh and surface plots
• Will be used in this class
• Meshes are required for numerical
computations.
• meshgrid: transforms the domain specified
by a single vector or two vectors x and y
into matrices X and Y for use in evaluating
functions of two variables.
Progamming
•
•
•
•
•
•
“if” on page 6-2
“switch and case” on page 6-4
“for” on page 6-5
“while” on page 6-6
“continue” on page 6-6
“break” on page 6-7
Animations
• matlabinto_anim.m