You are on page 1of 42

ME – 361 NUMERICAL METHODS FOR ENGINEERS

SOLUTION OF ENGINEERING PROBLEMS

Given A real physical problem such as design and manufacture of a


robot arm, heat exchanger, etc.

Determine Length, area, volume, material, velocity, acceleration, forces,


pressure, temperature, flow rates of mass and energy, etc.

Mathematical Use simplifying assumptions => Physical Modeling


Formulation

Make force, momentum, mass, energy balances

Obtain mathematical equations in the form of differential,


integral, integro-differential, algebraic, set of algebraic, etc.

Make further simplifications on the mathematical formulae


=> Mathematical Modeling

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

SOLUTION OF ENGINEERING PROBLEMS

Solve • Analytically (exactly)


Mathematical
Formulae • Numerically (approximately), using methods such
as finite differences, finite elements, spectral
methods, etc., using computers and programming

Report Errors With respect to the solution technique


and
Interpret With respect to the simplifications in the mathematical
Results formulae

With respect to the simplifications in the physical model

See the pdf file «Engineering Mathematicians» on the Moodle

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example
dv(t)
ma=m = FG - FD = m g - FD v(t) = ?
dt

Physical model: Perfect sphere

Mathematical model: Assume FD is proportinal to velocity

FD = CD v(t)

dv(t) m g - CD v(t)
=
dt m

Analytical (exact) solution:

gm   CD  
v(t) = 1 - exp  m t 
CD   
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example
Relax the mathematical model:

1 dv(t) m g - FD
  v(t) CD AP
2
FD = =
2 dt m

v(t) = ?

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

COMPUTERS AND PROGRAMMING

A computer program (code) a set (list) of commands (operations) to be executed.

Commands:

 Input and Output

 Defining variables

 Execution of mathematical operations

 Controlling the order in which commands are executed

 Repeating sections of the program

 Creating figures and charts

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Algorithm is the plan of implementation on a computer.

Problem: Find the real roots of the equation: a x  b x  c  0


2

-b  b-4a c -b  b-4a c
x1  x2 
2a 2a
Algorithm:

 Start and read in the given values for a, b, and c

 Calculate the value of the discriminant D = b2 – 4 a c

 If D ≥ 0, calculate the two real roots using the equations, and write them

 If D = 0, calculate the root x = -b/2a, write and display “Single root”

 If D < 0, display “No real root”

 Stop
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

COMPUTATIONAL PROCEDURE

Frequently, several methods are available for the numerical solution of a given
mathematical problem. Few relevant criteria for selection of a method:

 Accuracy
 Efficiency
 Numerical stability
 Programming simplicity
 Versatility
 Computer storage requirements
 Interfacing with available software
 Previous experience with a given method

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

REVIEW OF CALCULUS
Given: f(x), a real-valued continuous
f(x)
function

Open and Closed Intervals: f(b)

Open : (a , b) : in a to b f(a)
x
Closed : [a , b] : in and on a to b a b
Continuous Function

If a real valued function, f (x), is defined in (a , b) it is said to be continuous on


(a , b) at a point x0 if, for every ε > 0, there exists a positive, non-zero δ such

that | x – x0 | < δ, | f (x) - f (x0) | < ε

If a function is continuous for all x values in an interval, it is said to be


continuous on the interval.
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Mean-Value Theorem for Derivatives

When f(x) is continuous on [a , b] and f '(x) exists for all interior points, then at
some ξ
f(b) - f(a)
f ' (  , a  b
ba

f(x)
Slopes are equal

a x
b
ξ

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Mean-Value Theorem for Integrals

If f(x) is continuous and integrable on [a , b] then


b

 f (x) dx  (b - a) f ()
a
, ab

f(x)
Areas are equal

f(ξ)
x
ξ b
a

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Similarly, if f (x) and g (x) are continuous and integrable on [a , b], and if g (x)
does not change sign on [a , b], then

b b

 f (x) g (x) dx  f ( )  g (x) dx


a a
, a   b

Geometrical interpretation is that the right-hand-side represents a volume.


This corollary is what we will use most of the time.

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Taylor Series

If a function f(x) and all its derivatives exist at a point x = x 0, the function f(x) can
be represented by an infinite power series in powers of (x - x 0).

