Presentation is loading. Please wait.

Presentation is loading. Please wait.

BTEC NCF Dip in Comp - Unit 02 Fundamentals of Computer Systems Lesson 12 – Indices and Matrices Mr C Johnston.

Similar presentations


Presentation on theme: "BTEC NCF Dip in Comp - Unit 02 Fundamentals of Computer Systems Lesson 12 – Indices and Matrices Mr C Johnston."— Presentation transcript:

1 BTEC NCF Dip in Comp - Unit 02 Fundamentals of Computer Systems Lesson 12 – Indices and Matrices
Mr C Johnston

2 Learning Outcome Understand matrix representation in computer systems:
the relationship between matrices and arrays mathematical operations using matrices single, two and multi-dimensional arrays row-major and column-major order

3 Matrices Introduction to Matrices A matrix is a rectangular collection of numbers which can be used in mathematical operations Matrices are used within may areas of computing including in the calculations for wire framing Matrices can have different dimensions depending on the application 1 dimension matrix: 1 row x cols 3 dimension matrix: x layers, x rows, x cols 2 dimension matrix: x rows x cols

4 Reading and Referencing Matrices
Matrices – Elements, Order and Position Reading and Referencing Matrices Use co-ordinates to access elements (value) within a matrix Layer, Row, Column is the order of the co-ordinates (reference) 1 dimension matrix 3 dimension matrix [0] 1 2 3 [0,2,1]th = 3 [2]th = 1 [1] 2 dimension matrix 1 2 3 [1,3,2]th = 7 1 2 3 [2] 1 2 3 [2,1,3]th = 2 [2,3]th = 5

5 Activity Complete this basic matrix exercise
Matrix Fundamentals Dimensions & Elements Complete this basic matrix exercise

6 Calculations With Matrices - Addition
Add each corresponding element together a 4 2 b c 5 7 d Y= a 8 -9 b c -3 3 d Z= a 4 2 b c 5 7 d a 8 -9 b c -3 3 d Y + Z= + Y + Z= a YA + ZA YB + ZB b c YC + ZC YD + ZD d Y + Z= a 4 + 8 2 + -9 b c 5 + -3 7 + 3 d Y + Z= a 12 -7 b c 2 10 d

7 Calculations With Matrices - Subtraction
Matrices – Addition and Subtraction Calculations With Matrices - Subtraction Subtract each corresponding element a 4 2 b c 5 7 d Y= a 8 -9 b c -3 3 d Z= a 4 2 b c 5 7 d a 8 -9 b c -3 3 d Y - Z= - Y - Z= a YA – ZA YB - ZB b c YC - ZC YD – ZD d Y - Z= a 4 – 8 2 - -9 b c 5 - -3 7 – 3 d Y - Z= a -4 11 b c 8 4 d

8 Calculations With Matrices - Multiplication
Multiply the rows of one matrix by the row of the other a 4 2 b c 5 7 d Y= a 8 c 5 Z= a 4 2 b c 5 7 d a 8 c 5 Y * Z= * Y * Z= a (YA * ZA) + (YB * ZC) c (YC * ZA) + (YD * ZC) Y * Z= a (4 * 8) + (2 * 5) c (5 * 8) + (7 * 5) Y * Z= a c 40 +35 Y - Z= a 46 c 75

9 Activity Complete this basic maths matrix exercise

10 Transformation Matrices
Used to transform shapes Multiply original co-ordinates by the transformation matrix to get the transformed co-ordinates To calculate the transformed x co-ordinate use the formula x = ax + by To calculate the transformed x co-ordinate use the formula y = cx + dy For complex shapes deal with each co-ordinate in a logical way – go round the shape in either CW or ACW direction Reflect in X-Axis Transformation a -1 b c 1 d Reflect in Y-Axis Transformation a 1 b c -1 d Reflect in Origin Transformation a -1 b c d Line y = x Transformation a -1 b c d Line x = y Transformation a 1 b c d

11 Transformation Matrices Example
Reflect in X-Axis Transformation a -1 b c 1 d Original Co - Ordinates X 1 1 2 4 Y 1 3 4 2 (1,1) x = ax + by = -1*1 + 0*1 = = -1 y = cx + dy = 0*1 + 1*1 = = 1 (1,3) x = ax + by = -1*1 + 0*3 = = -1 y = cx + dy = 0*1 + 1*3 = = 3 (2,4) x = ax + by = -1*2 + 0*4 = = -2 y = cx + dy = 0*2 + 1*4 = = 4 Transformed Co - Ordinates X -1 -1 -2 -4 (4,2) x = ax + by = -1*4 + 0*1 = = -4 y = cx + dy = 0*4 + 1*2 = = 2 Y 1 3 4 2

12 Activity Transformation Matrices Transform this shape using the given transformation matrix. You must show your working out. Create a worksheet with 4 problems of your own. Show the answers to the questions with working on the reverse. Reflect in Y-Axis Transformation a 1 b c -1 d Original Co-Ordinates X Y Transformed Co-Ordinates X Y

13 Using Matrices to Solve Problems1
We can use matrices to work out simultaneous equations The equations need to be arrange in the format: <num1>X +/- <num2>Y = <num3> The numbers can then be represented as 2 x 2 and a 2 x 1 matrix Think of these two pairs of numbers 2x – 4 = 8y 5y + 2x = 10 Arrange them into the format <num1>X +/- <num2>Y = <num3> 2x – 8y = 4 2x + 5y = 10 This become in a matrix a 2 -8 b a X X = 4 * c 2 5 d c Y Y 10

14 Activity Rearranging Equations Expressing Simultaneous Equations as Matrices Practising rearranging these simultaneous equations into the format: <num1>X +/- <num2>Y = <num3> and then into a 2x2, 2x1 and answer matrix a b a = * c d c 2x + 13 = 5y b) 3x + 2y – 14 = 0 c) 5y -13 = 3x 3x + 4y - 15= 0 2x + 16 = 5y 2x + 3y – 4 = 0 d) x + 5y – 2 = 0 e) 4x + 3y + 10 = 0 f) 2x + 5y + 5 = 0 3y – 9 = 2x 5y – 18 = 2x 2y + 31 = 5x

15 Using Matrices to Solve Problems2
We now need to find out what X and Y, so using the rules of rearrangement we have to divide both sides by the matrix known To divide by a matrix we multiply by its inverse To invert a matrix we FIRST find the determinate using ad – bc, We then multiply the determinant by a modified matrix which has a and d swopped over and the signs changed of b and c a X c Y = 4 10 / a 2 -8 b c 5 d a 2 -8 b c 5 d a 5 8 b c -2 2 d original modified

16 Using Matrices to Solve Problems3
For division need to multiply by the determinate and the modified matrix a X c Y = 4 10 / a 2 -8 b c 5 d a X c Y = Determinate * Modified Matrix * Known Matrix a X c Y 1 26 a 5 8 b c -2 2 d 4 10 1 ad-bc = Determinate = * * 1 (2*5) - (-8*2) = 1 26 a X c Y (5*4) + (8*10) (-2*4) +(2*10) = * 1 26 = 1 26 a X c Y 100 12 = * a 5 8 b c -2 2 d Modified Matrix = a X c Y 3.8 0.46 = Modify the order of the multiplication so its easiest… 1/26 of 5?? No thanks Modified Matrix – a and d swopped, sign changed in b and c

17 Activity Using the method shown solve these equations
Solving Simultaneous Equations Using Matrices Using the method shown solve these equations 2x + 13 = 5y b) 3x + 2y – 14 = 0 c) 5y -13 = 3x 3x + 4y - 15= 0 2x + 16 = 5y 2x + 3y – 4 = 0 d) x + 5y – 2 = 0 e) 4x + 3y + 10 = 0 f) 2x + 5y + 5 = 0 3y – 9 = 2x 5y – 18 = 2x 2y + 31 = 5x Method Derive equations Rearrange equations Create matrices Calculate determinate Calculate modified matrix Carry out multiplication Check by substituting

