Matrices - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Matrices

Description:

Matrices. What is a Matrix. An arrangement of numbers in rows and columns ... transpose operator, deleting columns, ones, zeros,size(), entering values, ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 16
Provided by: saikatmuk
Category:
Tags: columns | matrices

less

Transcript and Presenter's Notes

Title: Matrices


1
Matrices
2
What is a Matrix
  • An arrangement of numbers in rows and columns
  • A mathematical structure

3
Using Matrices
  • A coat company has 4 factories for manufacturing
    coats and sends them to 5 stores. The cost of
    sending one coat from a factory to a store is
    given in this table
  • The amount of coats that each factory can
    manufacture for each store is given in this table
  • What is total cost of transporting from a factory
    to a store ?

4
Matrix Operators in MATLAB
  • Transpose Turns rows into columns and vice versa
  • Colon used to obtain subparts of the matrix
  • What is the total cost of transportation from
    factory 3
  • size() gives the size of the matrix
  • Replacing values in matrices
  • Into ones ones()?
  • Into zeros zeros()?
  • Into values from other matrices, vectors or
    scalars
  • Duplicating rows/columns
  • Deleting rows and columns

5
Some Special Matrices
  • Identity Matrix
  • Diagonal Matrices
  • Tridiagonal matrices

6
Matrix Manipulation
  • diag extracts or creates diagonal matrices
  • fliplr flips from left to right
  • flipud flips from top to bottom
  • rot90 rotates
  • tril extracts the lower triangular part
  • eye creates identity matrix

7
MATLAB Functions for Matrices
  • sum
  • mean
  • max
  • min

8
Vectorization of nested fors
  • Multiple for loops can be vectorized by matrix
    operations
  • Example If a regular fixed payment P is made n
    times a year to repay a loan of amount A over a
    period of k years, where the annual interest rate
    is r, then P is given by
  • PrA(1r/n)(nk)/(n(1r/n)(nk)-1)?

9
Multidimensional Arrays
  • Matrices can have more than two dimension
  • Think of 3D arrays as a matrix in each page
  • Used in color (RGB) pictures

10
Matrix---Numerical Entities
  • Matrix Multiplication
  • CAB
  • C(ij)Sum(a(ik)b(kj)) k1m
  • Matrix Multiplication generally is not
    commutative
  • AAI (I is the identity matrix)?
  • Some Other Functions
  • inv---Inverse of matrix (sort of like dividing by
    the matrix)?
  • lu---decomposing the matrix into upper and lower
    triangular parts
  • svd--decomposing the matrix, to save storage
    space

11
Solving Equations
  • 2x3y 4z9
  • xy-z1
  • 2x-y-z0
  • What values of x,y,z satisfy all the three
    equations?
  • We can use inv() to solve

12
From Numbers to Letters
  • Strings are just arrays of letters
  • Use the same vector operations as numbers
  • For arithmetic operations letters are considered
    as numbers
  • fprintf can be used for string manipulation
  • Fun things to do
  • Detect palindromes
  • Substitute letters in strings
  • Concatenate strings
  • How many three lettered words can you make with
    a,o,c,t,r ?

13
Other String Functions
  • blanks
  • deblanks
  • int2str
  • num2str
  • ischar
  • lower
  • Upper
  • 2D strings

14
Eval Function
  • eval() evaluates a MATLAB function
  • Can be used to for interactive plotting
  • lasterr() returns string containing last error
    message

15
Summary
  • Sections covered
  • 6.1 (except 6.1.14), 6.2,6.3 6.4, 6.5,6.6
    (except 6.6.2)?
  • What we learned
  • transpose operator, deleting columns, ones,
    zeros,size(), entering values, repmat, sum,
    min,mx, mean, all,any,diag,fliplr, flipud,
    rot90,tril, eye, matrix multiplication, svd, lu,
    inv,blanks,deblanks,lower, upper,ischar, int2str,
    num2str
Write a Comment
User Comments (0)
About PowerShow.com