Matrices CSE, POSTECH.

Slides:



Advertisements
Similar presentations
Sparse Matrices sparse … many elements are zero dense … few elements are zero.
Advertisements

TRIANGULAR MATRICES A square matrix in which all the entries above the main diagonal are zero is called lower triangular, and a square matrix in which.
Elementary Linear Algebra Anton & Rorres, 9th Edition
CSNB143 – Discrete Structure
Applied Informatics Štefan BEREŽNÝ
1 Section 7.3 Representing relations (part 1: matrices)
Algebraic, transcendental (i.e., involving trigonometric and exponential functions), ordinary differential equations, or partial differential equations...
Arrays and Matrices CSE, POSTECH. 2 2 Introduction Data is often available in tabular form Tabular data is often represented in arrays Matrix is an example.
LU - Factorizations Matrix Factorization into Triangular Matrices.
Arrays.
Arrays. 1D Array Representation In C 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
Solving Linear Systems (Numerical Recipes, Chap 2)
Section 1.7 Diagonal, Triangular, and Symmetric Matrices.
1.5 Elementary Matrices and a Method for Finding
Matrix Definition: An array of numbers in m rows and n colums is called an mxn matrix A square matrix of order n, is an (nxn) matrix.
1.7 Diagonal, Triangular, and Symmetric Matrices.
Autar Kaw Benjamin Rigsby Transforming Numerical Methods Education for STEM Undergraduates.
Determinants (10/18/04) We learned previously the determinant of the 2 by 2 matrix A = is the number a d – b c. We need now to learn how to compute the.
Maths for Computer Graphics
Design of parallel algorithms
Chapter 2 Matrices Definition of a matrix.
Matrix table of values
Module 6 Matrices & Applications Chapter 26 Matrices and Applications I.
Chapter 5 Determinants.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
A matrix having a single row is called a row matrix. e.g.,
Chapter 1: Matrices Definition 1: A matrix is a rectangular array of numbers arranged in horizontal rows and vertical columns. EXAMPLE:
1.7 Diagonal, Triangular, and Symmetric Matrices 1.
Presentation on Matrices and some special matrices In partial fulfillment of the subject Vector calculus and linear algebra ( ) Submitted by: Agarwal.
Arrays and Matrices 황승원 Fall 2010 CSE, POSTECH. 2 2 Any real-life matrix you know?
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Data Structure (Part II) Chapter 2 – Arrays. Matrix A matrix with 5 rows and 3 columns can be represented by n = 3 m = 5 We say this is a 5×3 matrix.
SNU IDB Lab. Ch8. Arrays and Matrices © copyright 2006 SNU IDB Lab.
Chapter 4 – Matrix CSNB 143 Discrete Mathematical Structures.
Co. Chapter 3 Determinants Linear Algebra. Ch03_2 Let A be an n  n matrix and c be a nonzero scalar. (a)If then |B| = …….. (b)If then |B| = …..... (c)If.
The Determinant of a Matrix Note: The determinant of a matrix can be positive, zero, or negative. Chapter 3 Determinants.
Chapter 3 Determinants Linear Algebra. Ch03_2 3.1 Introduction to Determinants Definition The determinant of a 2  2 matrix A is denoted |A| and is given.
Sparse Vectors & Matrices Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
CSNB143 – Discrete Structure Topic 3 – Matrices. Learning Outcomes Students should understand all matrices operations. Students should be able to differentiate.
Graphs 황승원 Fall 2010 CSE, POSTECH. 2 2 Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects.
Sparse Matrices Matrix  table of values. Sparse Matrices Matrix  table of values Row 2 Column 4 4 x 5 matrix.
1. 2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation.
2.5 – Determinants and Multiplicative Inverses of Matrices.
LEARNING OUTCOMES At the end of this topic, student should be able to :  D efination of matrix  Identify the different types of matrices such as rectangular,
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
Chapter 4 Section 1 Organizing Data into Matrices.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
Introduction Types of Matrices Operations
Arrays. 1D Array Representation In C++ 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
1.5 Matricies.
3.1 Introduction to Determinants
Arrays.
Chapter 8: Lesson 8.1 Matrices & Systems of Equations
Algorithms & Arrays.
Reminder: Array Representation In C++
RECORD. RECORD Subspaces of Vector Spaces: Check to see if there are any properties inherited from V:
RECORD. RECORD A Vector Space: the Definition.
بردارها و ماتريس ها ساختمان داده ها
Reminder: Array Representation In C++
CSE 541 – Numerical Methods
RECORD. RECORD COLLABORATE: Discuss: Is the statement below correct? Try a 2x2 example.
Determinant of a Matrix
Presented By Farheen Sultana Ist Year I SEM
Arrays.
Arrays.
Matrix A matrix is a rectangular arrangement of numbers in rows and columns Each number in a matrix is called an Element. The dimensions of a matrix are.
Reminder: Array Representation In C++
Presentation transcript:

Matrices CSE, POSTECH

Special Matrices A square matrix has the same number of rows and columns. Some special forms of square matrices are Diagonal: M(i,j) = 0 for i ≠ j Tridiagonal: M(i,j) = 0 for |i-j| < 1 Lower triangular: M(i,j) = 0 for i < j Upper triangular: M(i,j) = 0 for i > j Symmetric M(i,j) = M(j,i) for all i and j See Figure 7.7

Special Matrices

Special Matrices Why are we interested in these “special” matrices? We can provide more efficient implementations for specific special matrices. Rather than having a space complexity of O(n2), we can find an implementation that is O(n). We need to be clever about the “store” and “retrieve” operations to reduce time. Read Examples 7.4 & 7.5

Example 7.4 – Distance Matrix

Example 7.5 – Stack Folding Problem What is H(1,2)? Is this correct?

Diagonal Matrix Naive way to represent n x n diagonal matrix T d[n][n] d[i-1][j-1] for D(i,j) requires n2 x sizeof(T) bytes of memory Better way T d[n] d[i-1] for D(i,j) where i = j 0 for D(i,j) where i ≠ j requires n x sizeof(T) bytes of memory See Program 7.8 for the class diagonalMatrix

Tridiagonal Matrix Nonzero elements lie on one of three diagonals: main diagonal: i = j diagonal below main diagonal: i = j+1 diagonal above main diagonal: i = j-1 3n-2 elements on these three diagonals: T t[3n-2] Mappings of Figure 7.2(b) by row [2,1,3,1,3,5,2,7,9,0] by column [2,3,1,1,5,3,2,9,7,0] by diagonal [3,5,9,2,1,2,0,1,3,7] more on diagonal mapping on the next page

Tridiagonal Matrix Mapping by diagonals beginning with the lowest D(2,1) -> t[0] D(3,2) -> t[1] … D(n,n-1) -> t[n-2] D(1,1) -> t[n-1] D(2,2) -> t[n] ... D(n, n) -> t[(n-2)+n] = t[2n-2] D(1,2) -> t[2n-1] D(2,3) -> t[2n] D(n-1,n) -> t[(2n-2)+(n-1)] = t[3n-3] See Program 7.11

Triangular Matrix Nonzero elements lie in the region marked “nonzero” in the figure below 1+2+…+n = Σ(i=1..n) = n(n+1)/2 elements in the nonzero region

Triangular Matrix Both triangular matrices may be represented using 1-D array  T t[n(n+1)/2] Mappings by row?  [2,5,1,0,3,1,4,2,7,0] by column?  [2,5,0,4,1,3,2,1,7,0]

Lower Triangular Matrix Mapping by row L(i,j) = 0 if i < j L(i,j) = t[1+2+…+(i-1)+(j-1)] if i ≥ j = t[i(i-1)/2 + j-1] See Program 7.12 for the method lowerTriangularMatrix<T>::set

Upper Triangular Matrix Mapping by column  [2, 1, 1, 3, 3, 1, 0, 8, 6, 0] L(i,j) = ? if i > j L(i,j) = ? if i ≤ j Exercise: Write the method for upperTriangularMatrix<T>::set t[1+2+… +(j-1)+(i-1)] = t[j*(j-1)/2+i-1]

Symmetric Matrix An n x n matrix can be represented using 1-D array of size n(n+1)/2 by storing either the lower or upper triangle of the matrix Use one of the methods for a triangular matrix The elements that are not explicitly stored may be computed from those that are stored How do we compute this?

Sparse Matrix A matrix is sparse if many of its elements are zero A matrix that is not sparse is dense The boundary is not precisely defined Diagonal and tridiagonal matrices are sparse We classify triangular matrices as dense Two possible representations array linked list Read Example 7.6

Array Representation of Sparse Matrix The nonzero entries may be mapped into a 1D array in row-major order To reconstruct the matrix structure, need to record the row and column each nonzero comes from

Array Representation of Sparse Matrix template<class T> class Term { private: int row, col; T value; }; template<class T> class sparseMatrix { private: int rows, cols, int terms; Term<T> *a; int MaxTerms; public: //… }; See Programs 7.13~7.17 for the class definition and methods of sparseMatrix

Linked Representation of Sparse Matrix A shortcoming of the 1-D array of a sparse matrix is that we need to know the number of nonzero terms in each of the sparse matrices when the array is created A linked representation can overcome this shortcoming

Linked Representation of Sparse Matrix See Program 7.18 for linked representation of sparse matrix Read Chapter 7