18 Word Problem Example1 Taxi A charges £5 to get in and £1.50 a mile. Taxi B charges £3 to get in and £2 a mile. When does taxi A get cheaper than taxi B? TAXI A: COST = M TAXI B: COST = 3 + 2M Method Derive equations Rearrange equations Create matrices Calculate determinate Calculate modified matrix Carry out multiplication Check by substituting C = M C = 3 + 2M C M = 5 C – 2M = 3 a 1 -1.5 b a C C = 5 * c 1 -2 d c M M 3

19 / Word Problem Example2 =  1 -0.5 * * = 1 -0.5 * = 1 -0.5 * 1 -0.5 *
C c M = 5 3 / a 1 -1.5 b c -2 d a C c M = Determinate * Modified Matrix * Known Matrix 1 -0.5 a C c M a -2 1.5 b c -1 1 d 5 3 1 ad-bc = Determinate = * * 1 (1 * -2) - (-1.5*1) = 1 -0.5 a C c M (-2*5) + (1.5*3) (-1*5) +(1*3) = * 1 -0.5 = 1 -0.5 a C c M (-10) + (4.5) (-5) +(3) = * a -2 1.5 b c -1 1 d Modified Matrix = 1 -0.5 a C c M -5.5 -2 = * a C c M 11 4 =

20 Activity Using the method shown solve these problems
Solving Simultaneous Equations Using Matrices Using the method shown solve these problems 9 pens and five pencils cost £5, and 7 pens and 8 pencils cost £3. Find the unit price for each pen and pencil. Drayton manor is a popular school trip destination. This year 11 at School A and the year 11 at High School B both planned trips there. School A rented filled 8 vans and 8 buses with 240 students. School B rented and filled 4 vans and 1 bus with 54 students. Every van had the same number of students in it as did the buses. Find the number of students in each van and in each bus. A rugby club is selling tickets to one of its games. On the first day of ticket sales the school sold 3 senior citizen tickets and 1 child ticket for a total of £38. The school took in £52 on the second day by selling 3 senior citizen tickets and 2 child tickets. Find the price of a senior citizen ticket and the price of a child ticket. Mr J writes test to check the understanding of his BTEC learners. The test has 25 questions for a total score of 150 points. Among the 25 questions, each multiple choice questions carries 3 points and the descriptive type questions carries 8 points. How many multiple choice questions and descriptive type questions are there in the test?

21 Arrays As Matrices In computing arrays are stored as matrices, however the co-ordinates start a row 0 and col 0 rather than row 1 an col 1 so referencing is slightly different 1 dimension array 3 dimension array [0] 1 2 [0,1,0]th = 3 [1]th = 1 [1] 2 dimension array 1 2 [1,1,2]th = 7 1 2 [2] 1 2 [2,0,2]th = 2 [1,2]th = 5

22 Matrices in Memory There are two ways of storing Matrices in computer memory – row major order and column major order Within row major order matrices are stored in memory a row at a time, with the second row following the first Within column major order matrices are stored in memory a column at a time, with the second row following the first 4 E 2 7 ? A 3 4 E 2 7 ? A 2 3 4 E 2 7 ? A 3 4 7 E ? 2 2 A 3

23 Exam Question A computer system stores data in the matrices below.
The data is written to memory using colum-major order. Quantity is written to array a. Price is written to array b. Calculate the outcome of the formula Total = Quantity*Price using the data in locations a[7] and b[4] Show your working out.


Download ppt "BTEC NCF Dip in Comp - Unit 02 Fundamentals of Computer Systems Lesson 12 – Indices and Matrices Mr C Johnston."

Similar presentations


Ads by Google