Professional Documents
Culture Documents
Clase 2 Calculo Numerico II - PGRA - 2024 - 1
Clase 2 Calculo Numerico II - PGRA - 2024 - 1
IF-392
Semana 02
Dr. Pierre Giovanny Ramos Apestegui
2
Local Truncation Error O(h )
Global Truncation Error O(h)
Cálculo Numérico II-IF392
Introduction
Problem to be solved is a first order ODE :
y ( x) = f ( x, y ), y ( x0 ) = y0
yi +1 = yi + h f ( x 1 ,y 1 )
i+ i+
2 2
( xi , yi )
x0 x 1 xi +1
i+
2
h
y 1 = yi + f ( xi , yi ) , yi +1 = yi + h f ( x 1 ,y 1 )
i+ 2 i+ i+
2 2 2
Cálculo Numérico II-IF392
Midpoint Method
slope = f ( xi , yi )
( xi , yi )
x0 x 1 xi +1
i+
2
h
y 1 = yi + f ( xi , yi ) , yi +1 = yi + h f ( x 1 ,y 1 )
i+ 2 i+ i+
2 2 2
Cálculo Numérico II-IF392
Midpoint Method
(x ,y )
slope = f ( xi , yi )
1 1
i+ i+
2 2
( xi , yi )
x0 x 1 xi +1
i+
2
h
y 1 = yi + f ( xi , yi ) , yi +1 = yi + h f ( x 1 ,y 1 )
i+ 2 i+ i+
2 2 2
Cálculo Numérico II-IF392
Midpoint Method
slope = f ( x 1 ,y 1 )
i+ i+
(x 1 ,y 1 ) 2 2
i+ i+
2 2
( xi , yi )
x0 x 1 xi +1
i+
2
h
y 1 = yi + f ( xi , yi ) , yi +1 = yi + h f ( x 1 ,y 1 )
i+ 2 i+ i+
2 2 2
Cálculo Numérico II-IF392
Midpoint Method
slope = f ( x 1 ,y 1 )
i+ i+
(x 1 ,y 1 ) 2 2
i+ i+
2 2
( xi , yi )
x0 x 1 xi +1
i+
2
h
y 1 = yi + f ( xi , yi ) , yi +1 = yi + h f ( x 1 ,y 1 )
i+ 2 i+ i+
2 2 2
Cálculo Numérico II-IF392
Example 1
y (0) = 1
Use h = 0.1. Determine y(0.1) and y(0.2)
1
Average derivative= 𝑓 𝑥0 , 𝑦0 + 𝑓 𝑥1 , 𝑦1
2
Corrector : yi1+1 = yi +
h
2
(
f ( xi , yi ) + f ( xi +1, yi0+1 ) )
( xi +1 , yi0+1 )
( xi , yi )
xi xi +1
Prediction 0
yi +1 = yi + h f ( xi , yi )
Cálculo Numérico II-IF392
Heun’s Predictor Corrector
(Prediction)
( xi +1 , yi0+1 )
slope = f ( xi +1 , yi0+1 )
( xi , yi )
xi xi +1
Prediction y 0
i +1 = yi + h f ( xi , yi )
Cálculo Numérico II-IF392
Heun’s Predictor Corrector
(Correction)
f ( xi , yi ) + f ( xi +1 , yi0+1 )
slope =
2
( xi +1 , yi0+1 )
( xi , yi ) ( xi +1 , yi1+1 )
xi xi +1
y1
i +1 = yi +
h
2
(
f ( xi , yi ) + f ( xi +1 , yi0+1 ) )
Cálculo Numérico II-IF392
Example 2
Use the Heun' s Method to solve the ODE
y ( x) = 1 + x + y
2
y (0) = 1
Use h = 0.1. One correction only
Determine y(0.1) and y(0.2)
Step 1 :
Predictor : y10 = y0 + h f ( x0 , y0 ) = 1 + 0.1(2) = 1.2
Corrector : y = y0 +
1
1
h
2
( )
f ( x0 , y0 ) + f ( x1 , y10 ) = 1.2105
Step 2 :
Predictor : y20 = y1 + h f ( x1 , y1 ) = 1.4326
Corrector : y = y1 +
1
2
h
2
( )
f ( x1 , y1 ) + f ( x2 , y20 ) = 1.4452
Cálculo Numérico II-IF392
Summary
• Euler, Midpoint and Heun’s methods are similar in the
following sense:
yi +1 = yi + h slope
• Different methods use different estimates of the slope.
• Both Midpoint and Heun’s methods are comparable in
accuracy to the second order Taylor series method.
𝟏
𝒚=
𝒆−𝒙 𝒙𝟐 + 𝟐𝒙 + 𝟐 + 𝟏
In each part, calculate the error between the true solution and the
numerical solution at the points where the numerical solution is
determined.
Cálculo Numérico II-IF392
Comparison
Local Global
Method truncation truncation
error error
yi +1 = yi + h f ( x 1 ,y 1 )
i+ i+
2 2
yi +1 = yi + (a1k1 + a2 k 2 )h
Cálculo Numérico II-IF392
Second-Order Runge-Kutta Methods
yi +1 = yi + (a1k1 + a2 k 2 )h
y
Compare with f ( xi , yi ) f ( xi , yi ) h2
yi +1 = yi + f ( xi , yi )h + + f ( xi , yi )
x y 2!
Using h = 0.5.
Solution:
The first point of the solution is (0,3), which is the point where the initial
condition is given. The values of x and y at the first point are x1=0 and y1=3.
The rest of the solution is done in steps. In each step the next value of the
independent variable is calculated by: