Engineering Problem Solving with C++ An Object Based Approach Chapter 7 Two-Dimensional Arrays and Matrices.

Slides:



Advertisements
Similar presentations
Maths for Computer Graphics
Advertisements

11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Multiple-Subscripted Array
Chapter 7 Arrays C++ Programming, Namiq Sultan1 Namiq Sultan University of Duhok Department of Electrical and Computer Engineering Reference: Starting.
Building Java Programs Chapter 7.5
Part 3 Chapter 8 Linear Algebraic Equations and Matrices PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The.
Matrix Mathematics in MATLAB and Excel
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
1 Chapter 3 Matrix Algebra with MATLAB Basic matrix definitions and operations were covered in Chapter 2. We will now consider how these operations are.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
4.2 Operations with Matrices Scalar multiplication.
Chapter 2 Solving Linear Systems Matrix Definitions –Matrix--- Rectangular array/ block of numbers. –The size/order/dimension of a matrix: (The numbers.
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Chapter 8 Matrices and Determinants Copyright © 2014, 2010, 2007 Pearson Education, Inc Matrix Operations and Their Applications.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Arrays & Vectors Week 5. The simplest form of the multidimensional array is the two-dimensional array. A two- dimensional array is, in essence, a list.
Class Opener:. Identifying Matrices Student Check:
Defining a 2d Array A 2d array implements a MATRIX. Example: #define NUMROWS 5 #define NUMCOLS 10 int arr[NUMROWS][NUMCOLS];
Two-Dimensional Arrays ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
1 Chapter 7 Arrays. 2 Topics 7.1 Arrays Hold Multiple Values 7.2 Accessing Array Elements 7.3 No Bounds Checking in C Array Initialization 7.5 Processing.
ES 240: Scientific and Engineering Computation. Chapter 8 Chapter 8: Linear Algebraic Equations and Matrices Uchechukwu Ofoegbu Temple University.
Chapter 6 Matrices and Determinants Copyright © 2014, 2010, 2007 Pearson Education, Inc Matrix Operations and Their Applications.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Matrix Algebra Section 7.2. Review of order of matrices 2 rows, 3 columns Order is determined by: (# of rows) x (# of columns)
8.2 Operations With Matrices
Function Overloading Two different functions may have the same name as long as they differ in the number or types of arguments: int max(int x, int y) and.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
Sec 4.1 Matrices.
Algebra Matrix Operations. Definition Matrix-A rectangular arrangement of numbers in rows and columns Dimensions- number of rows then columns Entries-
Matrices and Matrix Operations. Matrices An m×n matrix A is a rectangular array of mn real numbers arranged in m horizontal rows and n vertical columns.
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:
Arrays Chapter 7. Arrays Hold Multiple Values Array: variable that can store multiple values of the same type Values are stored in adjacent memory locations.
Two-Dimensional Arrays and Matrices ELEC 206 Computer Applications for Electrical Engineers.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Multidimensional.
Linear System of Simultaneous Equations Warm UP First precinct: 6 arrests last week equally divided between felonies and misdemeanors. Second precinct:
Do Now: Perform the indicated operation. 1.). Algebra II Elements 11.1: Matrix Operations HW: HW: p.590 (16-36 even, 37, 44, 46)
Chapter 5: Matrices and Determinants Section 5.5: Augmented Matrix Solutions.
Precalculus Section 14.1 Add and subtract matrices Often a set of data is arranged in a table form A matrix is a rectangular.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
Matrix Algebra Basics Chapter 3 Section 5. Algebra.
Matrix Algebra Definitions Operations Matrix algebra is a means of making calculations upon arrays of numbers (or data). Most data sets are matrix-type.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
A rectangular array of numeric or algebraic quantities subject to mathematical operations. The regular formation of elements into columns and rows.
1 Two-Dimensional Arrays. 2 Terminology Two-dimensional arrays represent matrices A matrix contains a number of values of the same data type The values.
Ch. 12 Vocabulary 1.) matrix 2.) element 3.) scalar 4.) scalar multiplication.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
12-1 Organizing Data Using Matrices
Chapter 7 Matrix Mathematics
Two Dimensional Array Mr. Jacobs.
Matrix Multiplication
Matrix Operations SpringSemester 2017.
Two Dimensional Arrays
Engineering Problem Solving with C++, Etter/Ingber
Chapter 13 Vector of Vectors (2D Arrays)
4-2 Adding & Subtracting Matrices
Matrices Elements, Adding and Subtracting
Multidimensional array
1.8 Matrices.
Matrix Operations SpringSemester 2017.
1.8 Matrices.
3.5 Perform Basic Matrix Operations Algebra II.
Chapter 6 - Arrays Outline Multiple-Subscripted Arrays.
Presentation transcript:

Engineering Problem Solving with C++ An Object Based Approach Chapter 7 Two-Dimensional Arrays and Matrices

Two-Dimensional Arrays row 0 row 1 row 2 row 3 Access elements using two offsets or subscripts, the first for the row and the second for the column Example: int twoDArr[4][3];// declares a 2-D array with 4 //rows and 3 columns cout << twoDArr[0][2]; // prints the value in row 0, col 2 // The value 4 in this example col 0col 1col 2

Assigning data to 2-D Arrays Initialization: char table[2][3]= { {'a','g','k'}, {'c', 'm', 'h'}}; Assignment using nested for loops for (int i=0; i<2; i++)// for every row for (int j=0; j > table[i][j]; 'a''g''k' 'c''m''h'

Printing 2-D Array for(int r=0; r<NROWS; r++) { for(int c=0; c<NCOLS; c++){ cout << twoDArr[r][c] << ‘ ‘;} cout << endl; } Note: prints space after each element and newline after each row.

Printing 2-D Array(formatted) for(int r=0; r<NROWS; r++) { cout << " \n| "; for(int c=0; c<NCOLS; c++) cout << twoDArr[r][c] << " | "; cout << endl; } cout << " \n| ";

Functions and 2-D Arrays Default is call-by reference when passing 2-D array to a function All sizes of the array, except the leftmost one, must be specified. The leftmost one may be [] Function prototype example: –int rowAverage(int Arr[][4], int whichRow); Array declaration in main: –int table [5][4]; Function invocation example: –Ave = rowAverage(table, 3);

Matrices Mathematical Matrix –can be implemented as 2-D array –be careful translating between C++ offsets and matrix subscripts.

Determinant Used in computing inverses of matrices and solving systems of simultaneous equations. Determinant of 2x2 matrix: Determinant of 3x3 matrix:

Transpose of a matrix Rows of original matrix become columns in the transposed matrix.

Matrix Addition and Subtraction Matrix addition (or subtraction) adds (or subtracts) corresponding elements of the two matrices producing a third matrix of the same size. The original two matrices must also be of the same size.

Practice! Given the following matrices, what is A+B

Practice! Given the following matrices, what is A+B

Matrix Multiplication A*B The number of columns in A must be the same as the number of rows in B. The resulting matrix has the number of rows in A and the number of columns in B. Element c i,j, where C=A*B, is:

Practice! Given the following matrices, what is A*B

Practice! Given the following matrices, what is A*B