Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Introduction to Programming Lecture # 43 Math Library Complex number Matrix Quadratic equation and their solution …………….… Design Recipe To design a program properly, we must : – Analyze a problem statement, typically expressed as a word problem – Express its essence, abstractly and with examples – Formulate statements and comments in a precise language i.e. code – Evaluate and revise the activities in light of checks and tests and – PAY ATTENTION TO DETAIL Matrix • Matrix is nothing but a two dimensional array of numbers • Normally, represented in the form of : • Rows • Columns Example A= 1 5 9 2 6 10 3 7 11 Three Rows Four Columns 4 8 12 i & j are two Integers i representing the Row number j representing the Column number Operations Performed with Matrix • Addition of two matrices. • Addition of a scalar and a matrix • Subtraction of two matrices • Subtraction of a scalar from a matrix • Multiplication of two matrices • Multiplication of a scalar with a matrix • Division of a scalar with a matrix • Transpose of a matrix Interface Addition of two Matrices Aij+ Bij = Cij Addition of two Matrices Size of two matrices must be same Number of rows and columns must be identical for the matrices to be addable Example -2 -4 -5 -2 2 0 0 0 10 = Cij = 1 2 3 5 6 7 9 10 11 Aij - - Bij 3 6 8 7 4 7 9 10 1 Adding a Scalar to the Matrix Ordinary number added to every element of the matrix Subtracting a Scalar from a Matrix Ordinary number subtracted from every element of the matrix Division of Matrix by a Scalar Divide every element of Matrix by a scalar number Example Let : X be a Scalar number A be a Matrix C ij = Aij X Multiplication of a scalar with a Matrix : Example Let : X is a Scalar number A is a Matrix X*A X * A ij = Cij Multiply two Matrices 1 5 2 6 * 2 1 4 2 = (1)(2)+(2)(1) (1)(4)+(2)(2) (5)(2)+(6)(1) (5)(4)+(6)(2) Rules Regarding Matrix Multiplication Number of columns of the 1st Matrix = Number of rows of the 2nd Matrix Rules regarding Matrix Multiplication First matrix has – M rows – N columns Second matrix has – N rows – P columns Resultant matrix will have – M rows – P columns Transpose of a Matrix Interchange of rows and columns Transpose of a Matrix Example 1 5 9 2 6 10 3 7 11 1 2 3 5 6 7 9 10 11 Transpose of a Non Square Matrix Size of matrix change after transpose A 3 ( Rows ) * 4 ( Columns ) Before T A 4 ( Rows ) * 3 ( Columns ) After Next Phase of Analysis • Determine the Constants • Memory Allocation • What is it’s user interface Interface Interface Constructor : Parameters are Number of rows Number of columns Display function Plus operator : member operator of the class Subtraction operator : member operator of the class Plus operator : friend of the class Subtraction operator : friend of the class Plus Operator A+X X+A Subtraction Operator A-X X–A Interface Multiplication Operator : Member of the Class Multiplication Operator : Friend of the Class Division Operator : Member of the Class Transpose Function : Member of the Class Assignment Operator : Member of the Class += , -= : Members of the Class Multiplication Operator A*X X*A Assignment Operator A=B ( Member Operator ) Interface >> Extraction Operator : Friend Operator << Stream Insertion Operator : Friend Operator Copy Constructor Copy Constructor Assignment Operator Memory Allocation Memory Deallocation