# CS201-43 - Introduction to Programming Lecture # 43 Math...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Programming Lecture # 43 Math Library Complex number Matrix Quadratic equation and their solution …………….… To design a program properly, we must : – Analyze a problem statement, typically Design Recipe expressed as a word problem examples – Express its essence, abstractly and with – Formulate statements and comments in a precise language i.e. code – Evaluate and revise the activities in light – PAY ATTENTION TO DETAIL of checks and tests and 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 4 8 12 Three Rows Four Columns 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 -2 0 -4 2 0 -5 0 10 1 2 6 10 3 7 11 = 5 9 - 3 7 9 6 4 10 8 7 1 Cij = Aij - Bij 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) (5)(2)+(6)(1) (1)(4)+(2)(2) (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 – N rows – P columns – M rows Second matrix has Resultant matrix will have 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 A T 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 ...
View Full Document

## This note was uploaded on 01/12/2010 for the course CS CS 201 taught by Professor Dr.naveedmalik during the Spring '09 term at Virtual University of Pakistan.

Ask a homework question - tutors are online