You are on page 1of 57

a home base to excellence

Mata Kuliah : Analisis Numerik dan Pemrograman


Kode : TSP – 303
SKS : 3 SKS

Pengenalan Awal Metode Numerik


Pertemuan - 1
a home base to excellence

• TIU :
 Mahasiswa dapat mencari akar-akar suatu persamaan, menyelesaikan
persamaan aljabar linear, pencocokan kurva, dan membuat program
aplikasi analisis numeriknya

• TIK :
 Mahasiswa dapatmemberikan definisi tentang analisis numerik dan
tingkat ketelitian dari perhitungan dengan solusi numerik
a home base to excellence

• Sub Pokok Bahasan :


 Definisi metode numerik dan analisis
numerik
 Nilai bena, tingkat ketelitian dan error
• Text Book :
• Chapra, S., Canale, R.P. (2010). Numerical
Methods for Engineers. 6th ed. Mc Graw
Hill, Inc.
• Setiawan, A. (2007). Pengantar Metode
Numerik. 2nd ed. Penerbit Andi

• Bobot Penilaian :
• Tugas : 25 %
• Ujian Tengah Semester : 30%
• Ujian Akhir Semester : 45%
a home base to excellence

What are Numerical Methods?


• Techniques by which mathematical problems
are formulated so that they can be solved
with arithmetic operations {+,-,* /} , that can
then be performed by a computer.
a home base to excellence

Why You Need to Learn Numerical Methods?


• During your career, you may often need to use commercial
computer programs (canned programs) that involve numerical
methods. You need to know the basic theory of numerical
methods in order to be a better user.
• Numerical methods are extremely powerful problem-solving tools.
• You will often encounter problems that cannot be solved by
existing canned programs; you must write your own program of
numerical methods.
• Numerical methods are an efficient vehicle forlearning to use
computers.
• Numerical methods provide a good opportunity for you to
reinforce your understanding of mathematics.
• You need that in your life as an engineer or a scientist
a home base to excellence

Problems to solve in this course


Roots of equations:concerns with finding the value
of a variable that satisfies a single nonlinear
equation – especial valuable in engineering design
where it is often impossible to explicitly solve design
equations of parameters.

Systems of linear equations: a set of values is sought


that simultaneously satisfies a set of linear algebraic
equations. They arise in all disciplines of engineering,
e.g., structure, electric circuits, fluid networks; also
in curve fitting and differential equations.

Optimization:determine a value or values of an


i depe de t a ia le that o espo d to a est o
independent variable that correspond to a best or
optimal value of a function.It occurs routinely in
engineering contexts. (not in this course)
a home base to excellence

Problems to solve in this course


Curve fitting: to fit curves to data points.
Two types: regressionand interpolation.
Experimental results are often of the first
type.

Integration : determination of the area or


volume under a curve or a surface. It has
many applications in engineering practice.
a home base to excellence

Mathematical Modeling and Engineering


Problem solving
• Requires understanding of engineering systems
– By observation and experiment(empiricism)
– Theoretical analysis and generalization
These two are closely coupled (with a two way
connection as one compliments the other).
• Computers are great tools, however, without
fundamental understanding of engineering problems,
they will be useless.
a home base to excellence

The engineering
problem solving
process
a home base to excellence

• A mathematical model is represented as a functional relationship


of the form:

• Dependent variable: Characteristic that usually reflects the state


of the system
• Independent variables: Dimensions such as time and space along
which the systems behavior is being determined
• Parameters : efle t the s ste ’s p ope ties o o positio
• Forcing functions : external influences acting upon the system
a home base to excellence

Exa ple : Ne to ’s nd law of Motion


• States that the time rate change of momentum
of a body is equal to the resulting force acting on
it
• The model is formulated as
F=ma
• F = net force acting on the body (N)
• m= mass of the object (kg)
• a = its acceleration (m/s2)
a home base to excellence

Formulation of Ne to ’s 2nd law has several characteristics that


are typical of mathematical models of the physical world :
• It describes a natural process or system in mathematical
terms
• It represents an idealization and simplification of reality
(focuses on its essential manifestations).
• Finally it yields reproducible results consequently can be
used for predictive purposes, e.g.
F
a
m
a home base to excellence

• Some mathematical models of


physical phenomena may be
much more complex.
• Complex models may not be
solved exactly or require more
sophisticated mathematical
techniques than simple algebra
for their solution.
• Example : modeling of a falling
FD is the downward
parachutist force due to gravity. FU is
the upward force due to
air resistance
a home base to excellence

• A model for this falling parachutist case can


be derived by expressing the acceleration as
the time rate of change of the velocity (dv/dt)
dv F v = terminal velocity (m/s)
 F  FD  FU
dt m t = time (s)
FD  mg m = mass of the object (kg)
dv mg  cv
 FU  cv
g = gravitational constant
dt m c = drag coefficient (kg/s)
a home base to excellence

• Finally : dv c
g v
dt m
• This is a differential equation and is written in
terms of the differential rate of change dv/dt of
the variable that we are interested in predicting
• The exact solution for the velocity of the falling
parachutist cannot be obtained using simple
algebraic manipulation.
• Rather, more advanced techniques such as those
of calculus, must be applied to obtain an exact or
analytical solution.
a home base to excellence

• For example, if the parachutist is initially at


rest (v=0 at t =0), calculus can be used to
solve the equation for :

vt  
gm
c

1 e  c / m t
 (1)
Independent variable
Dependent variable Parameters
Forcing function
a home base to excellence

• Solution for differential equation cannot


always be solved analytically using simple
algebraic solution.
• The exact solution for differential equation
can be solved using calculus or by
approximation using numerical methods.
a home base to excellence

Example 1 :
A parachutist of mass 68,1 kg
jumps out a stationary hot air
balloon. Compute velocity prior to
opening the chute. The drag
coefficient is equal to 12.5 kg/s.
Inserting the parameters into the
equation (1) above yields :

vt  
9 ,8  68,1
12 ,5
  
1  e 12 ,5 / 68 ,1t  53,39 1  e 0 ,18355t 
a home base to excellence

• As mentioned previously,
numerical methods are those in
which the mathematical problem
is reformulated so it can be solved
by arithmetic operations.
• This can be illustrated for
Ne to ’s second law by realizing
that the time rate of change of
velocity can be approximated by

dv v vti 1   vti 
  (2) dv v
dt t ti 1  ti Remember :  lim
dt t 0 t
a home base to excellence

• Equation (2) is called a finite divided


difference approximation of the derivative at
time ti. Substitute (2) to (1) give :
vti 1   vti 
 g   vti 
c
ti 1  ti m

• Rearranged to yield :
 
vti 1   vti    g  vti  ti 1  ti 
c
(3)
 m 
this app oa h is fo all alled Eule ’s ethod
a home base to excellence

Example 2 :
Perform the same computation as in Example 1 but use
Equation (3) to compute the velocity. Employ a step size of 2 s
for the calculation.
At the start of the computation (ti =0), the velocity of the
parachutist is zero.
Using this information and the parameter values from Example
1, Eq. (3) can be used to compute velocity at ti+1=2s:
 12 ,5 
vt  2   0  9 ,8  0 2  19,60 m/s
 68,1 
a home base to excellence

Example 2 :
For the next interval (from t =2to 4 s), the computation is
repeated, with the result :

vt  4   19 ,60  9 ,8 
12 ,5
19,60 2  32,00 m/s
 68,1 
a home base to excellence

Approximations and Round-Off Errors


• Although the numerical technique yielded estimates that
were close to the exact analytical solution, there was a
discrepancy, or error, because the numerical method
involved an approximation.
• Actually, we were fortunate in that case because the
availability of an analytical solution allowed us to compute
the error exactly.
• For many applied engineering problems, we cannot obtain
analytical solutions.
• Therefore, we cannot compute exactly the errors associated
with our numerical methods.
• In these cases, we must settle for approximations or
estimates of the errors
a home base to excellence

• Significant Figure
a home base to excellence

• The significant digits of a number are those that can be


used with confidence.
• They correspond to the number of certain digits plus one
estimated digit.
• For example, the speedometer and the odometer yield
readings of three and seven significant figures,
respectively.
• For the speedometer, the two certain digits are 48. It is
conventional to set the estimated digit at one-half of the
smallest scale division on the measurement device. Thus
the speedometer reading would consist of the three
significant figures: 48.5.
• In a similar fashion, the odometer would yield a seven-
significant-figure reading of 87,324.45
a home base to excellence

The concept of significant figures has two important implications for our
study of numerical methods:
1. As introduced in the falling parachutist problem, numerical methods
yield approximate results. We must, therefore, develop criteria to
specify how confident we are in our approximate result. One way to do
this is in terms of significant figures. For example, we might decide that
our approximation is acceptable if it is correct to four significant figures.
2. Although ua tities su h as π, e, o √ ep ese t specific quantities,
they cannot be expressed exactly by a limited number of digits. For
e a ple, π= . ...
Because computers retain only a finite number of significant figures, such
numbers can never be represented exactly. The omission of the remaining
significant figures is called round-off error.
a home base to excellence

• Accuracy. How close is a


