1 / 17

COMP 116: Introduction to Scientific Programming

COMP 116: Introduction to Scientific Programming . Lecture 7 : Matrices and Linear Systems. Recap exercises. Indexing: what does A(3:7,5:end) return? Creating: how do you create this matrix? Statistical functions for matrices: min, max, sum, mean, std. A gambling game. One matrix M

gizi
Download Presentation

COMP 116: Introduction to Scientific 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. COMP 116: Introduction to Scientific Programming Lecture 7: Matrices and Linear Systems

  2. Recap exercises • Indexing: what does A(3:7,5:end) return? • Creating: how do you create this matrix? • Statistical functions for matrices: • min, max, sum, mean, std

  3. A gambling game • One matrix M • Two teams: the house and the gambler • Gambler picks a column of M, house picks an element from this column. The gambler wins this amount • How much should the house charge the gambler for playing this game? • How much should the gambler pay for playing this game?

  4. Today • Linear systems • Solving simultaneous (linear) equations

  5. Simultaneous equations • Solve this set of (math) equations • 5x+7y=17 • 2x+3y=7 • Now solve this one • 5x+7y+z+2w=30 • 3x+4y+8z+w=39 • 9x+y+4z+2w=31 • 6x+2y+5z+8w=57

  6. Linear Equations

  7. Solving linear equations • Ax=b • A is an m x n matrix • Rows of A correspond to equations • Columns of A correspond to variables • x is a n x 1 matrix (n element column vector) • b is a m x 1 matrix ( m element column) • In general if m equals n, then x=(A)-1b • Or in matlabspeak: • x=inv(A)*b • Matlab shorthand >> x=A\b

  8. Exercise • Solve these set of equations in the Matlab way • Convert to Ax=b format • Then x=inv(A)*b • Set I • 5x+7y=17 • 2x+3y=7 • Set II • 5x+7y+z+2w=30 • 3x+4y+8z+w=39 • 9x+y+4z+2w=31 • 6x+2y+5z+8w=57

  9. Matrix multiplication

  10. Vector multiplication >> [1 2 3]*[4 5 6] ??? Error using ==> mtimes Inner matrix dimensions must agree. >> [1 2 3]*[4;5;6] ans = 32 >> [1 2 3]*[4 5 6]' ans = 32

  11. Matrix-Vector Multiplication

  12. Linear Equations Key idea: Can write a complete linear system in vector notation: Ax=b. Since x is unknown, we need some way to express it in terms of A and b.

  13. Matrix Math • Matrix multiplication

  14. Matrix Math Exercise • Identity matrix

  15. Matrix Math • Inverse >> A*inv(A) ans = 1.0000 0 0.0000 1.0000 >> A\A ans = 1 0 0 1 Inverse needs to exist.

  16. Linear Equations: Solving Mathematical formulation One line: x = A\b MATLAB solution:

  17. Matrix element naming convention

More Related