cs201- introduction to programming- lecture 43
DESCRIPTION
Virtual University Course CS201- Introduction to Programming Lecture No 43 Instructor's Name: Dr. Naveed A. Malik Course Email: [email protected]TRANSCRIPT
![Page 1: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/1.jpg)
Introduction to Introduction to ProgrammingProgramming
Lecture # 43Lecture # 43
![Page 2: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/2.jpg)
Math Library
Complex number Matrix Quadratic equation and their solution
…………….…
![Page 3: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/3.jpg)
Design RecipeDesign Recipe To design a program properly, we must :To design a program properly, we must :
– Analyze a problem statement, typicallyAnalyze a problem statement, typically expressed as a word problemexpressed as a word problem– Express its essence, abstractly and with Express its essence, abstractly and with examplesexamples– Formulate statements and comments in a Formulate statements and comments in a precise language i.e. codeprecise language i.e. code– Evaluate and revise the activities in light Evaluate and revise the activities in light
of checks and tests andof checks and tests and– PAY ATTENTION TO DETAILPAY ATTENTION TO DETAIL
![Page 4: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/4.jpg)
Matrix• Matrix is nothing but a two dimensional array of numbers• Normally, represented in the form of :
• Rows• Columns
![Page 5: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/5.jpg)
Example1 2 3 4
5 6 7 8 9 10 11 12
A =
Three RowsFour Columns
![Page 6: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/6.jpg)
i & j are two Integers
i representing the Row numberj representing the Column number
![Page 7: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/7.jpg)
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
![Page 8: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/8.jpg)
Interface
![Page 9: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/9.jpg)
Addition of two Matrices
Aij+Bij Cij=
![Page 10: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/10.jpg)
Size of two matrices must be same
Number of rows and columns must be identical for the matrices to be addable
Addition of two Matrices
![Page 11: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/11.jpg)
Example1 2 3
5 6 7
9 10 11
-3 6 8
7 4 7
9 10 1
=-2 -4 -5
-2 2 0
0 0 10
Aij - BijCij =
![Page 12: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/12.jpg)
Ordinary number added to every element of the matrix
Adding a Scalar to the Matrix
![Page 13: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/13.jpg)
Ordinary number subtracted from every element of the matrix
Subtracting a Scalar from a Matrix
![Page 14: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/14.jpg)
Divide every element of Matrix by a scalar number
Division of Matrix by a Scalar
![Page 15: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/15.jpg)
Example
Let :X be a Scalar numberA be a Matrix
AijCij
=
X
![Page 16: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/16.jpg)
Multiplication of a scalar with a Matrix :
ExampleLet :
X is a Scalar numberA is a Matrix
A ij Cij=X *
X * A
![Page 17: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/17.jpg)
Multiply two Matrices
1 25 6 =*
2 41 2
( 1 ) ( 2 ) + ( 2 ) ( 1 ) ( 1 ) ( 4 ) + ( 2 ) ( 2 )
( 5 ) ( 2 ) + ( 6 ) ( 1 ) ( 5 ) ( 4 ) + ( 6 ) ( 2 )
![Page 18: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/18.jpg)
Number of columns of the 1st Matrix =Number of rows of the 2nd Matrix
Rules Regarding Matrix Multiplication
![Page 19: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/19.jpg)
Rules regarding Matrix Rules regarding Matrix MultiplicationMultiplication
First matrix hasFirst matrix has– M rowsM rows– N columnsN columns
Second matrix has Second matrix has – N rowsN rows– P columnsP columns
Resultant matrix will haveResultant matrix will have– M rowsM rows– P columnsP columns
![Page 20: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/20.jpg)
Transpose of a Matrix
Interchange of rows and columns
![Page 21: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/21.jpg)
Transpose of a MatrixExample
1 2 3 5 6 7 9 10 11
1 5 9 2 6 10 3 7 11
![Page 22: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/22.jpg)
Transpose of a Non Square Matrix
A AT
3 ( Rows ) * 4 ( Columns ) Before
4 ( Rows ) * 3 ( Columns ) After
Size of matrix change after transpose
![Page 23: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/23.jpg)
Next Phase of Analysis
• Determine the Constants• Memory Allocation• What is it’s user interface
![Page 24: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/24.jpg)
Interface
![Page 25: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/25.jpg)
InterfaceInterfaceConstructor : Parameters are Constructor : Parameters are
Number of rows Number of rows Number of columns Number of columns
Display functionDisplay functionPlus operator : member operator of the class Plus operator : member operator of the class Subtraction operator : member operator of the Subtraction operator : member operator of the class class Plus operator : friend of the class Plus operator : friend of the class Subtraction operator : friend of the class Subtraction operator : friend of the class
![Page 26: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/26.jpg)
Plus Operator
A + X
X + A
![Page 27: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/27.jpg)
Subtraction Operator
A - X
X – A
![Page 28: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/28.jpg)
*
![Page 29: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/29.jpg)
Interface Interface
Multiplication Operator : Member of the Class Multiplication Operator : Member of the Class
Multiplication Operator : Friend of the Class Multiplication Operator : Friend of the Class
Division Operator : Member of the ClassDivision Operator : Member of the Class
Transpose Function : Member of the ClassTranspose Function : Member of the Class
Assignment Operator : Member of the ClassAssignment Operator : Member of the Class
+= , -= : Members of the Class += , -= : Members of the Class
![Page 30: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/30.jpg)
Multiplication Operator
A * X
X * A
![Page 31: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/31.jpg)
Assignment Operator
A = B( Member Operator )
![Page 32: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/32.jpg)
>> Extraction Operator : Friend Operator
<< Stream Insertion Operator : Friend Operator
Interface
![Page 33: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/33.jpg)
Copy Constructor
![Page 34: CS201- Introduction to Programming- Lecture 43](https://reader035.vdocuments.site/reader035/viewer/2022070303/5492e73bb47959834a8b4670/html5/thumbnails/34.jpg)
Copy ConstructorCopy Constructor Assignment OperatorAssignment Operator Memory AllocationMemory Allocation Memory DeallocationMemory Deallocation