Additional Data Types: 2-D Arrays, Logical Arrays Selim Aksoy Bilkent University Department of Computer Engineering

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Maths for Computer Graphics
Arrays Revisited Selim Aksoy Bilkent University Department of Computer Engineering
Additional Data Types: 2-D Arrays, Logical Arrays, Strings Selim Aksoy Bilkent University Department of Computer Engineering
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering
EGR 106 – Week 4 – Math on Arrays
Week 3 Last week Vectors Array Addressing Mathematical Operations Array Multiplication and Division Identity Matrix Inverse of a Matrix Element by Element.
Part 3 Chapter 8 Linear Algebraic Equations and Matrices PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The.
Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering
Finding the Inverse of a Matrix
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
ECON 1150 Matrix Operations Special Matrices
4.4 & 4.5 Notes Remember: Identity Matrices: If the product of two matrices equal the identity matrix then they are inverses.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Chapter 2 Systems of Linear Equations and Matrices
Lecture 28: Mathematical Insight and Engineering.
Unit 3: Matrices.
Algebra 3: Section 5.5 Objectives of this Section Find the Sum and Difference of Two Matrices Find Scalar Multiples of a Matrix Find the Product of Two.
Matrices. Definitions  A matrix is an m x n array of scalars, arranged conceptually as m rows and n columns.  m is referred to as the row dimension.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
ES 240: Scientific and Engineering Computation. Chapter 8 Chapter 8: Linear Algebraic Equations and Matrices Uchechukwu Ofoegbu Temple University.
Slide Copyright © 2009 Pearson Education, Inc. 7.3 Matrices.
4.5 Matrices, Determinants, Inverseres -Identity matrices -Inverse matrix (intro) -An application -Finding inverse matrices (by hand) -Finding inverse.
ME 142 Engineering Computation I Matrix Operations in Excel.
1 ECE 1304 Introduction to Electrical and Computer Engineering Section 1.7 Linear Algebra with MATLAB.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
MT411 Robotic Engineering Asian Institution of Technology (AIT) Chapter 1 Introduction to Matrix Narong Aphiratsakun, D.Eng.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Chapter 4 Section 5 and 6 Finding and Using Inverses Algebra 2 Notes February 26, 2009.
H.Melikian/12101 System of Linear Equations and Augmented Matrices Dr.Hayk Melikyan Departmen of Mathematics and CS
Use Inverse Matrices to Solve Linear Systems Objectives 1.To find the inverse of a square matrix 2.To solve a matrix equation using inverses 3.To solve.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Project Teams Project on Diffusion will be a TEAM project. 34 Students in class so 6 teams of 5 and one Team of 4. Determine members of team and a team.
ENG College of Engineering Engineering Education Innovation Center 1 Array Operations in MATLAB 1.Types of Matrix arithmetic 2.Dot operators Mathematical.
Unit 3: Matrices. Matrix: A rectangular arrangement of data into rows and columns, identified by capital letters. Matrix Dimensions: Number of rows, m,
Do Now: Perform the indicated operation. 1.). Algebra II Elements 11.1: Matrix Operations HW: HW: p.590 (16-36 even, 37, 44, 46)
Matrices. Matrix - a rectangular array of variables or constants in horizontal rows and vertical columns enclosed in brackets. Element - each value in.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
1 Matrix Math ©Anthony Steed Overview n To revise Vectors Matrices.
Use Inverse Matrices to Solve Linear Systems
Solving Linear Systems Syed Nasrullah
Finding the Inverse of a Matrix
Linear Algebraic Equations and Matrices
Matrix Multiplication
Matrix Operations SpringSemester 2017.
EGR 106 – Week 4 – Math on Arrays
7.3 Matrices.
الوحدة السابعة : المصفوفات . تنظيم البيانات فى مصفوفات . الوحدة السابعة : المصفوفات . تنظيم البيانات فى مصفوفات . 1 جمع المصفوفات وطرحها.
Section 6.4 Multiplicative Inverses of Matices and Matrix Equations
Introduction to MATLAB Lecture 02
Use Inverse Matrices to Solve Linear Systems
Unit 3: Matrices
Section 9.4 Multiplicative Inverses of Matices and Matrix Equations
ARRAY DIVISION Identity matrix Islamic University of Gaza
3.6 Multiply Matrices.
1.8 Matrices.
Matrix Operations SpringSemester 2017.
1.8 Matrices.
3.5 Perform Basic Matrix Operations Algebra II.
Presentation transcript:

