650 likes | 825 Views
12-Oct-2010 APA 6903 Giulia Mantovani. Introduction to Matlab and matrix review. Mat rix Lab oratory Created in late 1970 ’ s Intended for used in courses in matrix theory, linear algebra and numerical analysis
E N D
12-Oct-2010 APA 6903 Giulia Mantovani Introduction to Matlab and matrix review
Matrix Laboratory • Created in late 1970’s • Intended for used in courses in matrix theory, linear algebra and numerical analysis • Currently has grown into an interactive system and high level programming language for general scientific and technical computation Why Matlab?
Why Matlab? • Common Uses for Matlab in Research • Data Acquisition • Multi-platform, Multi Format data importing • Analysis Tools (Existing,Custom) • Statistics • Graphing • Modeling
Why Matlab? Data Acquisition • A framework for bringing live, measured data into MATLAB using PC-compatible, plug-in data acquisition hardware
Why Matlab? Multi-platform, Multi Format data importing • Data can be loaded into Matlab from almost any format and platform • Binary data files (eg. REX, PLEXON etc.) • Ascii Text (eg. Eyelink I, II) • Analog/Digital Data files PC 100101010 UNIX Subject 1 143 Subject 2 982 Subject 3 87 …
Why Matlab? Analysis Tools • A Considerable library of analysis tools exist for data analysis • Provides a framework for the design, creation, and implementation of any custom analysis tool imaginable
Why Matlab? Statistical Analysis • A considerable variety of statistical tests available including: • TTEST • Mann-Whitney Test • Rank Sum Test • ANOVAs • Linear Regressions • Curve Fitting
Why Matlab? Graphing • A Comprehensive array of plotting options available from 2 to 4 dimensions • Full control of formatting, axes, and other visual representational elements
Why Matlab? Modeling • Models of complex dynamic system interactions can be designed to test experimental data
You can change the desktop arrangement to meet your needs, including resizing, moving, and closing tools. HowdoesMatlab look like?
1 2 Help on-line: a basictool
Before we start… Vectors • Ordered set of numbers: (1,2,3,4) • Example: (x,y,z) coordinates of pt in space.
Vector Addition V+w v w
Scalar Product av v
sum • max, min, mean, sort, … • Pointwise: .^ Operations on vectors
v w Inner (dot) Product The inner product is a SCALAR!
Matrices Sum: A and B must have the same dimensions
Matrices Product: A and B must have compatible dimensions ? QUESTION TIME!!! Can I multiply A2x3 and B3x2? What about C3x4 and D3x4? Identity Matrix:
Matrices Transpose: A is symmetric If
Matrices Determinant: A must be square ( n = m ) The area of the parallelogram is the absolute value of the determinant of the matrix formed by the vectors representing the parallelogram's sides. n = m = 2 r1 r2 r3 n = m = 3 The volume of this Parallelepiped is the absolute value of the determinant of the matrix formed by the rows r1, r2, and r3.
Matrices Inverse: A must be square
2D Translation P’ t P
P’ t ty P y x tx 2D Translation Equation
P’ t ty P t y x tx 2D Translation using Matrices P
Scaling P’ P
Scaling Equation P’ s.y P y x s.x
Stretching Equation P’ Sy.y P y x Sx.x
Rotation P P’
P’ y’ y P x x’ Rotation Equations Counter-clockwise rotation by an angle
Properties of rotation matrixes R is a rotation matrix and it must satisfy the following constraints:
y x’ P Affine Transformation y’ x
Understanding the Matlab Environment: • Navigating the Matlab Desktop • Commonly Used Toolboxes
Using Matlab • Solving equations using variables • Expression language • Expressions typed by the user are interpreted and evaluated by the Matlab system • Variables are names used to store values • Variable names allow stored values to be retrieved for calculations or permanently saved • When MATLAB encounters a new variable name, it automatically creates the variable and allocates the appropriate amount of storage. • Variable = Expression • **Variable Names are Case Sensitive! • Ex. «a» and «A» are two different variables
Using Matlab Solving equations using variables Variable = Expression • Basic Calculation Operators: • + Addition • Subtraction • Multiplication • / Division • ^ Exponentiation >> x + y ans = 8 >> x - y ans = 4 >> x * y ans = 12 >> x / y ans = 3 >> x ^ y ans = 36 >> x = 6 x = 6 >> y = 2 y = 2 Reserved variables! They are special names used to indicate either a specific number (e.g. pi, inf, eps, …), a keyword (e.g. char, double, …), or the result of an expression (ans). By default they have a specific meaning or value, if you assign a new expression to these names, you cannot use the default reserved variable anymore during the current session of Matlab.
Using Matlab • Working with Matrices • Matlab works with rectangular numerical matrixes • A matrix is a collection of numerical values that are organized into a specific configuration of rows and columns. • The number of rows and columns can be any number • Example • 3 rows and 4 columns define a 3 x 4 matrix having 12 elements
Using Matlab • Working with Matrices • Matlab works with rectangular numerical matrixes • A matrix is a collection of numerical values that are organized into a specific configuration of rows and columns. • The number of rows and columns can be any number • Example • 3 rows and 4 columns define a 3 x 4 matrix having 12 elements • A scalar is a single number and is represented by a 1 x 1 matrix in matlab. • A vector is a one dimensional array of numbers and is represented by an n x 1 column vector or a 1 x n row vector of n elements
Using Matlab Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix
Using Matlab Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix x = [ 3.5, 33.22, 24.5 ] x is a row vector or a 1 x 3 matrix
Using Matlab Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix x = [ 3.5, 33.22, 24.5 ] x is a row vector or a 1 x 3 matrix x1 = [ 2 5 3 -1] x1 is column vector or a 4 x 1 matrix
Using Matlab Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix x = [ 3.5, 33.22, 24.5 ] x is a row vector or a 1 x 3 matrix x1 = [ 2 5 3 -1] x1 is column vector or a 4 x 1 matrix A = [ 1 2 4 2 -2 2 0 3 5 5 4 9 ]A is a 4 x 3 matrix ? QUESTION TIME!!! Which type of brackets do we use to create a matrix?
Using Matlab • Working with Matrices • Spaces, commas, and semicolons are used to separate elements of a matrix
Using Matlab • Working with Matrices • Spaces, commas, and semicolons are used to separate elements of a matrix • Spaces or commas separate elements of a row • [1 2 3 4] or [1,2,3,4]
Using Matlab • Working with Matrices • Spaces, commas, and semicolons are used to separate elements of a matrix • Spaces or commas separate elements of a row • [1 2 3 4] or [1,2,3,4] • Semicolons separate columns • A = [1,2,3,4;5,6,7,8;9,8,7,6] = [1 2 3 4 • 5 6 7 8 • 9 8 7 6] • Colon operator identifies a range of values: • B = [1:4 ; 5:8 ; 9,8,7,6 ] = A
Using Matlab • Working with Matrices • Colon operator identifies a range of values: • [ 1 : 3 ] = [ 1 , 2 , 3] • [ 1 : 2: 9 ] = [ 1 , 3 , 5, 7, 9] • [ 5 : -1: 1 ] = [ 5 , 3 , 1] • B = [1:4 ; 5:8 ; 9,8,7,6 ] = A • A = [1,2,3,4;5,6,7,8;9,8,7,6] = [1 2 3 4 • 5 6 7 8 • 9 8 7 6] start jump end
Using Matlab • Indexing Matrices • A m x n matrix is defined by the number of m rows and number of n columns • An individual element of a matrix can be specified with the notation A(4,1)=5
Using Matlab • Indexing Matrices • A m x n matrix is defined by the number of m rows and number of n columns • An individual element of a matrix can be specified with the notation A(4,1)=5 • Example: • >> A = [1 2 4 5;6 3 8 2] A is a 4 x 2 matrix • >> A(1,2) • ans = 6 • The colon operator can be used to index a range of elements • >> A(1:3,2) • ans = 1 2 4 ? QUESTION TIME!!! Which type of brackets do we use to index a matrix?
Using Matlab • Indexing Matrices • Specific elements of any matrix can be overwritten using the matrix index • Example: • A = [1 2 4 5 • 6 3 8 2] • >> A(1,2) = 9 • Ans • A = [1 2 4 5 • 9 3 8 2]
Using Matlab • Matrix Shortcuts • The ones and zeros functions can be used to create any m x n matrices composed entirely of ones or zeros • Example • a = ones(2,3) • a = [1 1 • 1 1 • 1 1] • (!) if you need to understand more about how to use these functions, go to the HELP! b = zeros(1,5) b = [0 0 0 0 0]
Using Matlab • Data Types and Formats • The semicolon operator determines whether the result of an expression is displayed • who lists all of the variables in your matlab workspace • whos list the variables and describes their matrix size