Arrays and Matrices Prof. Abdul Hameed.

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

Lesson 12.2 Matrix Multiplication. 3 Row and Column Order The rows in a matrix are usually indexed 1 to m from top to bottom. The columns are usually.
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.
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.
Matrix Multiplication To Multiply matrix A by matrix B: Multiply corresponding entries and then add the resulting products (1)(-1)+ (2)(3) Multiply each.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
4.2 Operations with Matrices Scalar multiplication.
Arrays and Matrices 황승원 Fall 2010 CSE, POSTECH. 2 2 Any real-life matrix you know?
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
Class Opener:. Identifying Matrices Student Check:
8.2 Operations With Matrices
MATRIX A set of numbers arranged in rows and columns enclosed in round or square brackets is called a matrix. The order of a matrix gives the number of.
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
3.6 Multiplying Matrices Homework 3-17odd and odd.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Systems of Equations and Matrices Review of Matrix Properties Mitchell.
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.
C++ Arrays SarMag Trimester 31 C++ Arrays. C++ Arrays SarMag Trimester 32 C++ Arrays An array is a consecutive group of memory locations. Each group is.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
2.1 Matrix Operations 2. Matrix Algebra. j -th column i -th row Diagonal entries Diagonal matrix : a square matrix whose nondiagonal entries are zero.
MTH108 Business Math I Lecture 20.
13.4 Product of Two Matrices
Properties and Applications of Matrices
nhaa/imk/sem /eqt101/rk12/32
12-1 Organizing Data Using Matrices
Matrices Rules & Operations.
Linear Algebra review (optional)
Two-Dimensional Arrays
Discrete Structures – CNS2300
CHAPTER 2 MATRICES Determinant Inverse.
1.5 Matricies.
Arrays.
Matrix Multiplication
MULTI-DIMENSIONAL ARRAY
Matrix Operations SpringSemester 2017.
Reminder: Array Representation In C++
Multiplying Matrices.
WarmUp 2-3 on your calculator or on paper..
Matrix Algebra.
بردارها و ماتريس ها ساختمان داده ها
Reminder: Array Representation In C++
25. Basic matrix operations
2. Matrix Algebra 2.1 Matrix Operations.
CS111 Computer Programming
Section 2.4 Matrices.
2.2 Introduction to Matrices
Objectives Multiply two matrices.
Matrices Introduction.
CS100: Discrete structures
Multidimensional array
Multiplying Matrices.
Multi-Dimensional Arrays
Dimensions matching Rows times Columns
Arrays.
Arrays.
3.6 Multiply Matrices.
Linear Algebra review (optional)
Matrix Addition, C = A + B Add corresponding elements of each matrix to form elements of result matrix. Given elements of A as ai,j and elements of B as.
Matrix Operations SpringSemester 2017.
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++
Multiplying Matrices.
Multiplying Matrices.
Matrix Multiplication Sec. 4.2
Introduction to Matrices
Multiplying Matrices.
Applied Discrete Mathematics Week 4: Functions
Presentation transcript:

Arrays and Matrices Prof. Abdul Hameed

Introduction Data is often available in tabular form Tabular data is often represented in arrays Matrix is an example of tabular data and is often represented as a 2-dimensional array Matrices are normally indexed beginning at 1 rather than 0 Matrices also support operations such as add, multiply, and transpose

1D Array Representation in C++ Memory a b c d start 1-dimensional array x = [a, b, c, d] map into contiguous memory locations location(x[i]) = start + i

2D Arrays The elements of a 2-dimensional array a declared as: int a[3][4]; may be shown as a table a[0][0] a[0][1] a[0][2] a[0][3] a[1][0] a[1][1] a[1][2] a[1][3] a[2][0] a[2][1] a[2][2] a[2][3] What about #bytes/element of array? Excluded in above analysis.

Rows of a 2D Array a[0][0] a[0][1] a[0][2] a[0][3] row 0 What about #bytes/element of array? Excluded in above analysis.

Columns of a 2D Array a[0][0] a[0][1] a[0][2] a[0][3] What about #bytes/element of array? Excluded in above analysis. column 0 column 1 column 2 column 3

2D Array Representation in Memory 2-dimensional array x a, b, c, d e, f, g, h i, j, k, l view 2D array as a 1D array of rows x = [row0, row1, row 2] row 0 = [a, b, c, d] row 1 = [e, f, g, h] row 2 = [i, j, k, l] and store as 4 1D arrays

2D Array Representation in Memory b c d e f g h i j k l x[] 4 separate 1-dimensional arrays space overhead = overhead for 4 1D arrays = 4 * 4 bytes = 16 bytes = (number of rows + 1) x 4 bytes The 4 separate arrays are x, x[0], x[1], and x[2].

Array Representation in Memory b c d e f g h i j k l x[] This representation is called the array-of-arrays representation. Requires contiguous memory of size 3, 4, 4, and 4 for the 4 1D arrays. 1 memory block of size number of rows and number of rows blocks of size number of columns

Row-Major Mapping Example 3 x 4 array: a b c d e f g h i j k l Convert into 1D array y by collecting elements by rows. Within a row elements are collected from left to right. Rows are collected from top to bottom. We get y[] = {a, b, c, d, e, f, g, h, i, j, k, l} row 0 row 1 row 2 … row i

Column-Major Mapping a b c d e f g h i j k l Convert into 1D array y by collecting elements by columns. Within a column elements are collected from top to bottom. Columns are collected from left to right. We get y = {a, e, i, b, f, j, c, g, k, d, h, l}

Row- and Column-Major Mappings 2D Array int a[3][6]; a[0][0] a[0][1] a[0][2] a[0][3] a[0][4] a[0][5] a[1][0] a[1][1] a[1][2] a[1][3] a[1][4] a[1][5] a[2][0] a[2][1] a[2][2] a[2][3] a[2][4] a[2][5]

Matrices m x n matrix is a table with m rows and n columns. M(i,j) denotes the element in row i and column j. Common matrix operations transpose addition multiplication

Matrix Operations Transpose Addition The result of transposing an m x n matrix is an n x m matrix with property: MT(j,i) = M(i,j), Addition The sum of matrices is only defined for matrices that have the same dimensions. The sum of two m x n matrices A and B is an m x n matrix with the property: C(i,j) = A(i,j) + B(i,j),

Matrix Operations Multiplication The product of matrices A and B is only defined when the number of columns in A is equal to the number of rows in B. Let A be m x n matrix and B be a n x q matrix. A*B will produce an m x q matrix with the following property: