0% found this document useful (0 votes)
63 views34 pages

Metode Euler

Euler's method is a numerical method for solving differential equations by approximating the solution as linear between time steps. It works by: 1) Approximating the slope of the solution curve at the initial point using the differential equation. 2) Using this slope to estimate the solution at a nearby point as the point on the tangent line. 3) Repeating to generate a sequence of approximations at increasing time steps. The accuracy depends on the step size - smaller steps provide a better approximation at the cost of more computations. Euler's method is simple to implement and provides reasonably accurate solutions for many differential equations.

Uploaded by

x boba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views34 pages

Metode Euler

Euler's method is a numerical method for solving differential equations by approximating the solution as linear between time steps. It works by: 1) Approximating the slope of the solution curve at the initial point using the differential equation. 2) Using this slope to estimate the solution at a nearby point as the point on the tangent line. 3) Repeating to generate a sequence of approximations at increasing time steps. The accuracy depends on the step size - smaller steps provide a better approximation at the cost of more computations. Euler's method is simple to implement and provides reasonably accurate solutions for many differential equations.

Uploaded by

x boba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Euler’s Method

Metode Numerik
Genap 2022/2023
Euler’s Method: Tangent Line Approximation
• Recall that a first order initial value problem has the form
dy
 f (t , y ), y (t0 )  y0
dt

• If f and f /y are continuous, then this IVP has a unique


solution y = (t) in some interval about t0.
• When the differential equation is linear, separable or exact, we
can find the solution by symbolic manipulations.
• However, the solutions for most differential equations of this
form cannot be found by analytical means.
• Therefore it is important to be able to approach the problem in
other ways.
› For our first order initial value problem

y  f (t , y ), y (t0 )  y0 ,
an alternative is to compute approximate values
of the solution y = (t) at a selected set of t-
values.
› Ideally, the approximate solution values will be
accompanied by error bounds that ensure the
level of accuracy.
› There are many numerical methods that
produce numerical approximations to solutions
of differential equations. Euler, Léonard
› In this section, we examine the tangent line 1707-1783
method, which is also called Euler’s Method.
Euler’s Method: Tangent Line Approximation
• For the initial value problem y  f (t , y ), y (t0 )  y0 ,
we begin by approximating solution y = (t) at initial point t0.
• The solution passes through initial point (t0, y0) with slope
f (t0, y0).
y  y0  f t0 , y0 t  t0 
• The line tangent to solution at initial point is thus
• The tangent line is a good approximation to solution curve on an
interval short enough.
• Thus if t1 is close enough to t0,
we can approximate (t1) by

y1  y0  f t0 , y0 t1  t0 
Euler’s Formula
› For a point t2 close to t1, we approximate (t2) using the line
passing through (t1, y1) with slope f (t1, y1):
y2  y1  f t1 , y1 t 2  t1 
› Thus we create a sequence yn of approximations to (tn):

y1  y0  f 0  t1  t0 
y2  y1  f1  t 2  t1 

yn 1  yn  f n  t n 1  t n 

where fn = f (tn, yn).


› For a uniform step size h = tn – tn-1, Euler’s formula
becomes
yn 1  yn  f n h, n  0,1, 2,
Euler Approximation
› To graph an Euler approximation, we plot the points
(t0, y0), (t1, y1),…, (tn, yn), and then connect these points with line
segments.
yn 1  yn  f n  t n 1  t n , where f n  f t n , yn 
Euler Method: Integral Equation
› We could write problem as an integral equation. That is, since y =
(t) is a solution of y' = f (t, y), y(t0) = y0, we have
f t ,  (t ) dt
t n1 t n1
tn
 (t )dt  
tn

or
f t ,  (t ) dt
t n 1
 (t n 1 )   (t n )  
tn

› Approximating the above integral


we obtain
 (t n 1 )   (tn )  f t n ,  (t n )  t n 1  t n 

› Replacing (tn+1) and (tn) by their approximate values yn+1 and yn,
we obtain Euler’s formula:
yn 1  yn  f (t n , yn )  t n 1  tn , n  0,1, 2, 
 (t n 1 )   (t n )  f t n ,  (t n )  t n 1  t n 

yn 1  yn  f (t n , yn )  t n 1  t n , n  0,1, 2, 
Euler Methods: Taylor Series
› A third approach is to assume the solution y = (t) has a Taylor
series about t = tn. Then
1
 (t )   (tn )   (t n ) t  t n    (t n ) t  t n 2  
2!
› Since h = tn+1 – tn and ' = f (t, ), it follows that
1
 (t n 1 )   (t n )  f t n ,  (t n ) h   (t n )h 2  
2!
› If the series is terminated after the first two terms, and if we replace
(tn+1) and (tn) by their approximations yn+1 and yn, then once again
we obtain Euler’s formula:
yn 1  yn  f (t n , yn )  t n 1  t n , n  0,1, 2,
› Further, using a Taylor series with remainder, we can estimate the
magnitude of error in this formula (later in this section).
Example 1: Euler’s Method
› For the initial value problem
y  9.8  0.2 y, y (0)  0
we can use Euler’s method with h = 0.1 to
approximate the solution at t = 0.1, 0.2, 0.3, 0.4, as
shown
y1 below.
y0  f 0  h  0  9.8(0.1)  .98
y2  y1  f1  h  .98  9.8  0.2 .98(0.1)  1.94
y3  y2  f 2  h  1.94  9.8  0.2 1.94(0.1)  2.88
y4  y3  f 3  h  2.88  9.8  0.2 2.88(0.1)  3.80
We can find the exact solution to our IVP
y  9.8  0.2 y, y (0)  0
y  0.2 y  49 
dy
 0.2dt
y  49
ln y  49  0.2t  C
y  49  ke 0.2t , k  e C
y (0)  1  k  49
 y  491  e 0.2t 
Example 1: Error Analysis
› From table below, we see that the errors are small.
› This is most likely due to round-off error and the fact that the exact
solution is approximately linear on [0, 0.4].
› Note: yexact  yapprox
Percent Relative Error  100
yexact

t Exact y Approx y Error % Rel Error


0.00 0 0.00 0.00 0.00
0.10 0.97 0.98 -0.01 -1.03
0.20 1.92 1.94 -0.02 -1.04
0.30 2.85 2.88 -0.03 -1.05
0.40 3.77 3.8 -0.03 -0.80
Example 2: Euler’s Method
› For the initial value problem
y   4  t  2 y , y ( 0)  1
we can use Euler’s method with h = 0.1 to approximate the solution
at t = 1, 2, 3, and 4, as shown below.
y1  y0  f 0  h  1  4  0  (2)(1) (0.1)  1.6
y2  y1  f1  h  1.6  4  0.1  (2)(1.6) (0.1)  2.31
y3  y2  f 2  h  2.31  4  0.2  (2)(2.31) (0.1)  3.15
y4  y3  f 3  h  3.15  4  0.3  (2)(3.15) (0.1)  4.15

› Exact solution 7 1 11
y    t  e 2t
4 2 4
Example 2: Error Analysis
› The first ten Euler approxs are given in table below on left. A table of
approximations for t = 0, 1, 2, 3 is given on right. (Find for numerical
results with h = 0.05, 0.025, 0.01).
› The errors are small initially, but quickly reach an unacceptable level.
This suggests a nonlinear solution.
t Exact y Approx y Error % Rel Error t Exact y Approx y Error % Rel Error
0.00 1.00 1.00 0.00 0.00 0.00 1.00 1.00 0.00 0.00
0.10 1.66 1.60 0.06 3.55 1.00 19.07 15.78 3.29 17.27
0.20 2.45 2.31 0.14 5.81 2.00 149.39 104.68 44.72 29.93
0.30 3.41 3.15 0.26 7.59 3.00 1109.18 652.53 456.64 41.17
0.40 4.57 4.15 0.42 9.14 4.00 8197.88 4042.12 4155.76 50.69
0.50 5.98 5.34 0.63 10.58
0.60 7.68 6.76 0.92 11.96
0.70 9.75 8.45 1.30 13.31 Exact Solution :
0.80 12.27 10.47 1.80 14.64 7 1 11
0.90 15.34 12.89 2.45 15.96 y    t  e 2t
1.00 19.07 15.78 3.29 17.27
4 2 4
Example 2: Error Analysis & Graphs