Additional Data Types: 2-D Arrays, Logical Arrays Selim Aksoy Bilkent University Department of Computer Engineering

Spring 2004CS D Arrays a = [ 1:2:7; 10:2:16 ] a = [ x, y ] = size(a) x = 2 y = 4 a(2,:) ans = a(:) ans = Recall matrices and subarrays

Spring 2004CS D Arrays Adding the elements of a matrix function s = sum_elements(a) [r,c] = size(a); s = 0; for ii = 1:r, for jj = 1:c, s = s + a(ii,jj); end end

Spring 2004CS D Arrays a = [ 1:2:7; 10:2:16 ]; sum(a) ans = sum(a,1) ans = sum(a,2) ans = sum(a(:)) ans = 68 Adding the elements of a matrix (cont.)

Spring 2004CS D Arrays Finding the maximum value in each row function f = maxrow(a) [r,c] = size(a); f = zeros(r,1); for ii = 1:r, m = a(ii,1); for jj = 2:c, if ( m < a(ii,jj) ), m = a(ii,jj); end end f(ii) = m; end

Spring 2004CS D Arrays a = [ 1:2:7; 10:2:16 ]; max(a) ans = max(a,[],1) ans = max(a,[],2) ans = 7 16 max(a(:)) ans = 16 Finding the maximum value (cont.)

Spring 2004CS D Arrays Replace elements that are greater than t with the number t function b = replace_elements(a,t) [r,c] = size(a); b = a; for ii = 1:r, for jj = 1:c, if ( a(ii,jj) > t ), b(ii,jj) = t; end end end

Spring 2004CS 1118 Logical Arrays Created by relational and logical operators Can be used as masks for arithmetic operations A mask is an array that selects the elements of another array so that the operation is applied to the selected elements but not to the remaining elements

Spring 2004CS 1119 Logical Arrays Examples b = [ 1 2 3; 4 5 6; ] b = c = b > 5 c = whos Name Size Bytes Class a 2x4 64 double array b 3x3 72 double array c 3x3 72 double array (logical)

Spring 2004CS Logical Arrays Examples b(c) = sqrt( b(c) ) b = b(~c) = b(~c).^2 b =

Spring 2004CS Logical Arrays Examples c = b( ( b > 2 ) & ( b < 8 ) ) c = length( b( ( b > 2 ) & ( b < 8 ) ) ) ans = 5

Spring 2004CS Logical Arrays Examples [r,c] = find( ( b > 2 ) & ( b < 8 ) ) r = c =

Spring 2004CS Matrix Operations Scalar-matrix operations a = [ 1 2; 3 4 ] a = * a ans = a + 4 ans = Element-by-element operations a = [ 1 0; 2 1 ]; b = [ -1 2; 0 1 ]; a + b ans = a.* b ans =

Spring 2004CS Matrix Operations Matrix multiplication: C = A * B If A is a p-by-q matrix B is a q-by-r matrix then C will be a p-by-r matrix where

Spring 2004CS Matrix Operations Matrix multiplication: C = A * B

Spring 2004CS Matrix Operations Examples a = [ 1 2; 3 4 ] a = b = [ -1 3; 2 -1 ] b = a.* b ans = a * b ans =

Spring 2004CS Matrix Operations Examples a = [ 1 4 2; 5 7 3; ] a = b = [ 6 1; 2 5; 7 3 ] b = c = a * b c = d = b * a ??? Error using ==> * Inner matrix dimensions must agree.

Spring 2004CS Matrix Operations Identity matrix: I A * I = I * A = A Examples a = [ 1 4 2; 5 7 3; ]; I = eye(3) I = a * I ans =

Spring 2004CS Matrix Operations Inverse of a matrix: A -1 A A -1 = A -1 A = I Examples a = [ 1 4 2; 5 7 3; ]; b = inv(a) b = a * b ans =

Spring 2004CS Matrix Operations Matrix left division: C = A \ B Used to solve the matrix equation A X = B where X = A -1 B In MATLAB, you can write x = inv(a) * b x = a \ b (second version is recommended)

Spring 2004CS Matrix Operations Example: Solving a system of linear equations A = [ ; 2 8 2; ]; B = [ ]'; X = A \ B X =

Spring 2004CS Matrix Operations Matrix right division: C = A / B Used to solve the matrix equation X A = B where X = B A -1 In MATLAB, you can write x = b * inv(a) x = b / a (second version is recommended)