SlideShare a Scribd company logo
This document is intended for internal use only and shall not be distributed outside of GUtech in Oman
Numerical Methods for Engineers and Scientists
Lecturer: Assistant Prof. Dr. AYDIN AZIZI
Slide 2
Copyright © 2014 John Wiley & Sons, Inc. All rights reserved.
Third Edition
Amos Gilat • Vish Subramaniam
Numerical Methods
for
Engineers and Scientists
Slide 3
Lecturer: Assistant Prof. Dr. Aydin Azizi
Introduction to MATLAB
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 4
Lecturer: Assistant Prof. Dr. Aydin Azizi
Example of MATLAB Release 13 desktop
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 5
Lecturer: Assistant Prof. Dr. Aydin Azizi
Variables
– Vectors and Matrices –
• ALL variables are matrices
Variables
•They are case–sensitive i.e. x  X
•Their names can contain up to 31 characters
•Must start with a letter
•Variables are stored in workspace
e.g. 1 x 1 4 x 1 1 x 4 2 x 4






4239
6512 7123












3
9
2
3
 4
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 6
Lecturer: Assistant Prof. Dr. Aydin Azizi
How do we assign a value to a variable?
>>> v1=3
v1 =
3
>>> i1=4
i1 =
4
>>> R=v1/i1
R =
0.7500
>>>
>>> whos
Name Size Bytes Class
R 1x1 8 double array
i1 1x1 8 double array
v1 1x1 8 double array
Grand total is 3 elements using 24 bytes
>>> who
Your variables are:
R i1 v1
>>>
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 7
Lecturer: Assistant Prof. Dr. Aydin Azizi
How do we assign values to vectors?
>>> A = [1 2 3 4 5]
A =
1 2 3 4 5
>>>
>>> B = [10;12;14;16;18]
B =
10
12
14
16
18
>>>
A row vector values
are separated by
spaces
 54321A 

















18
16
14
12
10
B
A column vector
values are
separated by
semi–colon (;)
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 8
Lecturer: Assistant Prof. Dr. Aydin Azizi
How do we assign values to vectors?
• If we want to construct a vector of, say, 100 elements between 0 and 2 – linspace
>>> c1 = linspace(0,(2*pi),100);
>>> whos
Name Size Bytes Class
c1 1x100 800 double array
Grand total is 100 elements using 800 bytes
>>>
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 9
Lecturer: Assistant Prof. Dr. Aydin Azizi
How do we assign values to vectors?
If we want to construct an array of, say, 100 elements between 0 and 2
– colon notation
>>> c2 = (0:0.0201:2)*pi;
>>> whos
Name Size Bytes Class
c1 1x100 800 double array
c2 1x100 800 double array
Grand total is 200 elements using 1600 bytes
>>>
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 10
Lecturer: Assistant Prof. Dr. Aydin Azizi
How do we assign values to matrices ?
Columns separated by
space or a comma
Rows separated by
semi-colon
>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>>










987
654
321
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 11
Lecturer: Assistant Prof. Dr. Aydin Azizi
How do we access elements in a matrix or a vector?
>>> A(2,3)
ans =
6
>>> A(:,3)
ans =
3
6
9
>>> A(1,:)
ans =
1 2 3
>>> A(2,:)
ans =
4 5 6
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 12
Lecturer: Assistant Prof. Dr. Aydin Azizi
Some special variables
pi ()
inf (e.g. 1/0)
i, j ( )1
>>> 1/0
Warning: Divide by zero.
ans =
Inf
>>> pi
ans =
3.1416
>>> i
ans =
0+ 1.0000i
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 13
Lecturer: Assistant Prof. Dr. Aydin Azizi
Arithmetic operations – Matrices
Performing operations to every entry in a matrix
Add and subtract>>> A=[1 2 3;4 5 6;7 8
9]
A =
1 2 3
4 5 6
7 8 9
>>>
>>> A+3
ans =
4 5 6
7 8 9
10 11 12
>>> A-2
ans =
-1 0 1
2 3 4
5 6 7
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 14
Lecturer: Assistant Prof. Dr. Aydin Azizi
Arithmetic operations – Matrices
Performing operations to every entry in a matrix
Multiply and divide>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>>
>>> A*2
ans =
2 4 6
8 10 12
14 16 18
>>> A/3
ans =
0.3333 0.6667 1.0000
1.3333 1.6667 2.0000
2.3333 2.6667 3.0000
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 15
Lecturer: Assistant Prof. Dr. Aydin Azizi
Arithmetic operations – Matrices
Performing operations to every entry in a matrix
Power
>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>>
A^2 = A * A
To square every element in A, use
the element–wise operator .^
>>> A.^2
ans =
1 4 9
16 25 36
49 64 81
>>> A^2
ans =
30 36 42
66 81 96
102 126 150
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 16
Lecturer: Assistant Prof. Dr. Aydin Azizi
Performing operations between matrices
>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>> B=[1 1 1;2 2 2;3 3 3]
B =
1 1 1
2 2 2
3 3 3
A*B 



















333
222
111
987
654
321
A.*B










3x93x83x7
2x62x52x4
1x31x21x1










272421
12108
321
=
=










505050
323232
141414
Arithmetic operations – Matrices
Lecturer: Assistant Prof. Dr. Aydin Azizi
Slide 17
Lecturer: Assistant Prof. Dr. Aydin Azizi
Roots- Logarithms
Slide 18
Lecturer: Assistant Prof. Dr. Aydin Azizi
Random Number
Slide 19
Lecturer: Assistant Prof. Dr. Aydin Azizi
Random Real Number
Slide 20
Lecturer: Assistant Prof. Dr. Aydin Azizi
Random Integer Number
Slide 21
Lecturer: Assistant Prof. Dr. Aydin Azizi
Practice
Slide 22
Lecturer: Assistant Prof. Dr. Aydin Azizi
Characters and Encoding
Slide 23
Lecturer: Assistant Prof. Dr. Aydin Azizi
Characters and Encoding
Slide 24
Lecturer: Assistant Prof. Dr. Aydin Azizi
Characters and Encoding
Slide 25
Lecturer: Assistant Prof. Dr. Aydin Azizi
Practice
Slide 26
Lecturer: Assistant Prof. Dr. Aydin Azizi
Relational Expressions
Slide 27
Lecturer: Assistant Prof. Dr. Aydin Azizi
Relational Expressions
Slide 28
Lecturer: Assistant Prof. Dr. Aydin Azizi
Relational Expressions
Slide 29
Lecturer: Assistant Prof. Dr. Aydin Azizi
Logical Operators
Slide 30
Lecturer: Assistant Prof. Dr. Aydin Azizi
Logical Operators
Slide 31
Lecturer: Assistant Prof. Dr. Aydin Azizi
Logical Operators
Slide 32
Lecturer: Assistant Prof. Dr. Aydin Azizi
Truth Table for Logical Operators
Slide 33
Lecturer: Assistant Prof. Dr. Aydin Azizi
Logical Error
Slide 34
Lecturer: Assistant Prof. Dr. Aydin Azizi
Logical Error
Slide 35
Lecturer: Assistant Prof. Dr. Aydin Azizi
Practice
Slide 36
Lecturer: Assistant Prof. Dr. Aydin Azizi
While Loop
count = 0;
number = 8;
while number > 3
number = number - 2
count = count+1
end
Slide 37
Lecturer: Assistant Prof. Dr. Aydin Azizi
FOR Loop
mat=rand(5,6)
[r c] = size(mat)
for i = 1:r
for j = 1:c
mat(i,j) = mat(i,j) * 2
end
end
Slide 38
Lecturer: Assistant Prof. Dr. Aydin Azizi
IF Loop
x=rand(10,1);
v = [ ]
for i = 1:length(x)
if x(i) > 0
v = [v i]
end
end

More Related Content

