SlideShare a Scribd company logo
1 of 14
Course Material – SD, SB, PSK, NSN, DK, TAG – CS&E, IIT M 1
CS1100
Computational Engineering
Matrix Operations
Kamakoti V.
and
Jayalal Sarma M.N.
SD, PSK, NSN, DK, TAG – CS&E, IIT M 2
Multi-Dimensional Arrays
• Arrays with two or more dimensions can be
defined
0
1
2
3
0 1 2
A[4][3]
0 1 2 0 1 2
0
1
2
3
0 1
B[2][4][3]
SD, PSK, NSN, DK, TAG – CS&E, IIT M 3
Two Dimensional Arrays
• Declaration: int A[4][3] : 4 rows and
3 columns, 4×3 array
• Elements: A[i][j] - element in row i
and column j of array A
• Rows/columns numbered from 0
• Storage: row-major ordering
– elements of row 0, elements of row 1,
etc
• Initialization:
int B[2][3]={{4,5,6},{0,3,5}};
0
1
2
3
0 1 2
A[4][3]
SD, PSK, NSN, DK, TAG – CS&E, IIT M 4
Matrix Operations
• An m-by-n matrix M: m rows and n columns
• Rows: 1, 2, … , m and Columns: 1, 2, … , n
• M(i, j): element in ith
row, jth
col., 1≤i≤m, 1≤j≤n
• Array indexes in C language start with 0
• Use (m+1)×(n+1) array and ignore cells (0,i), (j,0)
• Programs can use natural convention – easier to
understand
• Functions: matRead(a,int,int), matWrite(a,int,int),
matAdd(a,b,c,int,int), matMult(a,b,c,int,int,int);
SD, PSK, NSN, DK, TAG – CS&E, IIT M 5
Using Matrix Operations
main( ){
int a[11][11], b[11][11], c[11][11]; /*max size: 10 by 10
*/
int aRows, aCols, bRows, bCols, cRows, cCols;
scanf("%d%d", &aRows, &aCols);
matRead(a, aRows, aCols);
scanf("%d%d", &bRows, &bCols);
matRead(b, bRows, bCols);
matMult(a, b, c, aRows, aCols, bCols);
cRows = aRows; cCols = bCols;
matWrite(c, cRows, cCols);
Remember
bRows=aCols
Address of the (0,0)
element of the array
SD, PSK, NSN, DK, TAG – CS&E, IIT M 6
Reading and Writing a Matrix
void matRead(int mat[ ][11], int rows, int cols){
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= cols; j++)
scanf("%d", &mat[i][j]);
}
void matWrite(int mat[ ][11], int rows, int cols){
for (int i = 1; i <= rows; i++){
for (int j = 1; j <= cols; j++) /* print a row */
printf ("%d ", mat[i][j]); /* notice missing n */
printf ("n"); /* print a newline at the end a row
*/
}
}
For the compiler to figure
out the address of mat[i][j],
the first dimension value is
not necessary. (Why?)
SD, PSK, NSN, DK, TAG – CS&E, IIT M 7
Matrix Multiplication
Multiply two numbers
Sum of N products
N
N
SD, PSK, NSN, DK, TAG – CS&E, IIT M 8
Matrix Multiplication
void matMult(int mat1[ ][11], int mat2[ ][11],
int mat3[ ][11], int m, int n, int p){
for (int i =1; i <= m; i++)
for (int j = 1; j <= p; j++)
for (int k = 1; k <= n; k++)
mat3[i][j] += mat1[i][k]*mat2[k][j];
} Remember it was initialized to zero in the
main program. It could have been done in
this function as well – probably a better idea.
SD, PSK, NSN, DK, TAG – CS&E, IIT M 9
scanf and getchar
• getchar( ) reads and returns one character
• scanf – formatted input, stores in variable
– scanf returns an integer = number of inputs it
managed to convert successfully
printf ("Input 2 numbers: ");
if (scanf ("%d%d", &i, &j) == 2)
printf ("You entered %d and %dn", i, j);
else printf ("You failed to enter two
numbersn");
from <http://cprogramming.com>
SD, PSK, NSN, DK, TAG – CS&E, IIT M 10
Input Buffer
• Your input line is first stored in a buffer
• If you are reading a number with scanf (%d) and
enter 1235ZZZ, scanf will read 1235 into the
variable and leave ZZZ in the buffer
• The next read statement will get ZZZ and may
ignore the actual input!
• One may need to write a statement to clear the
buffer…
while (getchar( ) != 'n');
This reads and ignores input till the end of line
SD, PSK, NSN, DK, TAG – CS&E, IIT M 11
Program to Insist on One Number Only
#include <stdio.h>
int main(void){
int temp;
printf ("Input your number: ");
while (scanf("%d", &temp) != 1)
{
while (getchar( ) != 'n');
printf ("Try again: ");
}
printf ("You entered %dn", temp);
return(0);
}
exit if one
number
clear buffer before
reading again
SD, PSK, NSN, DK, TAG – CS&E, IIT M 12
Experiments with Numbers
• The Collatz problem asks if iterating
always returns to 1 for positive α. The members
of the sequence produced by the Collatz problem
are sometimes known as hailstone numbers.
From Wolfram Mathworld
http://mathworld.wolfram.com/CollatzProblem.html
3αn-1 + 1 for αn-1 odd
½ αn-1 for αn-1 even
αn =
SD, PSK, NSN, DK, TAG – CS&E, IIT M 13
Hailstone Numbers
• A Hailstone Sequence is generated by a simple
algorithm:
Start with an integer N. If N is even, the next
number in the sequence is N/2. If N is odd, the
next number in the sequence is (3*N)+1
• 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2,
1, 4, 2, 1, ... repeats
• 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1 ….
• 909, 2726, 1364, 682, 341, 1024, 512, 256, 128, 64,
32, 16, 8, 4, 2, 1, 4, 2, 1… 210
SD, PSK, NSN, DK, TAG – CS&E, IIT M 14
Mathematical Recreations
http://users.swing.be/TGMSoft/hailstone.htm
Exercise : Write a program to accept an input and count the number of
iterations needed to get to 1, and the highest number reached. Generate a table
of results…

More Related Content

What's hot (20)

2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
 
Arrays
ArraysArrays
Arrays
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
SORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix SortSORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix Sort
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Implementation
ImplementationImplementation
Implementation
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And Enums
 
Matlab Graphics Tutorial
Matlab Graphics TutorialMatlab Graphics Tutorial
Matlab Graphics Tutorial
 
Csci101 lect01 first_program
Csci101 lect01 first_programCsci101 lect01 first_program
Csci101 lect01 first_program
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dags
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Unit 2
Unit 2Unit 2
Unit 2
 
Nikit
NikitNikit
Nikit
 
Radix sorting
Radix sortingRadix sorting
Radix sorting
 
Network security CS6
Network security   CS6Network security   CS6
Network security CS6
 
Unit 5
Unit 5Unit 5
Unit 5
 

Viewers also liked

Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringSri Harsha Pamu
 
3G And Other Telecom-Tech Training
3G And Other Telecom-Tech Training3G And Other Telecom-Tech Training
3G And Other Telecom-Tech TrainingAmrit Chhetri
 
Training material for vms nsn project rev 0.2 20110906
Training material for vms nsn project rev 0.2 20110906Training material for vms nsn project rev 0.2 20110906
Training material for vms nsn project rev 0.2 20110906Hieu Tran
 
Bhel telecom ppt
Bhel telecom pptBhel telecom ppt
Bhel telecom pptRANAPRAVESH
 
BHEL TRAINING REPORT IN TELECOMMUNICATION
BHEL TRAINING REPORT IN TELECOMMUNICATIONBHEL TRAINING REPORT IN TELECOMMUNICATION
BHEL TRAINING REPORT IN TELECOMMUNICATIONgy_manish
 
Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )
Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )
Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )Anuj Singh
 
