Numerical Methods in Engineering (ENGR20005)
Lecture 01 Dr. Leon Chan
lzhchan@unimelb.edu.au Department of Mechanical Engineering The University of Melbourne
Slides prepared by Prof.Andrew Ooi
Privacy Information
• “Post-Lecture/Live-Lecture” videos.
• These ‘live’ zoom lectures are recorded
• Student screen names are recorded
• If you turn on your camera/speak through the
microphone, it will be recorded.
• Can choose to NOT turn on camera and microphone
and communicate via chat box.
• Recorded video will be uploaded to Canvas only for
the purpose of the subject till the end of Sem 1 2021 and it will not be used again.
Mathematical equations that govern fluid flow
x
(a)
Computer Program
Supercomputer
x
(a) (c)
(a) (c)
Coughing
Calculations performed by Mr. Tony Zahtila
Gravity
currents
Water tank
heavy
gravity
light
Water tank
heavy
gravity
light
Water tank
heavy
light
Water tank
gravity
Hot (light air)
Cool (heavy air)
SolarGIS © 2014 GeoModel Solar [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons
gravity current
304 H. E. Huppert
Figure 3. A large-Reynolds-number compositional gravity current over the Los Angeles Basin. Almost every morning the sun shines down on Southern California and the neighbouring Pacific Ocean. The atmosphere above the land surface becomes relatively warm and less dense than that above the sea. The horizontal density difference results in a gravity current of relatively cold, moist air, which spreads across the California countryside (photographer: G. R. Stevens).
cuedeven if
Gravity current
Figure taken from H.E. Huppert. “Gravity currents: a personal
rrent. Note that g′ and A only appear as the product g′A, which is conserv
perspective”, Journal of Fluid Mechanics, vol 554, pp 299-322. mixing between the two fluids occurs.
The use of similarity theory applied to the shallow-water equations (Hoult 1972;
Teaching activities
Activity
Day
Time
“Venue”
Lecture 1
Thursdays
10am-11am
Zoom link
See “Home” on LMS site
Lecture 2
Fridays
10am-11am
Zoom link
See “Home” on LMS site
Teaching activities
Activity
Day
Time
“Venue”
Workshop 1
Monday
9am-11pm
PAR-Old Engineering- EDS6
Workshop 2
Tuesdays
10am-12pm
PAR-Old Engineering- EDS6
Workshop 3
Wednesdays
11am-1pm
PAR-Elec. Engineering-123
Workshop 4
Thursday
4:15pm-6:15pm
Zoom link
See “Home” on LMS site
Workshop 5
Thursday
12pm-2pm
PAR-Engineering B-102
Workshop 6
Monday
1pm-3pm
Zoom link
See “Home” on LMS site
Cover the same material. Only really need to attend one of these. Starts in week 1
Teaching activities
Students will be assessed in workshops (0.5marks/workshop)
Workshop activities to be conducted in groups of 3-4 people.
Students can form their own group on Canvas (members MUST be
from the same workshop session)
• • •
Learning Material
• ENGR 20005 “Book”.
LMS -> Modules-> Comprehensive Notes->ENGR20005Book.pdf
• “Pre-Lecture” videos. Released early in the week.
• “Pre-Lecture” notes. Released early in the lectures. • “Post-Lecture” videos. Released after the lectures.
• MATLAB live scripts from Workshops.
Prof Andrew Ooi Associate Dean (Student Engagement)
FEIT
Dr Leon Chan Research Fellow (Andrew’s minion)
How can you get help?
There are a range of mechanisms to use when you need help.
Ask the lecturer during or after the lecture.
Post your query to the LMS discussion forum. Read other posts and
responses
while you wait for a response to your query.
Ask tutors in the workshops, or email them
Email the lecturer
Make an appointment to have a “Zoom” session with the lecturer
after the lecture.
• •
• • •
Assessment
Workshop Assessment
5% (0.5% per workshop, maximum of 5%)
Do NOT Plagiarise!!!!!!
Assignment 1
10%
(due around week 5)
Assignment 2
20%
(due around week 7)
Assignment 3
25%
Do NOT Plagiarise!!!!!!
(due around week 11)
Exam
40%
End of semester
Do NOT Plagiarise!!!!!!
Do NOT Plagiarise!!!!!!
Do NOT Plagiarise!!!!!!
Do NOT Plagiarise!!!!!!
Assignment 1
Assignment 1
L1.1 MATLAB: Interface
“Traditional” MATLAB Interface
Command window
This is where you type in MATLAB commands
“Traditional” MATLAB Interface
Workspace
Where you will find information on all your variables
“Traditional” MATLAB Interface
Your current folder
MATLAB “Live Script” Interface
Nicely formatted text explanation.
MATLAB “Live Script” Interface
MATLAB COMMANDS
MATLAB “Live Script” Interface
OUTPUT FROM MATLAB COMMANDS
L1.2 MATLAB: Variables and Arrays
“Traditional” MATLAB Interface
The variable ‘a’ appears here, telling you that ‘a’ is now “active” in
MATLAB
“Traditional” MATLAB Interface
b=[2 6 10 4 15 13 8 9 23]
The variables ‘a’ and ‘b’ now appear here, telling you that both ‘a’ and ’b’ are now “active” in MATLAB
b is “row vector” consisting of 9 elements
“Traditional” MATLAB Interface
The variables ‘a’, ’b’ and ‘c’ now appear here, telling you that all ‘a’, ’b’ and ‘c’ are now “active” in MATLAB
The semicolon denotes a new row
26
10 4
c= 15 13
89 23
c is “column vector” consisting of 9 elements
“Traditional” MATLAB Interface
The variables ‘a’, ’b’, ’c’ and ‘d’ now appear here, telling you that all ‘a’, ’b’, ‘c’ and ‘d’ are now “active” in MATLAB
The semicolon denotes a new row
d=
2 6 10
4 15 13 d is 3×3 matrix 8 9 23
“Traditional” MATLAB Interface
MATLAB “Live Script” Interface
MATLAB “Live Script” Interface
MATLAB “Live Script” Interface
Explanation
MATLAB “Live Script” Interface
MATLAB COMMANDS
MATLAB “Live Script” Interface
OUTPUT FROM MATLAB COMMANDS
L1.3 MATLAB: Plot Graphs
x = [!2 !1.5 !1.0 !0.5 0.0 0.5 0.5 0.5 0.5
0.5
0.5 1.0 1.5 2.0]
0.5 0.5 0.5
x is “row vector” consisting of 9 elements
x = [!2 x . “2 = [(!2)2
x . “2 = [4
!1.5 !1.0 !0.5 0.0 0.5 1.0 1.5 2.0] (!1.5)2 (!1.0)2 (!0.5)2 0.02 0.52 1.02 1.52 22]
2.25 1.0 0.25 0.0 0.25 1.0 2.25 4.0]
x = [!2 !1.5 !1.0 !0.5 0.0 0.5 1.0 1.5 2.0] x . “3 ! x = [ (!2)3 (!1.5)3 (!1.0)3 (!0.5)3 0.03 0.53 1.03 1.53 23 ]
!(!2) !(!1.5) !(!1) 0.5 !0 !0.5 !1.0 !1.5 !2.0
x = [!6 !1.875 0 0.375 0.0 !0.375 0.0 1.875 6.0]
Function of two variables
The ripple on the surface of water caused by a drop of water at some instantaneous time can be modelled by the following equation
h(x,y)=Asin( x2+y2+c2) x2 +y2 +c2
h is the height of the water at coordinates (x, y). A, c are constants.
Plot contours
h(x,y)=Asin( x2+y2+c2) x2 +y2 +c2
Setup x, y grid
[x y] = meshgrid([-10:0.1:10], [-10:0.1:10]);
Calculate h
h = A*sin(sqrt(x.^2+y.^2+c^2))./sqrt(x.^2+y.^2+c^2);
Plot h
figure
contourf(x,y,h,[-1.5:0.5:4]);hold on;
contourf(x,y,h,[-1.5:0.5:4]);hold on;
contour(x,y,h,[-0.5 -0.5]);
pcolor(x,y,h); shading interp
surf(x,y,h); shading interp
#h=A ycos( x2+y2+c2)!ysin( x2+y2+c2) #y x2 +y2 +c2 (x2 +y2 +c2)3/2
*Use Quotient rule
#h=A xcos( x2+y2+c2)!xsin( x2+y2+c2) #x x2 +y2 +c2 (x2 +y2 +c2)3/2
*Use Quotient rule
L1.4 Taylor Series (Page 7 of Book)
Taylor Series
The Taylor series expansion of a function f(x) about the point x0 and can be written as
f(x)=!$ f(k)(x0)(x!x0)k k=0 k!
= f(x0) + f%(x0)(x ! x0) + f%%(x0) (x ! x0)2 + f (%%%)(x0) (x ! x0)3 + &+ 2! 3!
In reality, you cannot sum to infinity.
(1.1)
f(x) = PN(x) + RN(x) where N f (k)(x0) k
PN(x) = !k=0 k! (x ! x0)
PN(x) RN(x)
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
is the Nth order Taylor Polynomial for f
is the remainder which is also known as the truncation error. !(x) is a number between x and x0, i.e. x ‘ !(x) ‘ x0
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ! x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f %(!(x))(x ! x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f%(x0)(x ! x0)
R1(x) = f %%(!(x)) (x ! x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f%%(x0) 2 f%%%(!(x)) P2(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) R2(x)= 3! (x!x0)3
For N=3
f(x) = P3(x) + R3(x) f%%(x0) 2 f%%%(x0) 3 fiv(!(x)) P3(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) + 3! (x!x0) R3(x)= 4! (x!x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ! x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f %(!(x))(x ! x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f%(x0)(x ! x0)
R1(x) = f %%(!(x)) (x ! x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f%%(x0) 2 f%%%(!(x)) P2(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) R2(x)= 3! (x!x0)3
For N=3
f(x) = P3(x) + R3(x) f%%(x0) 2 f%%%(x0) 3 fiv(!(x)) P3(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) + 3! (x!x0) R3(x)= 4! (x!x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ! x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f %(!(x))(x ! x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f%(x0)(x ! x0)
R1(x) = f %%(!(x)) (x ! x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f%%(x0) 2 f%%%(!(x)) P2(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) R2(x)= 3! (x!x0)3
For N=3
f(x) = P3(x) + R3(x) f%%(x0) 2 f%%%(x0) 3 fiv(!(x)) P3(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) + 3! (x!x0) R3(x)= 4! (x!x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ! x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f %(!(x))(x ! x0)
As we increase N,
P has more terms
and become polynomial of order N
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f%(x0)(x ! x0)
R1(x) = f %%(!(x)) (x ! x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f%%(x0) 2 f%%%(!(x)) P2(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) R2(x)= 3! (x!x0)3
For N=3
f(x) = P3(x) + R3(x) f%%(x0) 2 f%%%(x0) 3 fiv(!(x)) P3(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) + 3! (x!x0) R3(x)= 4! (x!x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ! x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f %(!(x))(x ! x0)
As we increase N,
the remainder (or error) term becomes smaller and smaller near x=x0
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f%(x0)(x ! x0)
R1(x) = f %%(!(x)) (x ! x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f%%(x0) 2 f%%%(!(x)) P2(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) R2(x)= 3! (x!x0)3
For N=3
f(x) = P3(x) + R3(x) f%%(x0) 2 f%%%(x0) 3 fiv(!(x)) P3(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) + 3! (x!x0) R3(x)= 4! (x!x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ! x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f %(!(x))(x ! x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f%(x0)(x ! x0)
R1(x) = f %%(!(x)) (x ! x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f%%(x0) 2 f%%%(!(x)) P2(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) R2(x)= 3! (x!x0)3
For N=3
f(x) = P3(x) + R3(x) f%%(x0) 2 f%%%(x0) 3 fiv(!(x)) P3(x)=f(x0)+f%(x0)(x!x0)+ 2! (x!x0) + 3! (x!x0) R3(x)= 4! (x!x0)4
Taylor series illustration
f(x) = PN(x) + RN(x) f(x)
x0 = 0
Taylor series illustration
f(x) = P0(x) + R0(x) f(x)
x0 = 0
P0 = f(x0)
R0(x) = f %(!(x))(x ! x0)
Taylor series illustration
f(x) = P1(x) + R1(x) f(x)
x0 = 0
P1(x) = f(x0) + f%(x0)(x ! x0)
R1(x)= f%%(!(x))(x!x0)2 2!
Taylor series illustration
f(x) = P2(x) + R2(x) f(x)
x0 = 0
P2(x) = f(x0) + f%(x0)(x ! x0) + f%%(x0) (x ! x0)2 %%%
2! R2(x) = f (!(x))(x ! x0)3 3!
Taylor series illustration
R3(x) = f iv (!(x))(x ! x0)4 4!
x0 = 0
f(x) = P3(x) + R3(x) f(x)
P3(x) = f(x0) + f%(x0)(x ! x0) + f%%(x0) (x ! x0)2 + f%%%(x0) (x ! x0)3 2! 3!
Taylor series illustration
f(x) x0 = 1
Taylor series illustration
x0 = 1 R0(x) = f %(!(x))(x ! x0)
f(x) = P0(x) + R0(x) f(x)
P0 = f(x0)
Taylor series illustration
x0 = 1 R1(x) = f %% (!(x))(x ! x0)2
f(x) = P1(x) + R1(x) f(x)
2!
P1(x) = f(x0) + f%(x0)(x ! x0)
Taylor series illustration
x0 = 1 R2(x) = f %%% (!(x))(x ! x0)3
f(x) = P2(x) + R2(x) f(x)
3!
P2(x) = f(x0) + f%(x0)(x ! x0) + f%%(x0) (x ! x0)2 2!
Taylor series illustration
x0 = 1 R2(x) = f iv (!(x))(x ! x0)4
f(x) = P3(x) + R3(x) f(x)
4!
P3(x) = f(x0) + f%(x0)(x ! x0) + f%%(x0) (x ! x0)2 + f%%%(x0) (x ! x0)3 2! 3!
f(x) = P (x) + R (x) 0312 0312
f%(x ) f%%%(x )
0 2 0 3
P P ( =x ) f = ( x f ( ) x ) + f % ( x ) ( x ! x )
P(x)=f(x)+f%(x)(x!x)+ (x!x) + (x!x)
01 00 0 0
32 0 0 0 2! 0 3! 0
x0 = 0
f (x)
f (x)
x0 = 1
Example L01.1: Find the Taylor series of the function
f(x) = sin(x)
about x0=0. Plot the first few terms of this function and show that you can get closer to the original function if you use more and more terms in the series.
Want to find the Taylor series for
f(x) = sin(x)
The general formula for Taylor series is (see Eq. (1.1))
f(x) = f(x0) + f%(x0)(x ! x0) + f%%(x0)(x ! x0)2 + f%%%(x0)(x ! x0)3 + &+ 2! 3!
Using, Eq. (1.1), expand the function about x0=0. the Taylor series for sin(t) can be written as
x
%%% f%%(x ) f (x )
00 0
xxx0x200x3 f(x)=f(x0)+f%(x0)(x!x)+ (x!x) + (x!x) +&+
000
00000 0 0 0 2! 0 3! 0
x
You are given that
f(x) = sin(x)
f(x) = sin(x)
f ( x ) = f ( 0 ) + f %( 0 ) ( x ! 0 ) + f %%( 0 ) ( x ! 0 ) 2 + f %%%( 0 ) ( x ! 0 ) 3 + & +
2! 3!
f(x) = f(0) + f%(0)x + f%%(0) x2 + f%%%(0) x3 + &+ 2! 3!
d2f (x = 0) = ! sin(0) = 0 dx2 3
d f(x=0)=!cos(0)=!1 dx3
sin(0) = 0
df (x = 0) = cos(0) = 1
dx
f(x)=x!1×3+ 1 x5! 1 x7+…… 6 120 5040
f(x)=x!1×3+ 1 x5! 1 x7+…… 6 120 5040
Therefore for this example
P1(x)=x 1 3 P3(x) = x ! 6 x
P5(x)=x!1×3+ 1 x5 6 120
P7(x)=x!1×3+ 1 x5! 1 x7 6 120 5040
x0
f(x) = sin(x)
!1×3+ 1 x5! 1 x7 6 120 5040
P(x) = x 1
x0
f(x) = sin(x)
P(x) = x ! 1 x3
+ 1 x5! 1 x7 120 5040
3
6
x0
f(x) = sin(x)
P(x)=x!1×3+ 1 x5
! 1 x7 5040
5
6 120
x0
f(x) = sin(x)
P(x)=x!1×3+ 1 x5! 1 x7
7
6 120 5040
x0
f(x) = sin(x)
End of Example L01.1
L1.5
Mean Value Theorem (Page 5 of Book)
Mean Value Theorem
Recall Taylor’s Theorem
f(x) = PN(x) + RN(x) PN(x) = !N f (k)(x0) (x ! x0)k
RN(x) = f (N+1)(!(x)) (x ! x0)N+1 (N+1)!
k=0 k!
Let’s truncate the series at N=0
f(x) = f(x0) + f%(!(x))(x ! x0) Rearranging gives
P0(x) R0(x) x ‘ !(x) ‘ x0
f(x) ! f(x0) x!x0
= f%(!(x))
if f is a continuous function and differentiable between x
and x0, there exist a local gradient whose value is the
average gradient f(x) ! f(x0) x!x0
f(x)
Mean Value Theorem
f(xL) ! f(x0) xL ! x0
x0
x = xL
x
f(x) ! f(x0) x!x0
= f%(!(x)) x ‘ !(x) ‘ x0
f(x)
Mean Value Theorem
f(xL) ! f(x0) xL ! x0
x0
x = xL
x
f(x) ! f(x0) x!x0
= f%(!(x)) x ‘ !(x) ‘ x0
f(x)
Mean Value Theorem
f(xL) ! f(x0) xL ! x0
x0
x = xL
x
f(x) ! f(x0) x!x0
= f%(!(x)) x ‘ !(x) ‘ x0
f(x)
Mean Value Theorem
f(xL) ! f(x0) xL ! x0
x0 !(x)
x = xL
x
f(x) ! f(x0) x!x0
= f%(!(x)) x ‘ !(x) ‘ x0