computed or measured value
to the true value
• Precision (or reproducibility).
How close is a computed or
measured value to previously
Computed or measured values.
• Inaccuracy (or bias). A
systematic deviation from the
actual value
• Imprecision (or uncertainty).
Magnitude of scatter.

(a) Inaccurate and imprecise; (b) accurate and


imprecise; (c) inaccurate and precise; (d)
accurate and precise.
a home base to excellence

• In numerical methods , we use approximation, to represent


the exact mathematical operations.
• Numerical error is equal to the discrepancy between the
truth and the approximation
Et = true alue−approximation (4)
• where Et is the exact value of the error.
• The relative error can also be multiplied by 100 percent to
express it as
true error
t   100%
true value (5)
• where εt designates the true percent relative error
a home base to excellence

Example 3 :
Suppose that you have the task of measuring
the lengths of a bridge and a rivet and come up
with 9999 and 9 cm, respectively. If the true
values are 10,000 and 10 cm, respectively,
compute (a) the true error and (b) the true
percent relative error for each case.
a home base to excellence

If we cannot solved the problem


analytically to get the true value, how to
calculate its true error?
• We normalize the error to approximate value.
• Numerical methods use iterative approach to
compute answers.
• A present approximation is made on the basis
of a previous approximation.
a home base to excellence

• Percent relative error, a


current approximation - previous approximation
a   100% (6)
current approximation

• The signs of Eqs. (6) may be either positive or negative.


• Often, when performing computations, we may not be
concerned with the sign of the error, but we are interested
in whether the percent absolute value is lower than a
p espe ified pe e t tole a e εs.
• Therefore, it is often useful to employ the absolute value
of Eqs. (6).
• For such cases, the computation is repeated until
|εa|< εs
a home base to excellence

• It is also convenient to relate these errors to


the number of significant figures in the
approximation.
• It can be shown (Scarborough, 1966) that if
the following criterion is met, we can be
assured that the result is correct to at least n
significant figures.
 
 s  0,5  10 2 n %
a home base to excellence

Example 4 :
• In mathematics, functions can often be represented by
infinite series. For example, the exponential function can be
computed using Maclaurin series expansion
x 2 x3 xn
e  1 x 
x
  ... 
2 3! n!

• Estimate the value of e0,5.


• Add terms until the absolute value of the approximate error
estimate εa falls below a pre specified error criterion εs
conforming to three significant figures.
• Note that the true value is e0.5= . 4 …
a home base to excellence

Mata Kuliah : Analisis Numerik dan Pemrograman


Kode : TSP – 303
SKS : 3 SKS

Metode Terbuka
(Open Methods)
Pertemuan - 3
a home base to excellence

• TIU :
 Mahasiswa dapat mencari akar-akar suatu persamaan, menyelesaikan
persamaan aljabar linear, pencocokan kurva, dan membuat program
aplikasi analisis numeriknya

• TIK :
 Mahasiswa dapat menjelaskan Metode Terbuka (Open Methods)
untuk menyelesaikan permasalahan akar-akar persamaan
a home base to excellence

• Sub Pokok Bahasan :


 Simple Fixed-Point Iteration
 Metode Newton-Raphson
 Metode Secant
 Kelemahan dan Kelebihan dari metode tersebut
a home base to excellence

• For the bracketing methods, the root is located within


an interval prescribed by a lower and an upper bound.
• Repeated application of these methods always results
in closer estimates of the true value of the root.
• Such methods are said to be convergent because they
move closer to the truth as the computation
progresses
• In contrast, the open methods are based on formulas
that require only a single starting value of x or two
starting values that do not necessarily bracket the root
a home base to excellence

• As such, they
sometimes diverge or
move away from the
true root as the
computation
progresses (Fig. b).
• However, when the
open methods
converge (Fig. c), they
usually do so much
more quickly than the
bracketing methods.
a home base to excellence

Simple Fixed-Point Iteration


• Open methods employ a formula to predict
the root.
• Such a formula can be developed for simple
fixed-point iteration (or, as it is also called,
one-point iteration or successive substitution)
by rearranging the function f(x)=0 so that x is
on the left-hand side of the equation:
x=g(x) (1)
a home base to excellence

• This transformation can be accomplished


either by algebraic manipulation or by simply
adding x to both sides of the original
equation.
• For example,
x2  3
x  2x  3  0
2
x
2

sin x  0 x  sin x  x
a home base to excellence

• The utility of Eq. (1) is that it provides a formula to predict a


new value of x as a function of an old value of x.
• Thus, given an initial guess at the root xi, Eq. (1) can be used
to compute a new estimate xi+1 as expressed by the iterative
formula

xi+1= g(xi) (2)


• the approximate error for this equation can be determined
using the error estimator

xi 1  xi
a   100%
xi 1
a home base to excellence

