Week7 ENG1060 Lecture13

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 40

ENG 1060

Computing for Engineers


Lecturer: Dr Christopher Hutchinson
Lecture 13:
Introduction (Part 2)/Stock-take
Details about your Lecturers
• Introduction

• Subject
Overview
Yogen Padayatchy
• A Warning! Department of Mechanical Engineering
• PASS Program Room 134, Building 37
• An engineering
example of root Phone: 990 51089
finding Email: Yogen.Padayatchy@eng.monash.edu.au

Dr Christopher Hutchinson
Department of Materials Engineering
Room 161, Building 19

Phone: 990 55288


Email: Christopher.Hutchinson@eng.monash.edu.au

2
Asking me questions
• Introduction

• Subject
I can answer questions you may have (on
Overview
Part 2 of the course) out of lecture hours.
• A Warning!

• PASS Program

• An engineering I will be available at the following times in


example of root
finding my office (room 161 building 19):

Take advantage of this!

Monday : 10:00am – 12 lunchtime


Tuesday : 2:00pm – 4:00 pm

3
Where can I be found?
• Introduction

• Subject
Overview

• A Warning!

• PASS Program

• An engineering
example of root
finding

CRH Office (Rm 161/Bld 19)


4
Subject Overview (Part 1: YP)
• Introduction

Week 1-6: Learning to Program


• Subject
Overview

1: Introduction / Matlab demonstration


• A Warning!

• PASS Program

• An engineering 2: Variables & operators / How to program


example of root
finding
3: Arrays and Matrices
4: Logical Operations
5: Loop structures
6: Graphical Output
7: Function files
8: Advanced file input/output

5
Subject Overview (Part 2: CRH)
• Introduction

Week 7-12: Numerical Methods


• Subject
Overview

• A Warning!

• PASS Program Part 2 is all about using ‘programming’ to


• An engineering
example of root
develop the numerical tools that we use as
finding
engineers; i.e. our ‘tools of the trade’

These numerical methods are common to all


branches of science and engineering and you
will use them throughout the remaining 4 yrs
of your degree (and probably for many years
after).

6
Subject Overview
• Introduction
Week 7-12: Numerical Methods
• Subject
Overview

• A Warning! Week 7 Root Finding and Optimization


• PASS Program Week 8 Linear Algebra in Engineering
• An engineering
example of root
finding

7
Subject Overview
• Introduction
Week 7-12: Numerical Methods
• Subject
Overview

• A Warning! Week 9 Matrix Manipulation


• PASS Program Week 10 Curve fitting of data
• An engineering
example of root
finding

8
Subject Overview
• Introduction
Week 7-12: Numerical Methods
• Subject
Overview

• A Warning! Week 11 Numerical Integration


• PASS Program Week 12 The Solution of Ordinary
• An engineering
example of root
Differential Equations
finding (ODE’s)

9
A Warning!
ENG1060 is brutally cumulative
• Introduction

• Subject
Overview

• A Warning!

• PASS Program
Successful completion of Part 2 of
• An engineering
example of root
finding
ENG1060 requires a good
understanding of Part 1 of ENG1060

You must understand the basics of


programming (Part 1) before you can
use programming to solve
engineering problems (part 2)
10
Practice/Lab Classes
• The only way to succeed (pass) in
• Introduction

• Subject
Overview

• A Warning!
programming (ENG1060) is
• PASS Program practice practice practice.
• An engineering
example of root
finding

• The tutorials and laboratories are


the best (only) way for you to learn
material for this subject.

11
ENG 1060
Computing for Engineers
Lecturer: Dr Christopher Hutchinson
Lecture 13:
Root finding
An engineering example….
• Introduction

• Subject
Overview
Oil/Gas Pipelines
• A Warning!

• PASS Program

• An engineering
example of root
finding

13
An engineering example….
• Introduction
The function of an oil/gas pipeline is to safely
• Subject
Overview transport oil or gas under pressure over large
• A Warning!
distances.
• PASS Program