PPTX
Numerical Methods for Engineers and Scientists: An Introduction with Applicat...
PPTX
Absolute value
PPTX
October 17, 2014
PPT
October 1 Identity And Inverse Continued Recording
PDF
Algebra 2 Section 2-4
PPTX
Algebra tiles and equations 022614 altered
PDF
8th pre alg -l73
PDF
7th pre alg -l73
Numerical Methods for Engineers and Scientists: An Introduction with Applicat...
Absolute value
October 17, 2014
October 1 Identity And Inverse Continued Recording
Algebra 2 Section 2-4
Algebra tiles and equations 022614 altered
8th pre alg -l73
7th pre alg -l73

Viewers also liked (20)

PDF
СПЕЦПРОЕКТ ММСО-2017. ФОРУМ «Негосударственное дополнительное образование»
DOCX
Computer applications lab manual
PDF
Pmi servizio uc
DOCX
додаток 5. універсали (2)
PDF
PPTX
Conceptos basicos de probabilidad
PPS
Amazing likeness
PDF
Programa curricular-educacion-inicial
PPTX
Edición de videos
PPTX
Presentación biología 1
PPTX
Munu barnabörnin mín tala íslensku
PPTX
Di gennaro díaz_duran_presentaciónfinal
PDF
4 matriz 7º a
PPT
PDF
Blog Ethika Global: "¿Conseguirá el EURUSD llegar a la paridad? (Melchor Arme...
PPTX
Question 3
PDF
Estado da arte em Codificação Criativa
PPTX
El negocio del SEO y cómo hacer que Google quiera tu web
PPTX
Pleura and pleural cavity copy
PDF
Towards Streamlined Technology-driven orchestration for Effective Teaching
СПЕЦПРОЕКТ ММСО-2017. ФОРУМ «Негосударственное дополнительное образование»
Computer applications lab manual
Pmi servizio uc
додаток 5. універсали (2)
Conceptos basicos de probabilidad
Amazing likeness
Programa curricular-educacion-inicial
Edición de videos
Presentación biología 1
Munu barnabörnin mín tala íslensku
Di gennaro díaz_duran_presentaciónfinal
4 matriz 7º a
Blog Ethika Global: "¿Conseguirá el EURUSD llegar a la paridad? (Melchor Arme...
Question 3
Estado da arte em Codificação Criativa
El negocio del SEO y cómo hacer que Google quiera tu web
Pleura and pleural cavity copy
Towards Streamlined Technology-driven orchestration for Effective Teaching
Ad

Similar to Numerical Methods for Engineers and Scientists: An Introduction with Applications Using MATLAB (9)

PDF
Lecture#2,ch 02
PDF
Module I CSAS_105152.pdf
PDF
REvit training
PPT
Chapter 15 - Methods and Applications of Integration
PPT
Introductory maths analysis chapter 15 official
PPT
Chapter15 methodsandapplicationsofintegration-151007044206-lva1-app6891
PDF
Lecture#4,ch 02
PDF
refreshENM1500.pdf
PPTX
Play School Mini project of BTECH Civil.pptx
Lecture#2,ch 02
Module I CSAS_105152.pdf
REvit training
Chapter 15 - Methods and Applications of Integration
Introductory maths analysis chapter 15 official
Chapter15 methodsandapplicationsofintegration-151007044206-lva1-app6891
Lecture#4,ch 02
refreshENM1500.pdf
Play School Mini project of BTECH Civil.pptx
Ad

Recently uploaded (20)

PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
communication and presentation skills 01
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PPT
Occupational Health and Safety Management System
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
Soil Improvement Techniques Note - Rabbi
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Module 8- Technological and Communication Skills.pptx
PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
Software Engineering and software moduleing
PPTX
Artificial Intelligence
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Management Information system : MIS-e-Business Systems.pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
distributed database system" (DDBS) is often used to refer to both the distri...
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
communication and presentation skills 01
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Occupational Health and Safety Management System
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Soil Improvement Techniques Note - Rabbi
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Module 8- Technological and Communication Skills.pptx
Information Storage and Retrieval Techniques Unit III
Software Engineering and software moduleing
Artificial Intelligence