Example 1 :
Use simple fixed-point iteration to locate the
root of f(x)=e−x− x
The function can be separated directly and expressed
in the form
xi+1=e−xi
a home base to excellence

• Starting with an initial guess of x0=0, this


iterative equation can be applied to compute
Iteration xi g(xi)  a (%)  t (%)
0 0 1
1 1 0,36788 100
2
3
4
5 the true value of
6 the root: 0.56714329.
7
8
9
10
a home base to excellence

The Newton-Raphson Method


• Perhaps the most widely
used of all root-locating
formulas is the Newton-
Raphson equation.
• If the initial guess at the
root is xi, a tangent can be
extended from the point
[xi, f(xi)].
• The point where this
tangent crosses the x axis
usually represents an
improved estimate of the
root.
a home base to excellence

• the first derivative at x is equivalent to the


slope
f  xi   0
f  xi  

xi  xi 1

• Which can be rearranged to yield Newton-


Raphson formula :
f  xi 
xi 1  xi 
f xi 
(3)
a home base to excellence

Example 2 :
Use the Newton-Raphson method to estimate
the root of f(x)=e−x− x, employing an initial
guess of x0 = 0
The first derivative of the function can be evaluated as
f(x = −e− − , hi h can be substituted along with the
original function into Eq. (3) to give
e  xi  xi
xi 1  xi   xi
e 1
a home base to excellence

• Starting with an initial guess of x0=0, this iterative


equation can be applied to compute

 a (%)  t (%)
/
Iterasi xi f(x i ) f (x i )
1 0 1 -2
2 0,5 0,1065 -1,607
3 0,5663 0,0013 -1,568
4
5

the true value of


the root: 0.56714329.
a home base to excellence

• Although the Newton-Raphson method is


often very efficient, there are situations
where it performs poorly.
• Fig. a depicts the case where an inflection
point [that is, f’’ = ] o urs in the i init
of a root.
• Fig. b illustrates the tendency of the
Newton-Raphson technique to oscillate
around a local maximum or minimum.
• Fig. c shows how an initial guess that is
close to one root can jump to a location
several roots away.
• O iousl , a zero slope [f’ = ] is trul a
disaster because it causes division by zero
in the Newton-Raphson formula (see Fig d)
a home base to excellence

The Secant Method


• A potential problem in implementing the
Newton-Raphson method is the evaluation of
the derivative.
• Although this is not inconvenient for polynomials
and many other functions, there are certain
functions whose derivatives may be extremely
difficult or inconvenient to evaluate.
• For these cases, the derivative can be
approximated by a backward finite divided
difference, as in the following figure
a home base to excellence

f xi 1   f xi 
f xi  
xi 1  xi
This approximation can be
substituted into Eq. (3) to
yield the following iterative
equation:
f xi   xi 1  xi 
xi 1  xi  (4)
f xi 1   f xi 
a home base to excellence

• Equation (4) is the formula for the secant


method.
• Notice that the approach requires two initial
estimates of x.
• However, because f(x) is not required to
change signs between the estimates, it is not
classified as a bracketing method.
a home base to excellence

Example 3 :
Use the Secant method to estimate the root of
f(x)=e−x− x, employing an initial guess of x0 = 0
Start with initial estimates of x−1 =0 and x0= 1.0.

Iteration x i-1 xi x i+1 f(x i-1 ) f(x i )  a (%)


0 0 1 0,6127 1 -0,632
1 1 0,6127 0,5638 -0,632 -0,071 -8,666
2
3
4
5
a home base to excellence

The Difference Between the Secant and False-Position


Methods
False-Position Formula Secant Formula

f xu xl  xu  f xi   xi 1  xi 


xr  xu  xi 1  xi 
f xl   f xu  f xi 1   f xi 

• The Eqs. Above are identical on a term-by-term basis.


• Both use two initial estimates to compute an
approximation of the slope of the function that is used to
project to the x axis for a new estimate of the root.
• However, a critical difference between the methods is how
one of the initial values is replaced by the new estimate.
a home base to excellence

• Recall that in the false-position method the


latest estimate of the root replaces
whichever of the original values yielded a
function value with the same sign as f(xr).
• Consequently, the two estimates always
bracket the root.
• Therefore, the method always converges
• In contrast, the secant method replaces the
values in strict sequence, with the new
value xi+1 replacing xi and xi replacing xi− .
• As a result, the two values can sometimes
lie on the same side of the root.
• For certain cases, this can lead to
divergence.
a home base to excellence

Homework

Use : Simple Fixed-Point Iteration Method (x = g(x))


a home base to excellence

Homework

Use Secant Method


a home base to excellence

Homework

Use Newton Raphson Method

You might also like