CS201 43
CS201 43
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
1 2 3 4
A= 5 6 7 8
9 10 11 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
C = Aij
ij
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)(2)+(2)(1) (1)(4)+(2)(2)
2 4
1
5
2
6 * 1 2 = (5)(2)+(6)(1) (5)(4)+(6)(2)
Rules Regarding
Matrix Multiplication
Interchange of rows
and columns
Transpose of a Matrix
Example
1 2 3 1 5 9
5 6 7 2 6 10
9 10 11 3 7 11
Transpose of a Non
Square Matrix
A A
T
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
Memory Allocation
Memory Deallocation