t Exact y Approx y Error % Rel Error


0.00 1.00 1.00 0.00 0.00
1.00 19.07 15.78 3.29 17.27
2.00 149.39 104.68 44.72 29.93
3.00 1109.18 652.53 456.64 41.17
4.00 8197.88 4042.12 4155.76 50.69

7 1 11 2t
Exact Solution : y    t  e
4 2 4
Example 2: Error Analysis & Graphs
The exact solution (red) plotted together with the Euler
approximation (blue).

exact
solution
exact
solution

Euler app.

Euler app.
Example 3:
dy
 x  y; y (0)  0
dx
a) Tentukan y(0.1) dengan langkah h = 0.02 dan h = 0.05 .
b) Jika diketahui
langkah mana yang lebih teliti ?

y ( x)  e x  x  1

19
h = 0.05
x=0 y(0) = 0
x = 0.05 y(0.05) = 0 + 0.05(0+0) = 0
x = 0.1 y(0.1) = 0 + 0.05(0.05+0) = 0.0025

h = 0.02
x=0 y(0) = 0
x = 0.02 y(0.02) = 0 + 0.02(0+0) = 0
x = 0.04 y(0.04) = 0 + 0.02(0.02+0) = 0.0004
x = 0.06 y(0.06) = 0.004 +0.02(0.04+0.004) = 0.001208
x = 0.08 y(0.08) = 0.001208 +0.02(0.06+0.001208) = 0.00243216
x = 0.1 y(0.1) = 0.00243216 + 0.02(0.08+0.00243216)
= 0.0040808032
y(0.1) = e0.1-0.1-1 = 0.00517091807564762
Langkah h = 0.02 lebih teliti
20
Nilai hanya bergantung pada nilai-nilai
dan nilai . Dengan menggunakan syarat awal
nilai-nilai fungsi untuk
i = 1,2,3,… dapat ditentukan.

Metode Euler eksplisit diturunkan dari deret


Taylor dengan membuang suku orde dua

kesalahan pemotongan
2
lokal orde keduaO(h )
kesalahan pemotongan global O(h)
21
Besar dan sifat kesalahan pemotongan pada metode Euler dapat dijelaskan
dari deret Taylor.

Local Truncation Error for Euler Method


• Assume that y = (t) is a solution to ' = f (t, ), y(t0) = y0 and that
f, ft and fy are continuous. Then '' is continuous, where
 (t )  f t t ,  (t )   f y t ,  ( t )  f t ,  (t ) 
• Using a Taylor polynomial with a remainder to expand (t) about t
= tn, we have
1
 ( t )   ( t n )   ( t n )  t  t n  
 ( n )  t  t n 2
2!
where n is some point in the interval tn < n < tn+1.

• Since h = tn+1 – tn and ' = f (t, ), it follows that


1
 (t n 1 )   (t n )  f t n ,  (t n ) h   ( n )h 2
2!
Local Truncation Error for Euler Method
• From the previous slide, we have
1
 (t n 1 )   (t n )  f t n ,  (t n ) h   ( n )h 2
2!
• Recalling the Euler formula
yn 1  yn  f (t n , yn )h,
• it follows that
1
 (t n 1 )  yn 1   (t n )  yn    f t n ,  (t n )   f (t n , yn )h   ( n )h 2
2!
• To compute the local truncation error en+1 , we take yn =
(tn) and hence
1
en 1   (t n 1 )  yn 1   ( n )h 2
2!
Error Analysis
(Geometric Interpretation)
dy
 f ( x, y ), y ( x0 )  y0
dx
y dy
  f ( x, y )
x dx
y  f ( x, y )x
y1  y0  y  f ( x0 , y0 )x

 y1  y0  f ( x0 , y0 )x