Summer training from BSNL
Summer training from BSNLSummer training from BSNL
Summer training from BSNLNitish Tanwar
 
BHEL SUMMER TRAINING REPORT
BHEL SUMMER TRAINING REPORTBHEL SUMMER TRAINING REPORT
BHEL SUMMER TRAINING REPORTBhupendra Shukla
 
New final bsnl training report
New final bsnl training report New final bsnl training report
New final bsnl training report manish katara
 
Telecommunication basics
Telecommunication basicsTelecommunication basics
Telecommunication basicsYoohyun Kim
 
telecommunication-ppt
telecommunication-ppttelecommunication-ppt
telecommunication-pptsecomps
 
Tracxn Research — Telecom Infrastructure Landscape, December 2016
Tracxn Research — Telecom Infrastructure Landscape, December 2016Tracxn Research — Telecom Infrastructure Landscape, December 2016
Tracxn Research — Telecom Infrastructure Landscape, December 2016Tracxn
 

Viewers also liked (20)

Gsm optimization
Gsm optimizationGsm optimization
Gsm optimization
 
Bhel EC
Bhel EC Bhel EC
Bhel EC
 
Hoa Ke
Hoa KeHoa Ke
Hoa Ke
 
04 01 dpr 2700 rectifier introduction rev04
04 01 dpr 2700 rectifier introduction rev0404 01 dpr 2700 rectifier introduction rev04
04 01 dpr 2700 rectifier introduction rev04
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
 
