1 / 87

Introduction to MATLAB and MATLAB Programming

Introduction to MATLAB and MATLAB Programming. #1. Outline. Who are we and why are we here? (to paraphrase James Stockdale, 1992) Who am I and how did I get here? Who are you and why are you here? MATLAB. Started programming (BASIC) in 1981

tallis
Télécharger la présentation

Introduction to MATLAB and MATLAB Programming

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. Introduction to MATLAB and MATLAB Programming #1

  2. Outline • Who are we and why are we here? (to paraphrase James Stockdale, 1992) • Who am I and how did I get here? • Who are you and why are you here? • MATLAB

  3. Started programming (BASIC) in 1981 • Started imaging algorithm and software development (Pascal) in 1983 • Cambridge Instruments Quantimet 900 • 1 MB memory • Booted from 8” floppy disk • $100,000

  4. BCC ASET (1983), AA (1986) • BASIC, Pascal, FORTRAN, x86 Assembler • TSU BSEE (1986) • NCSU MSEE (1988) • MATLAB • C/C++ • APL, ProLog • NCSU PhD (1996)

  5. 3D ICUS • 3D Intracoronary Ultrasound • Lumen and medial-adventitial boundary estimation

  6. 3D Imaging Geometry

  7. TIPS

  8. Surgical Planning

  9. MRA Vessel Extraction

  10. Objectives • Develop a basic working knowledge of MATLAB (notation, syntax, built-in functions) • Learn to use the command line (MATLAB as a calculator) • Learn to develop scripts and functions • Learn basic programming skills • Learn to use the debugger to troubleshoot scripts and functions

  11. Objectives • Generate 2D and 3D data plots • Read, write, and manipulate numeric data (e.g. text files, binary files, Excel) • Read, write, manipulate, and display image data • Learn the basics of linear algebra • Learn about the FFT and complex variables

  12. What is MATLAB? • MATLAB - Matrix Laboratory • What is a matrix? • Fundamental data type in MATLAB • An image • What is an image? • A rectangular array of numbers • A point in a high-dimensional space • A representation of a system of equations

  13. What is MATLAB? • What is a matrix? • A linear mapping from Rnto Rm (or Cnto Cm)** • What’s a linear mapping? • Lines map to lines. Origin maps to the origin. • A collection of vectors • What is a vector? • Magnitude and direction (velocity, force, etc.) • An n-tuple of numbers

  14. What is MATLAB? • History • Netlib(netlib.org) • Large software library written in FORTRAN (FORmulaTRANslator) • Cleve Moler (EISPACK, LINPACK, cofounder of MathWorks) • Computing environment for technical computation, visualization, design, simulation, and implementation in a wide range of application areas.

  15. Common MATLAB Applications • Numerical Methods • Linear algebraic equations • Roots and optimization • Curve fitting • Integration and differentiation • Differential equations • MATLAB toolboxes • Statistics, optimization, image processing, computer vision, bioinformatics, …

  16. Why MATLAB? • Pros: • Easy to start using MATLAB with little or no prior programming experience • Relatively easy to learn • Can be used as a calculator or as a programming language • Can be used to test simple algorithms (command line or scripts) prior to coding in a higher-level language

  17. Why MATLAB? • Pros: • MATLAB has a large library of optimized, robust mathematical functions • MATLAB has a large collection of very powerful toolboxes (e.g. image processing, statistics) • Easy to produce 2D and 3D graphs

  18. Why Not MATLAB? • Cons: • Cost associated with ease of use • Interpreted language • Slow (10-100x) compared to some other programming languages (e.g. C, C++, FORTRAN, Pascal) • May be too slow to solve large problems • Fairly expensive (free alternatives available) • Designed for scientific computing • Not always the best solution for other applications

  19. 2-by-2 System of Equations • Can solve graphically • Can add/subtract equations

  20. 2-by-2 System of Equations • Can solve with the cross or outer product • cross ()

  21. n-by-n System of Equations • What about higher dimensions? • Cross product only works in 3D. • Harder (impossible?) to visualize. • Circuit analysis example • Graph theory (non-planar) and linear algebra • 6-by-6 system of equations

  22. Matrix Operations • The entry (or element) in row i and row j of a matrix, A, is denoted by aij • The entry in row i of a vector (i.e. matrix with only one column) vis denoted by vi.

  23. Matrix Operations • Two matrices are equal if: • They are the same size • All corresponding entries are equal • Two matrices can be added together if they have the same size (i.e. the same number of rows and columns)

  24. Matrix Operations • Multiplication by a scalar • Matrix-vector multiplication • If A is m-by-n and x is n-by-1, b is m-by-1.

  25. Matrix Operations • Matrix-vector multiplication

  26. Matrix Operations • Matrix-matrix multiplication • If A is m-by-r and B is r-by-n, C is m-by-n.

  27. Matrix Operations • Matrix-matrix multiplication • To find cij (i.e. the element of C in row i and column j) multiply corresponding entries in row i of A and column j of B, and add them together.

  28. Matrix Operations

  29. Matrix Operations • Zero matrix • A matrix where each element is 0 • zeros()

  30. Matrix Operations • Identity matrix • Square (i.e.m=n) • Diagonal entries equal to 1; all others are 0. • Multiplication by the identity matrix doesn’t change the matrix • eye()

  31. Row Reduction • Elementary row operations • Multiply a row by a scalar. • Add a scalar multiple of one row to another. • Exchange two rows. • Solve Ax=b • Row reduction with augmented matrix

  32. 2-by-2 cont’d • Back to 2-by-2 example • Rewrite as a matrix equation • Form an augmented matrix

  33. 2-by-2 cont’d • Solve by row reduction • Make left side look like an identity matrix using only elementary row operations

  34. Rank • r=rank(A) • Number of leading 1’s in the row-reduced matrix • From previous example, rank(A)=2

  35. Matrix Inverse • Matrix inverse • A must be square and full rank • If a matrix can be found such that AB=In, then B is called the inverse of A.

  36. 2-by-2 cont’d • Computing the inverse

  37. Matrix Inverse • If A is n-by-n and rank(A)=n, then A-1exists. • Implies there is a solution for every b • b is in the range of A • inv() • If A and B are both invertible,

  38. 2-by-2 cont’d • Inconsistent (no solution) • n=2, Rank=1 • Inverse doesn’t exist

  39. 2-by-2 cont’d • Consistent (infinite solutions) • n=2, Rank=1 • Inverse doesn’t exist

  40. Matrix Transpose • Transpose (‘ in MATLAB) • Swap rows and columns

  41. Scalar Product • Also called inner or dot product • Vectors must have the same length (size) • Multiply corresponding elements and add

  42. Scalar Product • Inner (dot) product • Also written as:

  43. Scalar Product • Properties

  44. Norms • Vector norms • 1-norm • 2-norm (Euclidean norm or length) • Infinity-norm

  45. Norms • Matrix Norm • 1-norm (column sum) • 2-norm – later • Infinity norm (row sum) • Frobenius norm

  46. Norms • Vector norm properties • Matrix norm properties

More Related