1 / 64

Introduction to Matlab and matrix review

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

ernst
Download Presentation

Introduction to Matlab and matrix review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 12-Oct-2010 APA 6903 Giulia Mantovani Introduction to Matlab and matrix review

  2. 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?

  3. Why Matlab? • Common Uses for Matlab in Research • Data Acquisition • Multi-platform, Multi Format data importing • Analysis Tools (Existing,Custom) • Statistics • Graphing • Modeling

  4. Why Matlab? Data Acquisition • A framework for bringing live, measured data into MATLAB using PC-compatible, plug-in data acquisition hardware

  5. 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 …

  6. 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

  7. Why Matlab? Statistical Analysis • A considerable variety of statistical tests available including: • TTEST • Mann-Whitney Test • Rank Sum Test • ANOVAs • Linear Regressions • Curve Fitting

  8. 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

  9. Why Matlab? Modeling • Models of complex dynamic system interactions can be designed to test experimental data

  10. You can change the desktop arrangement to meet your needs, including resizing, moving, and closing tools. HowdoesMatlab look like?

  11. Desktop Tools

  12. 1 2 Help on-line: a basictool

  13. Before we start… Vectors • Ordered set of numbers: (1,2,3,4) • Example: (x,y,z) coordinates of pt in space.

  14. Vector Addition V+w v w

  15. Scalar Product av v

  16. sum • max, min, mean, sort, … • Pointwise: .^ Operations on vectors

  17. v  w Inner (dot) Product The inner product is a SCALAR!

  18. Matrices Sum: A and B must have the same dimensions

  19. Matrices Product: A and B must have compatible dimensions ? QUESTION TIME!!! Can I multiply A2x3 and B3x2? What about C3x4 and D3x4? Identity Matrix:

  20. Matrices Transpose: A is symmetric If

  21. 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.

  22. Matrices Inverse: A must be square

  23. 2D Translation P’ t P

  24. P’ t ty P y x tx 2D Translation Equation

  25. P’ t ty P t y x tx 2D Translation using Matrices P

  26. Scaling P’ P

  27. Scaling Equation P’ s.y P y x s.x

  28. Stretching Equation P’ Sy.y P y x Sx.x

  29. Rotation P P’

  30. P’ y’ y  P x x’ Rotation Equations Counter-clockwise rotation by an angle 

  31. Properties of rotation matrixes R is a rotation matrix and it must satisfy the following constraints:

  32. y x’ P Affine Transformation y’ x

  33. Understanding the Matlab Environment: • Navigating the Matlab Desktop • Commonly Used Toolboxes

  34. 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

  35. 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.

  36. 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

  37. 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

  38. Using Matlab Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix 

  39. 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 

  40. 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

  41. 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?

  42. Using Matlab • Working with Matrices • Spaces, commas, and semicolons are used to separate elements of a matrix

  43. 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]

  44. 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

  45. 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

  46. 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

  47. 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?

  48. 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]

  49. 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]

  50. 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

More Related