Numerical Methods
KOM2722-
AVE3842
Week 2
Asst. Prof. Bilal Erol
Syllabus
Texts: Lecture Notes Grading: Attendance
• An Introduction to • We will use lecture • 60% Midterm + • At least 70%
Numerical notes of Asst. Prof. Homework
Methods and Birol Erol and Asst. • 40% Final
Analysis, J. F. Prof. Bahadır
Epperson, Wiley, Çatalbaş prepared
2002 from textbooks.
• Applied Numerical • Lecture slides will
Methods with be shared with
MATLAB, S.C. students.
Chapra, 2012,
McGrow-Hill
2
Basic Tools of Calculus
Taylor’s Theorem
Provides an approximation of (𝑛 + 1) times differentiable function around a given point.
Suppose that we are working on a function f(x) that is continuous and has (𝑛 + 1) continious derivatives on interval
(𝑎, 𝑏].
Theorem (Taylor’s Theorem with Remainder):
Let 𝑓(𝑥) have 𝑛 + 1 continuous derivatives on (𝑎, 𝑏] for some 𝑛 ≥ 0 and let 𝑥, 𝑥0 ∈ 𝑎, 𝑏 , then
𝑓 𝑥 = 𝑝𝑛 𝑥 + 𝑅𝑛 (𝑥)
𝑓′′ 𝑥0 𝑥−𝑥0 2 𝑥−𝑥0 𝑘 𝑘
𝑝𝑛 𝑥 = 𝑓 𝑥0 + 𝑓 ′ 𝑥0 𝑥 − 𝑥0 + + ⋯ = σ𝑛𝑘=0 𝑓(𝑥0 )
2! 𝑘!
The remainder
1 𝑥 𝑛 𝑛+1
𝑅𝑛 𝑥 = 𝑥−𝑡 𝑓 𝑡 𝑑𝑡
𝑛! 𝑥0
*Every continuous function can be approximated by a polynomial of order n.
*Allow us to replace/obtain, in a computational setting, a much simple problem.
3
The remainder, the error term,
𝑥−𝑥0 𝑛+1 (𝑛+1)
𝑅𝑛 𝑥 = 𝑓 𝑐 𝑓𝑜𝑟 𝑠𝑜𝑚𝑒 𝑐 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑥0 𝑎𝑛𝑑 𝑥
𝑛+1 !
𝑎𝑛𝑑
lim 𝑅𝑛 𝑥 = 0
𝑛→ ∞
Taylor’s series for 𝑥0 = 0 is called as Maclaurin series
Example: 𝑓 𝑥 = 𝑒 𝑥 , find 𝑛𝑡ℎ order Taylor series expansion of 𝑓 𝑥 around 𝑥 = 0
𝑓 𝑘 0 =1
1 2 1 3 1 𝑛 1
𝑒𝑥 = 1 + 𝑥 + 𝑥 + 𝑥 + ⋯+ 𝑥 + 𝑥 𝑛+1 𝑒 𝑐𝑥
2! 3! 𝑛! 𝑛+1 !
𝑝𝑛 (𝑥) 𝑅𝑛 𝑥 , remainder 𝑐𝑥 is an unknown
point between 𝑥 and 0.
4
Taylor’s Theorem an approximation and an error estimate provides
Considering the problem of approximating the exponential function on the interval [−1, 1]
1 2 1 3 1 𝑛 1
𝑒𝑥 = 1 + 𝑥 + 𝑥 + 𝑥 + ⋯+ 𝑥 + 𝑥 𝑛+1 𝑒 𝑐𝑥
2! 3! 𝑛! 𝑛+1 !
𝑝𝑛 (𝑥) Polynomial 𝑅𝑛 𝑥 , remainder
𝑐𝑥 is an unknown point between x and 0.
Without lost of generality 𝑥 can be any point in [-1, 1] then
𝑐𝑥 can be any point in [-1, 1]
For simplicity, let’s denote polynomial by 𝑝𝑛 (𝑥) and remainder by 𝑅𝑛 𝑥 , so that the
equation:
e𝑥 = 𝑝𝑛 𝑥 + 𝑅𝑛 (𝑥)
5
Suppose that we want this approximation to be accurate within 10−6 absolute error. i.e.,
|e𝑥 − 𝑝𝑛 𝑥 | ≤ 10−6 for all 𝑥 in the interval [−1, 1].
|e𝑥 − 𝑝𝑛 𝑥 | = |𝑅𝑛 (𝑥)| ≤ 10−6 , if we make |𝑅𝑛 (𝑥)| ≤ 10−6 the absolute error in
approximation will be less that 10−6 .
In other words, we need make the upper bound less than 10−6 .
|𝑥 𝑛+1 𝑒 𝑐𝑥 | 𝑥 𝑛+1 𝑒 𝑐𝑥
𝑅𝑛 𝑥 = = (Note that: 𝑒 𝑧 > 0 for all z.)
𝑛+1 ! 𝑛+1 !
𝑒 𝑐𝑥
≤ , because x ≤ 1 for all x ∈ [-1, 1]
𝑛+1 !
𝑒
≤ , because e𝑐𝑥 ≤ 𝑒 for all x ∈ [-1, 1]
𝑛+1 !
𝑒
So that, if we find 𝑛 such that ≤ 10−6 then we will have 𝑒 𝑥 − 𝑝𝑛 𝑥 = 𝑅𝑛 𝑥 ≤
𝑛+1 !
10−6 .
𝑛 = 9 satisfies the desired accuracy.
6
Rolle’s Theorem
𝑦
Suppose that 𝑦 = 𝑓(𝑥) is continuous at every
point of the closed interval [𝑎, 𝑏] and 𝑓′ 𝑐 = 0
differentiable at every point of its interior (𝑎, 𝑏). If
𝑓 𝑎 =𝑓 𝑏 𝑦=𝑓 𝑥
then there is at least one number 𝑐 in 𝑎, 𝑏 at
which
𝑓 ′ 𝑐 = 0. 0 𝑎 𝑐 𝑏
𝑥
Thus, there should be one place where tangent
line should be horizontal
Note that it is also satisfied for functions intersect
the x axis at two points; 𝑓 𝑎 = 𝑓 𝑏 = 0.
7
The Mean Value Theorem
𝑦
Let 𝑓 be a given function, continuous on closed
interval [𝑎, 𝑏] and differentiable at every point of 𝑓′ 𝜁
𝐵
its interior (𝑎, 𝑏). Then there exists a point 𝜁 ∈
𝑦=𝑓 𝑥
[𝑎, 𝑏] such that
𝐴
′
𝑓 𝑏 − 𝑓(𝑎)
𝑓 𝜁 =
𝑏−𝑎 𝑥
0 𝑎 ζ 𝑏
The mean value theorem (MVT) states that between any two points on the
graph of a differentiable function 𝑓 there at least one place where the
tangent line to the graph is parallel to line joining.
8
Consequences of MVT
MVT is used to prove many results
-> Let 𝑓 be a function that is continuous and differentiable on [𝑎, 𝑏]
if 𝑓 ′ 𝑥 > 0 for every 𝑥 in [𝑎, 𝑏], the f is increasing on [𝑎, 𝑏]
𝑓′ 𝑥 < 0 decreasing
𝑓′ 𝑥 = 0 constant
9
Proof:
Secant line intersection points for y = 𝑓(𝑥): A 𝑎, 𝑓 𝑎 , B(𝑏, 𝑓 𝑏 )
Equation of secant line: 𝑦 − 𝑦1 = 𝑚(𝑥 − 𝑥1 )
Here 𝑔(𝑥) is the equation of secant line AB
𝑓 𝑏 − 𝑓(𝑎)
𝑔 𝑥 −𝑓 𝑎 = (𝑥 − 𝑎)
𝑏−𝑎
𝑓 𝑏 −𝑓 𝑎
𝑔 𝑥 = 𝑥−𝑎 +𝑓 𝑎 (1)
𝑏−𝑎
Let ℎ 𝑥 = 𝑓 𝑥 − 𝑔(𝑥),
𝑓 𝑏 −𝑓 𝑎
ℎ 𝑥 =𝑓 𝑥 − 𝑥−𝑎 +𝑓 𝑎 𝑓𝑟𝑜𝑚 (1)
𝑏−𝑎
ℎ 𝑎 = ℎ 𝑏 = 0 and ℎ(𝑥) is continuous on [𝑎, 𝑏] and differentiable on (a, b).
Thus applying Rolle’s Theorem, there is some x = 𝑐 in (𝑎, 𝑏) such that ℎ′ (𝑐) = 0
′ ′
𝑓 𝑏 −𝑓 𝑎
ℎ 𝑥 =𝑓 𝑥 −
𝑏−𝑎
′
For some 𝑐 in 𝑎, 𝑏 , ℎ 𝑐 = 0. Thus,
′ ′
𝑓 𝑏 −𝑓 𝑎
ℎ 𝑐 =𝑓 𝑐 − =0
𝑏−𝑎
𝑓 𝑏 −𝑓 𝑎
𝑓 ′ (𝑐) =
𝑏−𝑎
10
Intermediate Value Theorem
Let 𝑓 ∈ 𝐶([𝑎, 𝑏]) be given, and assume that 𝑊 is a value between 𝑓(𝑎)
and 𝑓(𝑏), that is, either f 𝑎 ≤ 𝑊 ≤ 𝑓(𝑏), or 𝑓(𝑏) ≤ 𝑊 ≤ 𝑓(𝑎). Then
there exists a point 𝑐 ∈ [𝑎, 𝑏] such that 𝑓(𝑐) = 𝑊.
* This theorem says that a certain point exists does not give us much
information about its numerical value.
-> We will use this theorem as the basis for finding the roots.
Note: 𝐶([𝑎, 𝑏]) — The set of functions 𝑓 which are defined on the
interval [𝑎, 𝑏], continuous on all of (𝑎, 𝑏), and continuous from the
interior of [𝑎, 𝑏] at the endpoints.
11
Extreme Value Theorem
Let 𝑓 ∈ 𝐶 𝑎, 𝑏 be given; then there exists a point 𝑚 ∈ [𝑎, 𝑏] such
that 𝑓(𝑚) ≤ 𝑓(𝑥) for all 𝑥 ∈ [𝑎, 𝑏], and a point 𝑀 ∈ [𝑎, 𝑏] such that
𝑓(𝑀) ≥ 𝑓(𝑥) for all 𝑥 ∈ [𝑎, 𝑏]. Moreover, 𝑓 achieves its maximum
and minimum values on [𝑎, 𝑏] either at the endpoints 𝑎 or 𝑏, or at a
critical point.
The student should recall that a critical point is a point where the first
derivative is either undefined or equal to zero.
12
Integral Mean Value Theorem
Let 𝑓 and 𝑔 both be in 𝐶([𝑎, 𝑏]), and assume further that 𝑔 does not
change sign on [𝑎, 𝑏]. Then there exists a point 𝜁 ∈ [𝑎, 𝑏] such that
𝑏 𝑏
න 𝑔 𝑡 𝑓 𝑡 𝑑𝑡 = 𝑓(𝜁) න 𝑔 𝑡 𝑑𝑡
𝑎 𝑎
13
Discrete Average Value Theorem
Let 𝑓 ∈ 𝐶([𝑎, 𝑏]) and consider the sum, 𝑛
𝑆 = 𝑎𝑘 𝑓(𝑥𝑘 ) ,
𝑘=1
Where each point 𝑥𝑘 ∈ 𝑎, 𝑏 , and the coefficients satisfy
𝑛
𝑎𝑘 ≥ 0, 𝑎𝑘 = 1
𝑘=1
Then there exists a point 𝜂 ∈ [𝑎, 𝑏] such that 𝑓(𝜂)𝑛 = 𝑆, i.e.,
𝑓(𝜂) = 𝑎𝑘 𝑓(𝑥𝑘 )
𝑘=1
Proof: 𝑛 𝑛
𝑓 𝑥𝑘 ≤ 𝑓𝑀 ⇒ 𝑆 = 𝑎𝑘 𝑓 𝑥𝑘 ≤ 𝑓𝑀 𝑎𝑘 = 𝑓𝑀
𝑘=1 𝑘=1
14
Error, Approximate Equality and Asymptotic
Order
There are different error definitions such as measurement errors,
modeling errors, etc. Here we concerned here only with the
computational errors such as truncation error or approximation error
(True Value = Approximation Error + Error).
We have already talked about the "error" made in a simple Taylor series
approximation. It is time we got a little more precise.
15
Error
If 𝐴 is a quantity we want to compute and 𝐴ℎ is an approximation to that
quantity, then the error is the difference between the two:
𝑒𝑟𝑟𝑜𝑟 = 𝐴 − 𝐴ℎ ;
the absolute error is simply the absolute value of the error:
𝑎𝑏𝑠𝑜𝑙𝑢𝑡𝑒 𝑒𝑟𝑟𝑜𝑟 = 𝐴 − 𝐴ℎ ;
and the relative error normalizes by the absolute value of the exact value:
𝐴 − 𝐴ℎ
𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝑒𝑟𝑟𝑜𝑟 = ,
|𝐴|
where we assume that 𝐴 ≠ 0.
Using a relative error protects us from misguiding the accuracy of an
approximation for very large or very small numbers.
16
Approximate Equality
If two quantities are approximately equal to each other, we will use the notation “≈” to
denote this relationship, as in
𝐴≈𝐵
This is an admittedly vague notion. Is 0.99 ≈ 1? Probably so. Is 0.8 ≈ 1? Maybe not.
lim 𝐴ℎ = 𝐴 ⇒ 𝐴ℎ ≈ 𝐴 𝑓𝑜𝑟 𝑎𝑙𝑙 "ℎ" 𝑠𝑢𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑙𝑦 𝑠𝑚𝑎𝑙𝑙
ℎ→0
lim 𝐴𝑛 = 𝐴 ⇒ 𝐴𝑛 ≈ 𝐴 𝑓𝑜𝑟 𝑎𝑙𝑙 "𝑛" 𝑠𝑢𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑙𝑦 𝑙𝑎𝑟𝑔𝑒
𝑛→∞
For example, the definition of derivative of function 𝑦 = 𝑓 𝑥 is as follows:
𝑓 𝑥 + ℎ − 𝑓(𝑥)
lim = 𝑓 ′ (𝑥)
ℎ→0 ℎ
We therefore conclude that, for ℎ small enough,
𝑓 𝑥 + ℎ − 𝑓(𝑥)
≈ 𝑓′ 𝑥 .
ℎ
17
Asymptotic Order (Big O notation)
Another notation of use is the so-called "Big O" notation, more formally
known as asymptotic order notation. Suppose that we have a value 𝑦 and a
family of values {𝑦ℎ }, each of which approximates this value,
𝑦 ≈ 𝑦ℎ
for small values of ℎ. If there exists a positive function 𝛽(ℎ), 𝛽 ℎ → 0 as
ℎ → 0, and a constant 𝐶 > 0, independent of ℎ, such that
𝑦 − 𝑦ℎ ≤ 𝐶𝛽(ℎ)
for all ℎ sufficiently small, then we say that
𝑦 = 𝑦ℎ + 𝑂 𝛽 ℎ ,
meaning that 𝑦 − 𝑦ℎ is “on the order of” 𝛽(ℎ). Here 𝛽(ℎ) is a function of
the parameter h, and we assume that
lim 𝛽(ℎ) = 0
ℎ→0
18
∞ −2𝑥 𝑛 −2𝑥
Example: 𝐴 = 0 𝑒 𝑑𝑥 , 𝐴𝑛 = 0 𝑒 𝑑𝑥
1
Exact solution ⇒ 𝐴 =
2
1
1 −2𝑛
Solution 𝑜𝑓 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 ⇒ 𝐴𝑛 = − 𝑒
2 2
1 −2𝑛
⇒ 𝐴𝑛 = 𝐴 − 𝑒
2
1 −2𝑛
⇒ 𝐴 = 𝐴𝑛 + 𝑒
2
⇒ 𝐴 = 𝐴𝑛 + 𝑂(𝑒 −2𝑛 )
𝛽 𝑛 = 𝑒 −2𝑛
19
Theorem: Let 𝑦 = 𝑦ℎ + 𝑂(𝛽(ℎ)) and z = 𝑧ℎ + 𝑂(𝛾(ℎ)), with 𝑏𝛽 ℎ >
𝛾(ℎ) for all ℎ near zero. Then
𝑦 + 𝑧 = 𝑦ℎ + 𝑧ℎ + 𝑂(𝛽 ℎ + 𝛾(ℎ))
𝑦 + 𝑧 = 𝑦ℎ + 𝑧ℎ + 𝑂(𝛽 ℎ )
20
Horner’s Rule
Up to now, we devoted some time to the construction of polynomial approximations to
given functions. It might be good if we discussed the best way to evaluate those
approximations efficiently.
The most efficient way to evaluate a polynomial is by nested multiplication. If we have
𝑝𝑛 𝑥 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + ⋯ + 𝑎𝑛 𝑥 𝑛 ,
then we factor out each power of x as far as it will go, thus getting
𝑝𝑛 𝑥 = 𝑎0 + 𝑥(𝑎1 + 𝑥(𝑎2 + ⋯ + 𝑥 𝑎𝑛−1 + 𝑎𝑛 𝑥 … )).
In the first form –> we need to find powers of 𝑥 2 , 𝑥 3 , … , 𝑥 𝑛
In the second form –> (𝑛 + 1) multiplications and 𝑛 additions
21
Example: We could write
𝑞 𝑥 = 1 + 𝑥 + 3𝑥 2 − 6𝑥 3
as
𝑞 𝑥 = 1 + 𝑥(1 + 𝑥(3 − 6𝑥))
22
Difference Approximations To The Derivative
One of the simplest uses of Taylor's Theorem as a means of
constructing approximations involves the use of difference quotients to
approximate the derivative of a known function 𝑓 . Intuitively, this is
obvious from the definition of the derivative:
𝑓 𝑥 + ℎ + 𝑓(𝑥) 𝑓 𝑥 + ℎ − 𝑓(𝑥)
𝑓′ 𝑥 = lim ′
⇒𝑓 𝑥 =
ℎ→0 ℎ ℎ
The challenge for us is to make this vague statement more precise (just
how accurate is this approximation, in terms of the parameter ℎ?)
23
Using Tylor’s Theorem
1 2 ′′
𝑓 𝑥 + ℎ − 𝑓 𝑥 ℎ𝑓 ′ 𝑥 + ℎ 𝑓 𝜁𝑥, ℎ
𝑓′ 𝑥 − = 𝑓′ 𝑥 − 2
ℎ ℎ
1
= − ℎ𝑓′′ 𝜁𝑥, ℎ
2
Here the error is proportional to ℎ.
Can we do better?
′
1 2 ′′ 1 3 ′′′
⇒ 𝑓 𝑥 + ℎ = 𝑓 𝑥 + ℎ𝑓 𝑥 + ℎ 𝑓 𝑥 + ℎ 𝑓 𝜁1
2 6
′
1 2 ′′ 1 3 ′′′
⇒ 𝑓 𝑥 − ℎ = 𝑓 𝑥 − ℎ𝑓 𝑥 + ℎ 𝑓 𝑥 − ℎ 𝑓 𝜁2
2 6
Subtract
′
1 3 ′′′ 1 3 ′′′
𝑓 𝑥 + ℎ − 𝑓 𝑥 − ℎ = 2ℎ𝑓 𝑥 + ℎ 𝑓 𝜁1 − ℎ 𝑓 𝜁2
6 6
24
Let us solve for 𝑓′(𝑥)
′′′ ′′′
′
𝑓 𝑥 + ℎ − 𝑓(𝑥 − ℎ) 1 2
𝑓 𝜁1 + 𝑓 𝜁2
𝑓 𝑥 = − ℎ
2ℎ 6 2
′
𝑓 𝑥 + ℎ − 𝑓(𝑥 − ℎ) 1 2 ′′′
𝑓 𝑥 = − ℎ 𝑓 𝜁𝑥 , ℎ
2ℎ 6
This estimate will tent to be better since ℎ2 < ℎ.
𝑓 𝑥+ℎ −𝑓(𝑥)
Forward difference approximation: 𝑓 ′ 𝑥 =
ℎ
𝑓 𝑥+ℎ −𝑓(𝑥−ℎ)
Central difference approximation: 𝑓 ′ 𝑥 =
2ℎ
25
Example: 𝑓 𝑥 = 𝑒 𝑥 , take derivative for 𝑥 = 1, using ℎ = 1/8
Exact Value:
𝑓′ 𝑥 = 𝑒𝑥, 𝑓′ 1 = 𝑒
Forward difference approximation:
𝑒 1.125 −𝑒
𝑓′ 𝑥 ≈ = 2.895480164
0.125
Central difference approximation:
′ 𝑒 1.125 −𝑒 0.875
𝑓 𝑥 ≈ = 2.72536622
0.25
The error in first approximation is −0.177
in second approximation is −7.084𝑥10−3
26
Euler's Method For Initial Value Problems
One immediate application of difference methods for approximating
derivatives is the approximate solution o f initial value problems for
ordinary differential equations. The usual general form of such a
problem is
𝑦 ′ = 𝑓 𝑡, 𝑦 , 𝑦 𝑡0 = 𝑦0 ,
where 𝑓 is a known function of 𝑡 and 𝑦, and 𝑡0 and 𝑦0 are given values.
The object in solving this problem is to find 𝑦 as a function of 𝑡; in
ordinary differential equations, there are different techniques for
analytically solution ways but in some cases, it may not be easy or
feasible.
27
From the last course, we can show that
′
𝑓 𝑥+ℎ −𝑓 𝑥 1 ′′
𝑓 𝑥 − = − ℎ𝑓 𝜁𝑥,ℎ = 𝑂(ℎ)
ℎ 2
with Taylor series expansion.
For 𝑦 ′ (𝑡) = 𝑓 𝑡, 𝑦(𝑡) ,
𝑦 𝑡 + ℎ − 𝑦(𝑡) 1 ′′
= 𝑓 𝑡, 𝑦 𝑡 + ℎ𝑦 (𝑡ℎ )
ℎ 2
which can be simplified slightly to become
1 2 ′′
𝑦 𝑡 + ℎ = 𝑦 𝑡 + ℎ𝑓 𝑡, 𝑦 𝑡 + ℎ 𝑦 𝑡ℎ .
2
28
We will choose some small increment Δ𝑥
(𝑥3 , 𝑦3 )
** The basic idea behind Euler’s method is to
start at the known initial point 𝑥0 , 𝑦0 and (𝑥2 , 𝑦2 )
draw a line segment in the direction
determined by the slope field until we reach (𝑥1 , 𝑦1 )
the point (𝑥1 , 𝑦1 ) with 𝑥 coordinate 𝑥1 =
𝑥0 + Δ𝑥 (𝑥0 , 𝑦0 )
𝑦𝑛+1 − 𝑦𝑛 (𝑥𝑛+1 , 𝑦𝑛+1 )
= 𝑓(𝑥𝑛 , 𝑦𝑛 ) Δ𝑥
Δ𝑥
𝑦𝑛+1 = 𝑦𝑛 + 𝑓 𝑥𝑛 , 𝑦𝑛 Δx
𝑦𝑛+1 − 𝑦𝑛
(𝑥𝑛 , 𝑦𝑛 ) Δ𝑥 (𝑥𝑛+1 , 𝑦𝑛 )
29
To approximate the solution of the initial-value problem
𝑦 ′ = 𝑓 𝑥, 𝑦 , 𝑦 𝑥0 = 𝑦0
Step 1: Choose a nonzero number Δ𝑥 to serve as an increment or step
size along x-axis
𝑥1 = 𝑥0 + Δ𝑥, 𝑥2 = 𝑥1 + Δ𝑥, ….
Step 2: Compute successively,
𝑦1 = 𝑦0 + 𝑓 𝑥0 , 𝑦0 Δ𝑥
𝑦2 = 𝑦1 + 𝑓 𝑥1 , 𝑦1 Δ𝑥 The number 𝑦1 , 𝑦2 , … , 𝑦𝑛+1
are the approximations of
… 𝑦 𝑥1 , 𝑦 𝑥2 , … , 𝑦 𝑥𝑛+1
𝑦𝑛+1 = 𝑦𝑛 + 𝑓(𝑥𝑛 , 𝑦𝑛 )Δ𝑥
𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑡𝑛 , 𝑦𝑛 )
30
Example: 𝑦 ′ = −𝑦 + sin 𝑡 , 𝑦 0 = 1
3 1
This has exact solution 𝑦 𝑡 = 𝑒 −𝑡 + (sin 𝑡 − cos(𝑡)), found by using the
2 2
kinds of methods taught in the usual ODE courses.
Let us apply Euler’s method for ⇒ ℎ = 1/4
Step 1: ℎ = 1/4, so 𝑡1 = ℎ = 1/4 and 𝑦0 is given as 1. Then,
𝑦1 = 𝑦0 + ℎ𝑓 𝑡0 , 𝑦0
1 3
= 1 + −1 + sin 0 =
4 4
1
Thus, 𝑦 ≈ 0.75, the error in this approximation
4
1
𝑒1 = 𝑦 − 𝑦1 = 0.8074469434 − 0.75 = 0.0574469434
4
1
Step 2: We have 𝑡2 = 2ℎ = and 𝑦1 = 0.75 from the Step 1. Then
2
3 1 3 1 1
𝑦2 = 𝑦1 + ℎ𝑓 𝑡1 , 𝑦1 = + − + sin = 0.624350 ≈ 𝑦( )
4 4 4 4 2
1
𝑒2 = 𝑦 − 𝑦2 = 0.7107174779 − 0.624350 = 0.08636
2
31