3G And Other Telecom-Tech Training
3G And Other Telecom-Tech Training3G And Other Telecom-Tech Training
3G And Other Telecom-Tech Training
 
Training material for vms nsn project rev 0.2 20110906
Training material for vms nsn project rev 0.2 20110906Training material for vms nsn project rev 0.2 20110906
Training material for vms nsn project rev 0.2 20110906
 
Bhel telecom ppt
Bhel telecom pptBhel telecom ppt
Bhel telecom ppt
 
Bao cao. Cam bien vi tri va cam bien dich chuyen
Bao cao. Cam bien vi tri va cam bien dich chuyenBao cao. Cam bien vi tri va cam bien dich chuyen
Bao cao. Cam bien vi tri va cam bien dich chuyen
 
BHEL TRAINING REPORT IN TELECOMMUNICATION
BHEL TRAINING REPORT IN TELECOMMUNICATIONBHEL TRAINING REPORT IN TELECOMMUNICATION
BHEL TRAINING REPORT IN TELECOMMUNICATION
 
Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )
Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )
Project working capital management at bhel jhansi unit from Anuj ( BU Jhansi )
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Telecom ppt
Telecom pptTelecom ppt
Telecom ppt
 
Summer training from BSNL
Summer training from BSNLSummer training from BSNL
Summer training from BSNL
 
BHEL SUMMER TRAINING REPORT
BHEL SUMMER TRAINING REPORTBHEL SUMMER TRAINING REPORT
BHEL SUMMER TRAINING REPORT
 
New final bsnl training report
New final bsnl training report New final bsnl training report
New final bsnl training report
 
Telecom ppt
Telecom pptTelecom ppt
Telecom ppt
 
Telecommunication basics
Telecommunication basicsTelecommunication basics
Telecommunication basics
 
telecommunication-ppt
telecommunication-ppttelecommunication-ppt
telecommunication-ppt
 
Tracxn Research — Telecom Infrastructure Landscape, December 2016
Tracxn Research — Telecom Infrastructure Landscape, December 2016Tracxn Research — Telecom Infrastructure Landscape, December 2016
Tracxn Research — Telecom Infrastructure Landscape, December 2016
 

Similar to Week7

C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxrohinitalekar1
 
Abir ppt3
Abir ppt3Abir ppt3
Abir ppt3abir96
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...AntareepMajumder
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN Cnaveed jamali
 
Data Structure_Array_and_sparse matrix.pptx
Data Structure_Array_and_sparse matrix.pptxData Structure_Array_and_sparse matrix.pptx
Data Structure_Array_and_sparse matrix.pptxpubgnewstate1620
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...nsitlokeshjain
 

Similar to Week7 (20)

C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
L5 array
L5 arrayL5 array
L5 array
 
R
RR
R
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Abir ppt3
Abir ppt3Abir ppt3
Abir ppt3
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Arrays 06.ppt
Arrays 06.pptArrays 06.ppt
Arrays 06.ppt
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Matlab1
Matlab1Matlab1
Matlab1
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
Data Structure_Array_and_sparse matrix.pptx
Data Structure_Array_and_sparse matrix.pptxData Structure_Array_and_sparse matrix.pptx
Data Structure_Array_and_sparse matrix.pptx
 
4.ArraysInC.pdf
4.ArraysInC.pdf4.ArraysInC.pdf
4.ArraysInC.pdf
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
 
1st lecture.ppt
1st lecture.ppt1st lecture.ppt
1st lecture.ppt
 
arrays
arraysarrays
arrays
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 