(x - x 0 )2 (x - x 0 )n (n)
f(x)  f(x 0 )  (x - x 0 ) f '(x 0 )  f ''(x 0 )  ...  f (x 0 )  R
2! n!
(x - x 0 )n1 (n1)
R f ( ) Remember radius of convergence
(n  1) !

Set x – x0 =  x :

(x)2 (x)n (n)


f(x)  f(x 0 )  x f '(x 0 )  f ''(x 0 )  ...  f (x 0 )  R
2! n!

(x)n1
R  f (n1) ( ) , x0 <  < x
(n  1) !
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Brook Taylor, FRS

English Mathematician

1685 - 1731

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

In another form, substitute x - x 0 = Δx = h

h2 hn (n)
f (x)  f (x 0 )  h f '(x 0 )  f ''(x 0 )  ...  f (x 0 )  R
2! n!

hn1
R  f (n1) ( ) , x0 <  < x
(n  1) !

In another form, substitute x = x 0 + h

h2 hn (n)
f (x 0  h)  f (x 0 )  h f '(x 0 )  f ''(x 0 )  ...  f (x 0 )  R
2! n!

hn1
R  f (n1) ( ) , x0 <  < x
(n  1) !

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Taylor Series and Mean Value Theorem or Integrals

b b

 f (x) g (x) dx  f ( )  g (x) dx


a a
, a   b

x x
(x - t)n ( n 1) (x - t)n
R=  f (t) dt = f ( n 1) ( ) x n! dt
x0
n! 0

(x - x 0 )n 1
R= f ( n 1)
( ) , x0 <  < x
(n+1)!

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Approximations with Different Number of Terms

f(x)
f(x)

Three terms
f(x0+h) ≈ f(x0) + h f ’(x0) + h2/2 f ’’(x0)

Two terms
f(x0+h) ≈ f(x0) + h f ’(x0)

One term
f(x0+h) ≈ f(x0)

x0 x = x0+h x
h
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example 1.

1
Consider the function: f (x)  , x  1
1-x

Taylor Series expansion around a chosen point x 0:

(x - x 0 )2 (x - x 0 )3
f(x)  f(x 0 )  (x - x 0 ) f '(x 0 )  f ''(x 0 )  f '''(x 0 )  ...
2! 3!
(x - x 0 )n (n) (x - x 0 )n1 (n1)
...  f (x 0 )  f ( ) , x0    x
n! (n  1) !

1 2
Derivatives: f ' (x 0 )  f ' ' (x 0 ) 
(1 - x 0 ) 2 (1 - x 0 ) 3

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Approximations to f(x):

1
One term, f (x)  Error  (x - x 0 ) f ' ( )
First Order 1- x0

1 (x - x 0 ) (x - x 0 ) 2
Two terms, f (x)   Error  f ' ' ( )
Second Order 1 - x 0 (1 - x 0 ) 2 2!

Three terms, 1 (x - x 0 ) (x - x 0 ) 2 (x - x 0 ) 3
f (x)   2
 Error  f ' ' ' ( )
Third Order 1 - x 0 (1 - x 0 ) (1 - x 0 ) 3 3!

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example 2. If x0 = 1.6. Estimate f(2) using two terms in the Taylor series
expansion; Find the true and estimated errors

True Error: Etrue (x)  f(x) - P1(x)

f(x) - P1(x)
True Relative Error: Etrue (x)  *100 in percent
f(x)

(x - x 0 )2
Estimated Error: Eest (x)  f ''( )
2!

x f(x) Estimation with True Error Estimated Error


two terms
ξ = 1.6 ξ=2
2 -1.0 -0.55556 0.44444 44.4 % Max Min
0.74 0.16

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

-0.5

-1

-1.5

-2

-2.5

-3

-3.5

-4 1/(1-x)
-1/0.6
-1/0.6+(x-1.6)/0.6**2
-4.5 -1/0.6+(x-1.6)/(0.6)**2+(x-1.6)**2/(-0.6)**3

-5

-5.5
1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2

Error Calculation: Find the error at x = 2


Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example 3.

If one applies integration by parts to the integral


1
yn =  x e x dx
0

defining yn+1, the result is the recurrence relation

yn1 = e - (n + 1) yn

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

