CS 177 Week 9 Recitation Slides 1 Matrix Encoding Matrix Multiplication Trees as Lists Columnar Transposition 3/1/2016.

Slides:



Advertisements
Similar presentations
Section 13-4: Matrix Multiplication
Advertisements

Prim’s Algorithm from a matrix A cable TV company is installing a system of cables to connect all the towns in the region. The numbers in the network are.
Matrix Multiplication To Multiply matrix A by matrix B: Multiply corresponding entries and then add the resulting products (1)(-1)+ (2)(3) Multiply each.
ENGR-1100 Introduction to Engineering Analysis
Matrix Multiplication (i,j,k) for I = 1 to n do for j = 1 to n do for k = 1 to n do C[i,j] = C[i,j] + A[i,k] x B[k,j] endfor.
1 Matrix Addition, C = A + B Add corresponding elements of each matrix to form elements of result matrix. Given elements of A as a i,j and elements of.
Multiplying matrices An animated example. (3 x 3)x (3 x 2)= (3 x 2) These must be the same, otherwise multiplication cannot be done Is multiplication.
Table of Contents Matrices - Multiplication Assume that matrix A is of order m  n and matrix B is of order p  q. To determine whether or not A can be.
Modeling Multiplication of Fractions
Data Structures More List Methods Our first encoding Matrix.
Arrays and Fact Families
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Factors and Primes by 2July. Definition Product – the answer to a multiplication problem. 5 x 6 = 30 Product.
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.
4.3 Matrix Multiplication 1.Multiplying a Matrix by a Scalar 2.Multiplying Matrices.
Programming Practicum Day 3: Problem Solving with Graphs Aaron Tan NUS School of Computing.
8.2 Operations With Matrices
ADA: 4.5. Matrix Mult.1 Objective o an extra divide and conquer example, based on a question in class Algorithm Design and Analysis (ADA) ,
SATMathVideos.Net A set S consists of all multiples of 4. Which of the following sets are contained within set S? A) S2 only B) S4 only C) S2 and S4 D)
Objectives: Students will be able to… Multiply two matrices Apply matrix multiplication to real life problems.
Review Algebra 1 Chapter
Matrix Multiplication The Introduction. Look at the matrix sizes.
Section 4.3 – Multiplying Matrices. MATRIX MULTIPLICATION 1. The order makes a difference…AB is different from BA. 2. The number of columns in first matrix.
Section – Operations with Matrices No Calculator By the end of this lesson you should be able to: Write a matrix and identify its order Determine.
Matrix Multiplication. Row 1 x Column X 25 = Jeff Bivin -- LZHS.
National Tsing Hua University ® copyright OIA National Tsing Hua University HSA HW1.
3.6 Multiplying Matrices Homework 3-17odd and odd.
Announcements No Labs / Recitation this week On Friday we will talk about Project 3 Release late afternoon / evening tomorrow Cryptography.
= the matrix for T relative to the standard basis is a basis for R 2. B is the matrix for T relative to To find B, complete:
What does this say? Matrix Multiplication ! What does this say?
Notes Over 4.2 Finding the Product of Two Matrices Find the product. If it is not defined, state the reason. To multiply matrices, the number of columns.
12-2 MATRIX MULTIPLICATION MULTIPLY MATRICES BY USING SCALAR AND MATRIX MULTIPLICATION.
Matrix Multiplication Example 1 Original author: Jeffrey Bivin, Lake Zurich High School.
Multiply matrices Use the properties of matrix multiplication.
Data Structures So far, we have seen native data structures: Simple values: int, float, Boolean Sequences: Range, string, list Tuple, dictionary (chapter.
CSNB 143 Discrete Mathematical Structures
Lesson 43: Working with Matrices: Multiplication
MATRICES.
12-1 Organizing Data Using Matrices
What Property is being demonstrated? 6x(4 – 2) = 24x – 12x
Factors and Primes.
Matrix Multiplication
Matrix Multiplication
Columnar Transposition
D I s , a ·.... l8l8.
FP1 Matrices Introduction
Multiplying Matrices.
Section 3.1 – Operations with Matrices
Find 4 A + 2 B if {image} and {image} Select the correct answer.
Dynamic Programming 2 Neil Tang 4/22/2010
Modeling Multiplication of Fractions
I ll I
CS100: Discrete structures
Determinant of a Matrix

MATRICES Operations with Matrices Properties of Matrix Operations
Multiplying Matrices.
' 1 A ./.\.l+./.\.l
Dynamic Programming 2 Neil Tang 4/22/2008
Dimensions matching Rows times Columns
Space groups Start w/ 2s and 21s 222.
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.
Multiplying Matrices.
Multiplying Matrices.
Matrix Multiplication Sec. 4.2
Matrices - Operations MULTIPLICATION OF MATRICES
Multiplying Matrices.
Applied Discrete Mathematics Week 4: Functions
Presentation transcript:

CS 177 Week 9 Recitation Slides 1 Matrix Encoding Matrix Multiplication Trees as Lists Columnar Transposition 3/1/2016

Announcements 3/1/2016 2

Matrix Encoding: Row by Row 3/1/ A ,00,10,2 1,01,11,2 2,02,1 A = [1, 1, 0, 3, 2, 8, 5, -3, 5] rowLength = 3 A[rowLength*y +x]

Matrix Encoding: Column by Column 3/1/ A ,00,10,2 1,01,11,2 2,02,1 A = [1, 3, 5, 1, 2, -3, 0, 8, 5] columnLength = 3 A[columnLength*y +x]

Matrix Multiplication 3/1/ ,00,10,2 1,01,11,2 2,02,1 0,00,10,2 1,01,11,2 2,02,1 0,00,10,2 1,01,11,2 2,02,1 = * CA B CAB

Matrix Multiplication 3/1/ CA B C 0,0 = A 0,0 * B 0,0 + A 0,1 * B 1,0 + A 0,2 * B 2,

Matrix Multiplication 3/1/ CA B C 0,1 = A 0,0 * B 0,1 + A 0,1 * B 1,1 + A 0,2 * B 2,

Matrix Multiplication 3/1/ CA B C 0,2 = A 0,0 * B 0,2 + A 0,1 * B 1,2 + A 0,2 * B 2,

Matrix Multiplication 3/1/ CA B C 1,0 = A 1,0 * B 0,0 + A 1,1 * B 1,0 + A 1,2 * B 2,

Matrix Multiplication 3/1/ CA B C 1,1 = A 1,0 * B 0,1 + A 1,1 * B 1,1 + A 1,2 * B 2,

Matrix Multiplication 3/1/ CA B C 1,2 = A 1,0 * B 0,2 + A 1,1 * B 1,2 + A 1,2 * B 2,

Matrix Multiplication 3/1/ CA B C 2,0 = A 2,0 * B 0,0 + A 2,1 * B 1,0 + A 2,2 * B 2,

Matrix Multiplication 3/1/ CA B C 2,1 = A 2,0 * B 0,1 + A 2,1 * B 1,1 + A 2,2 * B 2,

Matrix Multiplication 3/1/ CA B C 2,2 = A 2,0 * B 0,2 + A 2,1 * B 1,2 + A 2,2 * B 2,

3/1/ ,0= *0,0+1,1*1,0+1,2*2,0 2,2=2,0*0,2+2,1*1,2+2,2* 2,1=2,0*0,1+2,1*1,1+2,2*2,1 2,0= *0,0+2,1*1,0+2,2*2,0 1,1=1,0*0,1+1,1* +1,2*2,1 1,2=1,0*0,2+1,1*1,2+ *2,2 0,1=0,0*0,1+ *1,1+0,2*2,1 0,0= * +0,1*1,0+0,2*2,0 0,2=0,0*0,2+0,1*1,2+0,2*2,2 Indexes in Matrix Multiplication

Matrix Multiplication 3/1/ A = [[1, 1, 1],[2,2,2],[3,3,3]] B = [[1, 2, 3], [4,5,6],[7,8, 9]] C = [3*[0] for i in range(3)] for i in range(3): for j in range(3): for k in range(3): C[i][j] = C[i][j] + ( A[i][k] * B[k][j])

Trees as Lists Lists are powerful structures Lists can be used to build trees 3/1/ Root Leaf1Leaf2Leaf3 Root L1 L2 L3L4L5L0 L1 L2 L3L4 L6 L0 L5 Root

Simple trees >>> Tree1 = ['L0', 'L1'] >>>Tree2 = ['L0', 'L1', 'L2'] >>>Tree3 = ['L0', 'L1', 'L2','L3', 'L4', 'L5'] 3/1/ L1 Tree1 L0 L1 L2 L0 Tree2 L0 Tree3 L1 L2 L3L4 L5

>>> Tree = [['L0', 'L1'], ['L2','L3']] What is tree[1][0]? What is tree[0][1]? 3/1/ Tree L1L L2L3 0 1

Question Build the list representing the following tree, (and call it tree) 3/1/ Tree BA EF C D

Answer >>>Tree = [[‘A’,’B’],[’C’,’D’],[’E’,’F’]] 3/1/ Tree BA EF C D

Question Build the following tree: 3/1/ Tree B EF D XYZ

Answer Build the following tree >>> Tree = [[['X','Y'],'B'],[['Z'],'D'],['E','F'] ] 3/1/ Tree B EF D XY Z

Question How to access: X, Z, and E? 3/1/ Tree B EF D XY Z

Answer >>>Tree[0][0][0] ‘X’ >>>Tree[1][0][0] ‘Z’ >>>Tree[2][0] ‘E’ 3/1/ Tree B EF D XY Z

Columnar Transposition S = [[‘P’, ‘R’, ‘O’], [‘G’, ‘R’, ‘A’], [‘M’, ‘~’, ‘~’]] How to get “PROGRAM”? How to get “MGP~RP~AO”? 26 PRO GRA M~~

D = "" for i in range(0,3): for j in range(0,3): D = D + S[i][j] print(D) D = "" for i in range(0,3): for j in range(0,3): D = D + S[3-1-j][i] print(D) 27

ANY QUESTIONS? 3/1/