Week7

  • 1. Course Material – SD, SB, PSK, NSN, DK, TAG – CS&E, IIT M 1 CS1100 Computational Engineering Matrix Operations Kamakoti V. and Jayalal Sarma M.N.
  • 2. SD, PSK, NSN, DK, TAG – CS&E, IIT M 2 Multi-Dimensional Arrays • Arrays with two or more dimensions can be defined 0 1 2 3 0 1 2 A[4][3] 0 1 2 0 1 2 0 1 2 3 0 1 B[2][4][3]
  • 3. SD, PSK, NSN, DK, TAG – CS&E, IIT M 3 Two Dimensional Arrays • Declaration: int A[4][3] : 4 rows and 3 columns, 4×3 array • Elements: A[i][j] - element in row i and column j of array A • Rows/columns numbered from 0 • Storage: row-major ordering – elements of row 0, elements of row 1, etc • Initialization: int B[2][3]={{4,5,6},{0,3,5}}; 0 1 2 3 0 1 2 A[4][3]
  • 4. SD, PSK, NSN, DK, TAG – CS&E, IIT M 4 Matrix Operations • An m-by-n matrix M: m rows and n columns • Rows: 1, 2, … , m and Columns: 1, 2, … , n • M(i, j): element in ith row, jth col., 1≤i≤m, 1≤j≤n • Array indexes in C language start with 0 • Use (m+1)×(n+1) array and ignore cells (0,i), (j,0) • Programs can use natural convention – easier to understand • Functions: matRead(a,int,int), matWrite(a,int,int), matAdd(a,b,c,int,int), matMult(a,b,c,int,int,int);
  • 5. SD, PSK, NSN, DK, TAG – CS&E, IIT M 5 Using Matrix Operations main( ){ int a[11][11], b[11][11], c[11][11]; /*max size: 10 by 10 */ int aRows, aCols, bRows, bCols, cRows, cCols; scanf("%d%d", &aRows, &aCols); matRead(a, aRows, aCols); scanf("%d%d", &bRows, &bCols); matRead(b, bRows, bCols); matMult(a, b, c, aRows, aCols, bCols); cRows = aRows; cCols = bCols; matWrite(c, cRows, cCols); Remember bRows=aCols Address of the (0,0) element of the array
  • 6. SD, PSK, NSN, DK, TAG – CS&E, IIT M 6 Reading and Writing a Matrix void matRead(int mat[ ][11], int rows, int cols){ for (int i = 1; i <= rows; i++) for (int j = 1; j <= cols; j++) scanf("%d", &mat[i][j]); } void matWrite(int mat[ ][11], int rows, int cols){ for (int i = 1; i <= rows; i++){ for (int j = 1; j <= cols; j++) /* print a row */ printf ("%d ", mat[i][j]); /* notice missing n */ printf ("n"); /* print a newline at the end a row */ } } For the compiler to figure out the address of mat[i][j], the first dimension value is not necessary. (Why?)
  • 7. SD, PSK, NSN, DK, TAG – CS&E, IIT M 7 Matrix Multiplication Multiply two numbers Sum of N products N N
  • 8. SD, PSK, NSN, DK, TAG – CS&E, IIT M 8 Matrix Multiplication void matMult(int mat1[ ][11], int mat2[ ][11], int mat3[ ][11], int m, int n, int p){ for (int i =1; i <= m; i++) for (int j = 1; j <= p; j++) for (int k = 1; k <= n; k++) mat3[i][j] += mat1[i][k]*mat2[k][j]; } Remember it was initialized to zero in the main program. It could have been done in this function as well – probably a better idea.
  • 9. SD, PSK, NSN, DK, TAG – CS&E, IIT M 9 scanf and getchar • getchar( ) reads and returns one character • scanf – formatted input, stores in variable – scanf returns an integer = number of inputs it managed to convert successfully printf ("Input 2 numbers: "); if (scanf ("%d%d", &i, &j) == 2) printf ("You entered %d and %dn", i, j); else printf ("You failed to enter two numbersn"); from <http://cprogramming.com>
  • 10. SD, PSK, NSN, DK, TAG – CS&E, IIT M 10 Input Buffer • Your input line is first stored in a buffer • If you are reading a number with scanf (%d) and enter 1235ZZZ, scanf will read 1235 into the variable and leave ZZZ in the buffer • The next read statement will get ZZZ and may ignore the actual input! • One may need to write a statement to clear the buffer… while (getchar( ) != 'n'); This reads and ignores input till the end of line
  • 11. SD, PSK, NSN, DK, TAG – CS&E, IIT M 11 Program to Insist on One Number Only #include <stdio.h> int main(void){ int temp; printf ("Input your number: "); while (scanf("%d", &temp) != 1) { while (getchar( ) != 'n'); printf ("Try again: "); } printf ("You entered %dn", temp); return(0); } exit if one number clear buffer before reading again
  • 12. SD, PSK, NSN, DK, TAG – CS&E, IIT M 12 Experiments with Numbers • The Collatz problem asks if iterating always returns to 1 for positive α. The members of the sequence produced by the Collatz problem are sometimes known as hailstone numbers. From Wolfram Mathworld http://mathworld.wolfram.com/CollatzProblem.html 3αn-1 + 1 for αn-1 odd ½ αn-1 for αn-1 even αn =
  • 13. SD, PSK, NSN, DK, TAG – CS&E, IIT M 13 Hailstone Numbers • A Hailstone Sequence is generated by a simple algorithm: Start with an integer N. If N is even, the next number in the sequence is N/2. If N is odd, the next number in the sequence is (3*N)+1 • 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, ... repeats • 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1 …. • 909, 2726, 1364, 682, 341, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 4, 2, 1… 210
  • 14. SD, PSK, NSN, DK, TAG – CS&E, IIT M 14 Mathematical Recreations http://users.swing.be/TGMSoft/hailstone.htm Exercise : Write a program to accept an input and count the number of iterations needed to get to 1, and the highest number reached. Generate a table of results…