Think in
terms of
Taylor’s If the true solution were a straight line, then
expansion Euler is exact
24
Error Analysis
(From Taylor’s Expansion)

y ( x  x)  y ( x)  y( x)x  y( x) 2x  y( x) 6x  


2 3

 y ( x )  f ( x , y ) x  d
dx f ( x, y ) x 2
2 
Euler’s
Euler’s truncation error
O(x2) per step

1st order method

25
Cumulative Error
y




x
Remark:
x=0 x Error 
x=T
But computation time

Number of steps = T/x


Cumulative Err. = (T/x)  O(x2) = O(x) 26
Example 4

dengan syarat awal


2
Penyelesaian eksak: .
(1+𝑒 −2𝑡 )

Interval dibagi menjadi N = 20


subinterval yang sama besar, ambil .
Nilai-nilai fungsi 𝑛 , n = 1,2,3, …
dihitung menggunakan skema Euler:

𝑖+1 𝑖 𝑖 𝑖 , dengan i = 1,2,3,.....


27
 1 0 0 0

 2 1 1 1

 3 2 2 2

5
 dan seterusnya.

28
Euler kesalahan
t eksak
eksplisit mutlak -1
0.0 -2.000 -2.000 0.000
0.1 -1.900 -1.900 0.000 -1.2
0.2 -1.801 -1.803 0.002 -1.4
0.3 -1.705 -1.709 0.004

y
0.4 -1.614 -1.620 0.006 -1.6
0.5 -1.529 -1.538 0.009
-1.8
0.6 -1.451 -1.463 0.012
0.7 -1.381 -1.396 0.015 -2
0.8 -1.319 -1.336 0.017 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
t
0.9 -1.266 -1.284 0.018
1.0 -1.220 -1.238 0.019
0.02
1.1 -1.180 -1.200 0.019
1.2 -1.148 -1.166 0.019
0.015
1.3 -1.120 -1.138 0.018
1.4 -1.098 -1.115 0.017
0.01

e rro r
1.5 -1.079 -1.095 0.016
1.6 -1.064 -1.078 0.014
1.7 -1.052 -1.065 0.013 0.005
1.8 -1.041 -1.053 0.012
1.9 -1.033 -1.044 0.010 0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
2.0 -1.027 -1.036 0.009 t
Backward Euler Formula
• The backward Euler formula is derived as follows. Let y = (t) be the
solution of y' = f (t, y). At t = tn, we have
   f t n ,  (t n ) 
• Using a backward difference quotient for ', it follows that
 (tn )   (t n 1 )
 f t n ,  (t n ) 
t n  t n 1
• Replacing (tn) and (tn -1) by their approximations yn and yn-1, and solving
for yn, we obtain the backward Euler formula
yn  yn 1  f (t n , yn )  h  yn 1  yn  f (t n 1 , yn 1 )  h
• Note that this equation implicitly defines yn+1, and must be solved in
order to determine the value of yn+1.
Metode Euler implisit juga dapat diturunkan melalui deret Taylor
:
2
′ ′′
𝑖−1 𝑖 𝑖 𝑖


(suku orde kedua
dihilangkan)

, dengan i = 1,2,3,.......

31
Skema yang implisit :
nilai bergantung pada nilai-nilai dan
nilai

Skema numerik Euler implisit persamaan nonlinear

penyelesaiannya memerlukan prosedur untuk


menyelesaikan persamaan nonlinear, misalnya
metode iterasi titik tetap, metode bagi dua,
metode Newton, dll.

32
Metode Euler implisit diturunkan dari deret Taylor
dengan membuang suku orde dua

Kesalahan pemotongan metode Euler implisit


kesalahan pemotongan lokal: orde kedua:
kesalahan pemotongan global:orde pertama atau

33
0.02

0.018

0.016

0.014

0.012

0.01

0.008

0.006

0.004 Euler eksplisit; h = 0.1


Euler implisit; h = 0.1
0.002

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
t

Gambar: Perbandingan kesalahan mutlak metode Euler eksplisit dan


implisit dalam menyelesaikan Example 4 dengan h = 0.1.

You might also like