Numerical Methods for Engineers and Scientists: An Introduction with Applications Using MATLAB

  • 1. This document is intended for internal use only and shall not be distributed outside of GUtech in Oman Numerical Methods for Engineers and Scientists Lecturer: Assistant Prof. Dr. AYDIN AZIZI
  • 2. Slide 2 Copyright © 2014 John Wiley & Sons, Inc. All rights reserved. Third Edition Amos Gilat • Vish Subramaniam Numerical Methods for Engineers and Scientists
  • 3. Slide 3 Lecturer: Assistant Prof. Dr. Aydin Azizi Introduction to MATLAB Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 4. Slide 4 Lecturer: Assistant Prof. Dr. Aydin Azizi Example of MATLAB Release 13 desktop Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 5. Slide 5 Lecturer: Assistant Prof. Dr. Aydin Azizi Variables – Vectors and Matrices – • ALL variables are matrices Variables •They are case–sensitive i.e. x  X •Their names can contain up to 31 characters •Must start with a letter •Variables are stored in workspace e.g. 1 x 1 4 x 1 1 x 4 2 x 4       4239 6512 7123             3 9 2 3  4 Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 6. Slide 6 Lecturer: Assistant Prof. Dr. Aydin Azizi How do we assign a value to a variable? >>> v1=3 v1 = 3 >>> i1=4 i1 = 4 >>> R=v1/i1 R = 0.7500 >>> >>> whos Name Size Bytes Class R 1x1 8 double array i1 1x1 8 double array v1 1x1 8 double array Grand total is 3 elements using 24 bytes >>> who Your variables are: R i1 v1 >>> Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 7. Slide 7 Lecturer: Assistant Prof. Dr. Aydin Azizi How do we assign values to vectors? >>> A = [1 2 3 4 5] A = 1 2 3 4 5 >>> >>> B = [10;12;14;16;18] B = 10 12 14 16 18 >>> A row vector values are separated by spaces  54321A                   18 16 14 12 10 B A column vector values are separated by semi–colon (;) Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 8. Slide 8 Lecturer: Assistant Prof. Dr. Aydin Azizi How do we assign values to vectors? • If we want to construct a vector of, say, 100 elements between 0 and 2 – linspace >>> c1 = linspace(0,(2*pi),100); >>> whos Name Size Bytes Class c1 1x100 800 double array Grand total is 100 elements using 800 bytes >>> Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 9. Slide 9 Lecturer: Assistant Prof. Dr. Aydin Azizi How do we assign values to vectors? If we want to construct an array of, say, 100 elements between 0 and 2 – colon notation >>> c2 = (0:0.0201:2)*pi; >>> whos Name Size Bytes Class c1 1x100 800 double array c2 1x100 800 double array Grand total is 200 elements using 1600 bytes >>> Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 10. Slide 10 Lecturer: Assistant Prof. Dr. Aydin Azizi How do we assign values to matrices ? Columns separated by space or a comma Rows separated by semi-colon >>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>>           987 654 321 Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 11. Slide 11 Lecturer: Assistant Prof. Dr. Aydin Azizi How do we access elements in a matrix or a vector? >>> A(2,3) ans = 6 >>> A(:,3) ans = 3 6 9 >>> A(1,:) ans = 1 2 3 >>> A(2,:) ans = 4 5 6 Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 12. Slide 12 Lecturer: Assistant Prof. Dr. Aydin Azizi Some special variables pi () inf (e.g. 1/0) i, j ( )1 >>> 1/0 Warning: Divide by zero. ans = Inf >>> pi ans = 3.1416 >>> i ans = 0+ 1.0000i Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 13. Slide 13 Lecturer: Assistant Prof. Dr. Aydin Azizi Arithmetic operations – Matrices Performing operations to every entry in a matrix Add and subtract>>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> >>> A+3 ans = 4 5 6 7 8 9 10 11 12 >>> A-2 ans = -1 0 1 2 3 4 5 6 7 Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 14. Slide 14 Lecturer: Assistant Prof. Dr. Aydin Azizi Arithmetic operations – Matrices Performing operations to every entry in a matrix Multiply and divide>>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> >>> A*2 ans = 2 4 6 8 10 12 14 16 18 >>> A/3 ans = 0.3333 0.6667 1.0000 1.3333 1.6667 2.0000 2.3333 2.6667 3.0000 Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 15. Slide 15 Lecturer: Assistant Prof. Dr. Aydin Azizi Arithmetic operations – Matrices Performing operations to every entry in a matrix Power >>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> A^2 = A * A To square every element in A, use the element–wise operator .^ >>> A.^2 ans = 1 4 9 16 25 36 49 64 81 >>> A^2 ans = 30 36 42 66 81 96 102 126 150 Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 16. Slide 16 Lecturer: Assistant Prof. Dr. Aydin Azizi Performing operations between matrices >>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> B=[1 1 1;2 2 2;3 3 3] B = 1 1 1 2 2 2 3 3 3 A*B                     333 222 111 987 654 321 A.*B           3x93x83x7 2x62x52x4 1x31x21x1           272421 12108 321 = =           505050 323232 141414 Arithmetic operations – Matrices Lecturer: Assistant Prof. Dr. Aydin Azizi
  • 17. Slide 17 Lecturer: Assistant Prof. Dr. Aydin Azizi Roots- Logarithms
  • 18. Slide 18 Lecturer: Assistant Prof. Dr. Aydin Azizi Random Number
  • 19. Slide 19 Lecturer: Assistant Prof. Dr. Aydin Azizi Random Real Number
  • 20. Slide 20 Lecturer: Assistant Prof. Dr. Aydin Azizi Random Integer Number
  • 21. Slide 21 Lecturer: Assistant Prof. Dr. Aydin Azizi Practice
  • 22. Slide 22 Lecturer: Assistant Prof. Dr. Aydin Azizi Characters and Encoding
  • 23. Slide 23 Lecturer: Assistant Prof. Dr. Aydin Azizi Characters and Encoding
  • 24. Slide 24 Lecturer: Assistant Prof. Dr. Aydin Azizi Characters and Encoding
  • 25. Slide 25 Lecturer: Assistant Prof. Dr. Aydin Azizi Practice
  • 26. Slide 26 Lecturer: Assistant Prof. Dr. Aydin Azizi Relational Expressions
  • 27. Slide 27 Lecturer: Assistant Prof. Dr. Aydin Azizi Relational Expressions
  • 28. Slide 28 Lecturer: Assistant Prof. Dr. Aydin Azizi Relational Expressions
  • 29. Slide 29 Lecturer: Assistant Prof. Dr. Aydin Azizi Logical Operators
  • 30. Slide 30 Lecturer: Assistant Prof. Dr. Aydin Azizi Logical Operators
  • 31. Slide 31 Lecturer: Assistant Prof. Dr. Aydin Azizi Logical Operators
  • 32. Slide 32 Lecturer: Assistant Prof. Dr. Aydin Azizi Truth Table for Logical Operators
  • 33. Slide 33 Lecturer: Assistant Prof. Dr. Aydin Azizi Logical Error
  • 34. Slide 34 Lecturer: Assistant Prof. Dr. Aydin Azizi Logical Error
  • 35. Slide 35 Lecturer: Assistant Prof. Dr. Aydin Azizi Practice
  • 36. Slide 36 Lecturer: Assistant Prof. Dr. Aydin Azizi While Loop count = 0; number = 8; while number > 3 number = number - 2 count = count+1 end
  • 37. Slide 37 Lecturer: Assistant Prof. Dr. Aydin Azizi FOR Loop mat=rand(5,6) [r c] = size(mat) for i = 1:r for j = 1:c mat(i,j) = mat(i,j) * 2 end end
  • 38. Slide 38 Lecturer: Assistant Prof. Dr. Aydin Azizi IF Loop x=rand(10,1); v = [ ] for i = 1:length(x) if x(i) > 0 v = [v i] end end