0% found this document useful (0 votes)
56 views34 pages

CS201 43

The document discusses matrices and their operations. It defines a matrix as a two-dimensional array and covers topics such as addition, subtraction, multiplication, and transposition of matrices. It also discusses designing a class interface for matrices, including constructor, display function, operator overloading for operations like addition and multiplication, and other functions like copy constructor and destructor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views34 pages

CS201 43

The document discusses matrices and their operations. It defines a matrix as a two-dimensional array and covers topics such as addition, subtraction, multiplication, and transposition of matrices. It also discusses designing a class interface for matrices, including constructor, display function, operator overloading for operations like addition and multiplication, and other functions like copy constructor and destructor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

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
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

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
1 2 3 3 6 8
-2 -4 -5
-2 2 0
= 5 6 7 - 7 4 7
0 0 10
9 10 11 9 10 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 = 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

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 2 3 1 5 9
5 6 7 2 6 10
9 10 11 3 7 11
Transpose of a Non
Square Matrix

Size of matrix change after transpose

A A
T

3 ( Rows ) * 4 ( Columns ) 4 ( Rows ) * 3 ( Columns )


Before 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

You might also like