• An engineering
example of root
finding

14
An engineering example….
• Introduction
Pipelines are essentially huge pressure vessels.
• Subject
Overview

• A Warning!
It is of paramount importance that the pipeline is safe
• PASS Program
All real engineering structures contain
• An engineering
example of root
t cracks!
finding

Every bridge, car, plane and building


you see contains thousands of cracks.
R
2ac
Pressure, P
h
When we design engineering structures
we design so that even if cracks are
Pipe cross-section there they will not lead to failure.

15
An engineering example….
• Introduction
There are two types of cracks:
• Subject
Overview
• those that grow very slowly (and can be monitored)
• A Warning!

• PASS Program • those that grow very quickly (at the speed of sound)
• An engineering and lead to catastrophic failure
example of root
finding

16
An engineering example….
• Introduction
There are two types of cracks:
• Subject
Overview
• those that grow very slowly (and can be monitored)
• A Warning!

• PASS Program • those that grow very quickly (at the speed of sound)
• An engineering and lead to catastrophic failure
example of root
finding

There is an equation that tells us which is which!


C 1
 f aC  CK IC Cos   a c 
Fracture toughness (material parameter)
Crack size e.g. steel KIC~50 MPa m1/2

f is the stress at which a crack of size ac will grow unstably and lead
to catastrophic failure
17
An engineering example….
• Introduction
We need to make sure that a crack that reaches all
• Subject
Overview the way through the wall of the pipe (ac=t/2) will still
• A Warning! not propagate unstably and lead to catastrophic
• PASS Program failure (‘leak before break’ criteria).
• An engineering
example of root The Hoop stress is given by:
finding t PR
h 
t
R The catastrophic failure stress is
2ac
given by:
Pressure, P
h K IC
 f   aC 
Cos   a c 

Pipe cross-section

18
An engineering example….
• Introduction
In the design of the pipeline we need to choose a pipe
• Subject
Overview wall thickness t, so that h<f, with cracks of size
• A Warning! ac=t/2, to really be sure we are safe
• PASS Program

h PR
• An engineering
example of root
 
finding t t
K IC
f 
  t / 2  Cos   t / 2
R
2ac
Pressure, P
h Our design limit is:
PR K IC

Pipe cross-section
t   t / 2  Cos  t / 2 
19
An engineering example….
• Introduction
Our design limit is: PR K IC

• Subject
Overview
t   t / 2  Cos  t / 2
• A Warning!

• PASS Program Usually, P, R and KIC are specified.


• An engineering
example of root
finding We need to choose the pipe wall thickness, t.

Whatever you do to the above equation, you cannot


get t on its own on the LHS!

This is called an implicit equation in t.

The value of t which satisfies this equation is known


as its ‘root’.
20
Root finding
• Introduction
‘Implicit equations’ occur all the time in engineering.
• Subject
Overview
Especially in engineering design problems
• A Warning!

• PASS Program
PR K IC

  t / 2  Cos  t / 2
• An engineering
example of root t
finding

We need methods to efficiently solve these equations

This is the first ‘Numerical Method’ we are going to


learn how to program

21
Root finding
• Introduction
This implicit equation can be rewritten as:
• Subject
Overview
K IC PR
g (t )  
  t / 2  Cos   t / 2
• A Warning!
t
• PASS Program

• An engineering
example of root
finding
We would like to find the value of t for which g(t)=0

22
Root finding
• Introduction
This implicit equation can be rewritten as:
• Subject
Overview
K IC PR
g (t )  
  t / 2  Cos   t / 2
• A Warning!
t
• PASS Program

• An engineering
example of root
finding
We would like to find the value of t for which g(t)=0

A good way to start is to plot this equation as a


function of t. What does it look like?

Typical values of the relevant parameters might be:


P (Pressure) =30MPa, KIC (Fracture Toughness) =60MPa.m1/2
R (Pipe Radius) =40cm

23
Function file
K IC PR
g (t )  
  t / 2  Cos   t / 2  t

function g = pipeline(K,P,R,t)

%This function will return the value of g for a given value of t.


%This applies to the piple line pressure vessles problems of Lecture 13

g=inline('K./(((pi.*t/2).^0.5).*((cos(pi.*t/2)).^0.5))-P.*R./t','K','P','R','t');

24
Root finding
• Introduction
For P=30MPa, KIC=60MPa.m1/2 and R=40cm
• Subject
Overview K IC PR
g (t )  
• A Warning!
  t / 2  Cos   t / 2 t
• PASS Program
1.50E+08
• An engineering
example of root 1.00E+08
finding

5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08 The root of g(t) is t~6-7cm


-2.00E+08

25
Root finding
• Introduction
Graphical methods are useful to see what the
• Subject
Overview
behaviour of g(t) looks like but they are not very
• A Warning!
good at accurately determining the root.
• PASS Program
K IC PR
• An engineering g (t )  
example of root
finding   t / 2  Cos   t / 2  t

Furthermore, sometimes we need to find the roots


of equations thousands of times as part of a larger
program.

We need an automated way to do this

26
Root finding
• Introduction
A very common method to do this is known as the
• Subject
Overview
‘Bisection method’ (Chapra, pg 122, 2nd Ed).
• A Warning!
Step 1. Choose an upper and lower value for t (tl, tu) that ‘brackets’ the
• PASS Program
root; i.e. g(tl)*g(tu)<0.
• An engineering
example of root
finding
(this just means that g changes sign in going from tl to tu)
1.50E+08 tl tu
1.00E+08

5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

27
Root finding
• Introduction
‘Bisection method’
• Subject
Overview Step 2: Evaluate g((tu+tl)/2) → g((tu+tl)/2)<0
• A Warning!

• PASS Program 1.50E+08 tl tu


• An engineering 1.00E+08
example of root
finding
5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

If g((tu+tl)/2)*g(tu)<0, then you know that the root lies in between (tu+tl)/2
and tu.

Therefore reset tl= (tu+tl)/2. Repeat Step 2. 28


Root finding
• Introduction
‘Bisection method’
• Subject
Overview Step 2: Therefore reset tl= (tu+tl)/2. Repeat Step 2.
• A Warning!

• PASS Program 1.50E+08 tl tu


• An engineering 1.00E+08
example of root
finding
5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

29
Root finding
• Introduction
‘Bisection method’
• Subject
Overview Step 2: Evaluate g((tu+tl)/2) → g((tu+tl)/2)>0
• A Warning!

• PASS Program 1.50E+08


tl tu
• An engineering 1.00E+08
example of root
finding
5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

30
Root finding
• Introduction
‘Bisection method’
• Subject
Overview Step 2: Evaluate g((tu+tl)/2) → g((tu+tl)/2)>0
• A Warning!

• PASS Program 1.50E+08


tl tu
• An engineering 1.00E+08
example of root
finding
5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

If g((tu+tl)/2)*g(tu)<0, then you know that the root lies in between (tu+tl)/2
and tu. Otherwise it lies between (tu+tl)/2 and tl.

In this case reset tu= (tu+tl)/2 and repeat Step 2. 31


Root finding
• Introduction
‘Bisection method’
• Subject
Overview Step 2: In this case reset tu= (tu+tl)/2 and repeat Step 2.
• A Warning!

• PASS Program 1.50E+08


tl tu
• An engineering 1.00E+08
example of root
finding
5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

32
Root finding
• Introduction
‘Bisection method’
• Subject
Overview Step 2: Evaluate g((tu+tl)/2) → g((tu+tl)/2)>0
• A Warning!

• PASS Program 1.50E+08


tl tu
• An engineering 1.00E+08
example of root
finding
5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