n yn ,single
0 1.71828183
1 1.00000000
2 0.71828183
3 0.56343634
4 0.46453647
5 0.39559948
6 0.34468495
7 0.30548718
8 0.27438439
9 0.24882232
10 0.23005863
11 0.18763690
12 0.46663903
13 -3.34802556
14 49.59063967 Why is this happening?
15 -741.14131322
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

n yn ,single yn ,double
0 1.71828183 1.71828183
1 1.00000000 1.00000000
2 0.71828183 0.71828183
3 0.56343634 0.56343634
4 0.46453647 0.46453646 Use double precision
5 0.39559948 0.39559955
all the time
6 0.34468495 0.34468454
7 0.30548718 0.30549004
8 0.27438439 0.27436153
9 0.24882232 0.24902803
10 0.23005863 0.22800152
11 0.18763690 0.21026516
12 0.46663903 0.19509991
13 -3.34802556 0.18198305
14 49.59063967 0.17051906
15 -741.14131322 0.16049585
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example 4.

The “machine epsilon”, ε, of a computer is the smallest positive number in the form
ε = 2-k such that 1.0 +   1.0 . It is also called the unit of round-off error of the
machine. Use the following algorithm to compute an approximate value of ε for the
computer that you intend to use in this course.
input s == 1.0
for k = 1, 2, … 100 do
s == 0.5 * s
t == s + 1.0
if t ≤ 1.0 then
s == 2.0 * s
output k-1 , s
stop
end if
end
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example 5.

 x 
Expand the function f(x) = sin   in Taylor series around the point x0 = 0
 2 
(MacLaurin series). Find the expression for the remainder, and estimate the

number of terms that would be needed to guarantee six significant digit accuracy

for all x in the interval [-1,+1].

Six significant digit accuracy means that the error should be less than or equal to

0.5 10-6.

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

 x  x2 x3 xn (n) xn+1 (n+1)


f(x) = sin   = f(0) + x f'(0) + 2! f''(0) + 3! f'''(0) + ... + n! f (0) + (n+1)! f ( )
 2 

 x     x   x   x
3 5 3 7 5 7

f(x) = sin   = 2 x -  2  3! +  2  5! -  2  7! + ... + R


 2       

   
2n+1
x 2n+1
R =   sin    , -1 <  < 1 n = 1, 2, 3, …
2 (2 n + 1)! 2 

The maximum error is expected to occur at x = 1 and ξ = 1.

For 6 significant digit accuracy, R should be less than 0.5 10-6.

 
2n+1
1
R max =   < 0.5 10-6 Find n.
2 (2 n + 1)!
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

No of non- Rmax
zero terms
1 6.45964 10-1
2 7.96926 10-2 n = 6 is the required number
3 4.68175 10-3 of non-zero terms
4 1.60441 10-4
5 3.59884 10-6
6 5.69217 10-8

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Taylor Series expansion of a function of two variables, f(x,y), around (x 0,y0)

f f
f(x,y)  f(x 0,y0 )  (x - x 0 )  (y - y 0 ) +
x x0 ,y 0 y x0 ,y 0

1  2  f
2
 2f  2f 
(x - x 0 )  (y - y 0 ) 2
+ 2 (x - x 0 ) (y - y0 ) 
2!  x 2 y 2 x y x ,y 
 x0 ,y 0 x0 ,y 0 0 0 

+ ...

Note that these expansions are valid within a radius of convergence, r.

For one-variable case: (x - x 0 ) < r

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example 6.

The Stefan-Boltzmann law states that the radiative energy, Φ, emitted from an
object is given by the relation

Φ = A ε σ T4

where Φ is in Watts, A is the surface area in m2, ε is emissivity, σ is Stephan-


Boltzmann constant equal to 5.67 10-8 W/m2.K4, and T is absolute temperature in
K. Using the general error estimator of the Taylor series, estimate the error in Φ
for a copper sphere with radius r = 0.1 ± 0.01 m, emissivity ε = 0.5 ± 0.05, and
temperature T = 500 ± 20 K. Compare your result with the actual error.

  
Φ(r, ε, T) = 4 π r2 εσ T4 =>  = r +  + T
r  T
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Jožef Štefan
Ludwig Boltzmann
Carinthian Slovene Physicist
Austrian physicist
1835-1893
1844-1906
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Solution of Example 6.
𝜕Φ 𝜕Φ 𝜕Φ
Partial derivatives: = 8 π r ε σ T4 = 4 π r2 σ T4 = 16 π r2 ε σ T3
𝜕𝑟 𝜕ε 𝜕T