If g((tu+tl)/2)*g(tu)<0, then you know that the root lies in between (tu+tl)/2
and tu. Otherwise it lies between (tu+tl)/2 and tl.

In this case reset tu= (tu+tl)/2 and repeat Step 2. 33


Root finding
• Introduction
‘Bisection method’
• Subject
Overview This is continued until tu-tl is within the precision with which you need
• A Warning! to know the root of g(t)
• PASS Program 1.50E+08
tltu
• An engineering 1.00E+08
example of root
finding
5.00E+07

0.00E+00
0 0.05 0.1 0.15 0.2
g(t)

-5.00E+07 t

-1.00E+08

-1.50E+08

-2.00E+08

With what you have learnt in Part 1 of this course you can write a
program to find the root of an equation using the ‘Bisection Method’.
34
M-file: Bisection method
function root = bisect(func,x1,x2,acc,K,P,R)

• Introduction %Firstly we evaluate the function at the two input values of the indep
%variable
• Subject fx1=feval(func,K,P,R,x1);
Overview fx2=feval(func,K,P,R,x2);

% We will use a 'While' loop to loop through our guesses at the root of
• A Warning! % the function. Whilst the value of the function evaluated at the root
% is greater than the accuracy we have specified, 'acc' then we keep
% looping.
• PASS Program
% We are also going to count the number of loops it takes to find the %
% root in the variable, 'LoopNum'
• An engineering LoopNum=1;
example of root
fxr=1;
finding
while (abs(fxr)>acc)

%Evaluate the new guess at the root


xr=(x1+x2)/2;
fxr=feval(func,K,P,R,xr);

% Now we need to work out whether the new guess at the root lies on the
% LHS or RHS of the true root and set new brackets accordingly
if ((fx1*fxr)<0)
x2=xr;
else
x1=xr;
end

%We will print to the window our successive guesses at the root so you
%can see well how the algorithm works
fprintf('%5d %10.4f\n',LoopNum,xr)

% After each attempt we increment our number of guesses at the root by


% one. Note: This has no affect at all on the routine. It is just so
% we can look at how many guesses it takes before we arrive at the
% solution.
LoopNum=LoopNum+1;

end

root=xr; 35
Root finding
• Introduction
The Bisection Method is known as one of the
• Subject
Overview
‘Bracketing Methods’ for root finding.
• A Warning!

• PASS Program The name arises because you must initially choose
• An engineering value of tl and tu that ‘bracket’ the root.
example of root
finding

There are a number of ‘Bracketing Methods’, that differ


only in the way they make the new guess of t.

Another ‘Bracketing method’ is the


‘False Position Method’ (Chapra, 2nd Ed, pp.128)

36
False Position Method
• Introduction
The new guess is found f ( x u )  x l  x u 
• Subject x r  xu 
Overview using this equation f ( xl )  f ( xu )
• A Warning!

• PASS Program

• An engineering
example of root xl xu
finding

xr

xu  xl
cf. Bisection method: xr 
2
37
Bracketing Methods
• Introduction Bracketing methods are reliable and work extremely
• Subject
Overview
well so long as you can initially bracket the root
• A Warning!
It helps to know a bit about the Possible problems!
• PASS Program behaviour of the function
• An engineering
example of root
finding

38
Lecture Summary
• Introduction

• Subject
Overview • Overview of Part 2 (Numerical
• A Warning!
methods) of ENG1060
• PASS Program

• An engineering
example of root
finding
• Designing pipelines: An example
requiring root-finding
• Bracketing methods for root finding
→ Bisection method
→ False position Method

39
Next Lecture
Bracketing methods only work if your initial
• Introduction

• Subject
Overview guesses bracket the root.
• A Warning!

• PASS Program
Sometimes this is not easy to ensure!
• An engineering
example of root
finding
• ‘Open methods’ for root finding (no need to
bracket the root)
• Optimization (finding minima and maxima)

40

You might also like