Substitute the given values: Φ(r, ε, T) = 222.66 W

𝜕Φ 𝜕Φ 𝜕Φ
= 445.3 = 4453 = 1.781
𝜕ε 𝜕𝑟 𝜕T

  
 = r +  + T = (4453) (0.01) + 445.3) (0.05) + (1.781) (20)
r  T
= 102.42 W

Therefore: Φ(r, ε, T) = 222.66 ∓ 102.42

This is almost 50 % error.

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

APPROXIMATING FUNCTIONS
Objectives:

 Replace a complicated function f(x) with a simpler function g(x) which is easier
to manipulate, i.e. differentiate, integrate, etc. (Note that transcendental
functions, such as ln(x), sin(x), erf(x), etc., cannot be evaluated by strictly
arithmetic operations without first finding approximating, simpler functions
such as a finite power series.)
 Interpolate in tables of functional values

n
Power series: g (x)  Pn (x)   a i x i
i0

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

n n
Fourier Functions: g (x)  a 0   a k cos (k x)   a k sin (k x)
k 1 k 1

n
Exponentials g (x)   a i e bi x
i0

Pn (x) a i xi
Rational Functions g (x)   i0
m Pade approximation
i
Pm (x) i
c x
i0

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Jean Baptiste Joseph Fourier

French Mathematician

1768 – 1830

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

SENSITIVITY and CONDITION

A problem is insensitive, or well-conditioned, if given relative change in the input


causes commensurate relative change in the solution.

A problem is sensitive, or ill-conditioned, if relative change in solution can be much


larger than that in input data.

 _ 
f ( x ) - f (x)  / f (x)
 
Relative Change in solution
Condition Number  _
Relative change in input data
( x - x) / x

Problem is sensitive or ill-conditioned if Condition Number >> 1

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example: Sensitivity

Consider the problem of computing cosine function for arguments near π /2.
Let x ≈ π /2 and let h be a small perturbation to x.
Then, the error in cos(x + h) is given by
Absolute Error = cos(x + h) - cos(x) ≈ - h sin(x) ≈ - h
Relative Error ≈ - h tan(x) ≈ ∞
So, small changes in x near π /2 cause large relative changes in cos(x) regardless
of method for computing it.

Example: cos(1.57079) = 0.63267949 10-5


cos(1.57078) = 1.63267949 10-5
Relative change in output is about a quarter million times greater than relative
change in input.

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example: Condition Number for a Function

When a function, f, is evaluated for an approximate input argument Δx = x + h


instead of true input value x:

Error in the function = f(x + h) - f(x) ≈ Δx f’(x) = h f '(x)


f (x  h) - f (x) f(x) f '(x)
Relative error in the function  =  h
f (x) f(x) f (x)

x
Relative error in the input 
x

h f ' (x ) / f (x) f '(x)


Condition Number = CN =  x
h/x f (x)

Relative error in the functional value can be much larger or smaller than that
(relative error in) the input.
Prof. Dr. Faruk Arınç fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

x
Example 7: Find the condition number, CN, for f(x) =
1-x
(a) When x = 0.93 and
(b) When x = - 0.93
(c) Comment on the results by evaluating f(x) near 0.93 and - 0.93

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

ACCURACY and PRECISION

ACCURACY

How closely computed or measured


values agree with the true value

PRECISION

How closely computed or measured


values agree with each other

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

ERRORS

True Error => usually not known

Estimated Error => approximated

Approximate Error => estimated

Relative (percent) Error => relative to the true error

Deterministic Error => due the measuring instrument

Statistical (stocastic) Error => result of experiments

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

ERRORS

Truncation Error => series representation

Round-off Error => lost precision

Proramming Errors => Syntax error (no compilation)

=> Run-time error (compiles, but stops running)

=> Logical error (compiles and runs, but

the output is wrong)

Read the article «Errors and Error Estimation.pdf» on the Moodle.

Prof. Dr. Faruk Arınç fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Prof. Dr. Faruk Arınç fall 2020

You might also like