0% found this document useful (0 votes)
6 views

Lecture 9

Uploaded by

crfpfyfynj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture 9

Uploaded by

crfpfyfynj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Numerical and Engineering Analysis – 3rd Stage M. Sc.

Dina Sami

Numerical Solution of Ordinary Differential Equation


‫الحل العددي للمعادالت التفاضلية االعتيادية‬

A differential equation is an equation, which contains one or more terms, which involve
the derivatives of one variable (i.e., dependent variable) with respect to the other variable
(i.e., independent variable). The general form of n-order ODE is

Here “x” is an independent variable, and “y” is a dependent variable.

Differential Equation Types


Differential equations can be divided into several types namely

• Ordinary Differential Equations


• Partial Differential Equations
• Linear Differential Equations
• Non-linear differential equations
• Homogeneous Differential Equations
• Non-homogenous Differential Equations

‫) بإمكانها تحقيق المعادلة التفاضلية وكذلك بامكان هذه‬Function( ‫المقصود بحل اي معادلة تفاضلية هو إيجاد دالة‬
‫ ويتمثل الحل هذا بايجاد حل عام لهذه المعادلة حاويا ً على ثوابت‬.‫المعادلة تحقيق بعض الشروط االبتدائية والحدودية‬
‫ فكثيرا ً ما تكون المعادالت التفاضيلة غير المعادالت الخطية وبالتالي‬.‫يمكن ايجاد قيمها من الشروط االبتدائية والحدودية‬
.‫تستوجب الحالة وجود شروط ابتدائية عند الدرجة العليا والتي قلما تكون متوفرة‬

114
‫‪Numerical and Engineering Analysis – 3rd Stage‬‬ ‫‪M. Sc. Dina Sami‬‬

‫ونستنتج من ذلك بان الحل التحليلي قد ال يكون مهيئا ً لمثل هذا النوع من المعادالت التفاضلية بسبب المحددات في الحل‪.‬‬
‫سوف نتعرف على حل المعادالت التفاضلية االعتيادية بالطرق العددية‪ .‬وان هذه الطرق ال تحدد بصيغة قياسية‪ .‬ويتم‬
‫التطرق الى طريقة حل المعادلة التفاضلية من الدرجة االولى ومن ثم كيف تستخدم نفس الطريقة في حل المعادالت‬
‫التفاضلية من الدرجة االولى ودرجات اعلى منها‪.‬‬

‫دراستنا ستكون لطريقة تعتمد على اساس القيمة االبتدائية (‪ )Initial Value Problems‬والتي تتواجد فيها قيمة‬
‫‪ y(xo) = yo‬حيث يمكن تصنيفها الى صنفين اساسيين‪:‬‬

‫‪ Single-Step Methods -1‬طرق الخطوة المنفردة‪:‬‬

‫يتم هنا استخدام المعلومات المتوفرة للمنحني بنقطة واحدة فقط لحساب قيمة تقريبية للنقطة القادمة‪.‬‬

‫‪ Multi-Step Methods -2‬طرق الخطوات المتعددة‪:‬‬

‫في هذه الطرق يمكن ايجاد قيمة الدالة في نقطة ما وذلك باستخدام معلومات عن عدد من النقاط التي سبقتها ويمكن‬
‫تحسين قيمة دالة الحل وذلك باستخدام العالقات التكرارية حيث نحصل على القيمة التقريبية ذات الدقة المطلوبة‪ .‬وتعرف‬
‫هذه الطرق بالمخمن الصحيح (‪. ) predictor-correct‬‬

‫‪115‬‬
Numerical and Engineering Analysis – 3rd Stage M. Sc. Dina Sami

Solution of Ordinary Differential Equations (ODE 1st order)

1. Euler’s method
𝑑𝑦
The general form of 1st order equation is given by = f(x, y) with condition y(xo) = yo
𝑑𝑥

𝑑𝑦
Slope = ∅ = ý =
𝑑𝑥

Xn+1= Xn + h

Where h: step size on x-axis

How to find the new y (yn+1)?

By geometric:

Y1 – Yo = ∅ h Y1 ∅ ∅h

Y1= Yo + ∅ h Yo h

Y1= Yo + h ýo X0 X1

In Euler’s Method: 𝒚𝒏+𝟏 = 𝒚𝒏 + h 𝒚′𝒏

This formula is referred to as Euler’s (or the Euler-Cauchy or the point-slope) method. The
new value of y is predicted using the slope (equal to the first derivative at the original
value of x) to extrapolate linearly over the step size h.

116
Numerical and Engineering Analysis – 3rd Stage M. Sc. Dina Sami

By Tayler series:

A general form of Taylor Series expansion is:

........ (1)

Where: ℎ = 𝑥𝑛+1 − 𝑥𝑛 .

For small values of h (h2, h3, h4, are small and may be neglected)

In Euler’s Method: 𝒚𝒏+𝟏 = 𝒚𝒏 + h 𝒚′𝒏 ….. (2)

New value = Old value + (step size × slope)

𝑦𝑎𝑐𝑡𝑢𝑎𝑙 −𝑦𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒
𝜀𝑎 = | | × 100%
𝑦𝑎𝑐𝑡𝑢𝑎𝑙

Example 1:

Sol:
𝑦𝑛+1 = 𝑦𝑛 + h 𝑦𝑛′ ➔ 𝑦𝑛+1 = 𝑦𝑛 +0.5 [(𝑥𝑛 − 1)2 − 𝑦𝑛2 ]
𝑥𝑛 𝑦𝑛
0 𝑦0 = 0.5
0.5 𝑦1 =𝑦0 +0.5 [(𝑥0 − 1)2 − 𝑦02 ] = 0.5 +0.5 [(0 − 1)2 − 0.52 ] = 0.875
1 𝑦2 =𝑦1 +0.5 [(𝑥1 − 1)2 − 𝑦12 ] = 0.875 +0.5 [(0.5 − 1)2 − 0.8752 ] = 0.6172
1.5 𝑦3 =𝑦2 +0.5 [(𝑥2 − 1)2 − 𝑦22 ] = 0.6712 +0.5 [(1 − 1)2 − 0.67122 ] = 0.4267
2 𝑦4 =𝑦3 +0.5 [(𝑥3 − 1)2 − 𝑦32] = 0.4267+0.5 [(1.5 − 1)2 − 0.42672 ] = 0.4607
2.5 𝑦5 =𝑦4 +0.5 [(𝑥4 − 1)2 − 𝑦42] = 0.4607+0.5 [(2 − 1)2 − 0.46072 ] = 0.8546

117
Numerical and Engineering Analysis – 3rd Stage M. Sc. Dina Sami

Example 2: A ball at 1200K is allowed to cool down in air at an ambient temperature of


300K. Assuming heat is lost only due to radiation, the differential equation for the
temperature of the ball is given by:

Sol:

𝑦𝑛+1 = 𝑦𝑛 + h 𝑦𝑛′ ➔ 𝜃𝑛+1 = 𝜃𝑛 + h [-2.2067×10-12 (𝜃𝑛4 − 81 × 108 )]

tn (s) 𝜃𝑛 (𝑘)
0 𝜃0 = 1200
240 𝜃1 = 𝜃0 + h [-2.2067×10-12 (𝜃04 − 81 × 108 )]
= 1200 + 240 [-2.2067×10-12 (12004 − 81 × 108 )] = 106.09
480 𝜃2 = 𝜃1 + h [-2.2067×10-12 (𝜃14 − 81 × 108 )]
= 106.09 + 240 [-2.2067×10-12 (106.094 − 81 × 108 )] = 110.32

Example 3: For the differential equation 𝑦´ = y – x with initial conditions that


y (0)=2, for the range x = 0 – 0.5 with interval of 0.1. Find the numerical solution by
Euler’s method.

118
Numerical and Engineering Analysis – 3rd Stage M. Sc. Dina Sami

2. Modified Euler’s Method


𝑑𝑦
For a given differential equation = 𝑓 (𝑥, 𝑦) with initial condition y (xo) = yo find the
𝑑𝑥

approximate solution using Predictor-Corrector method.

Predictor-Corrector Method :

The predictor-corrector method is also known as Modified-Euler method.


In the Euler method, the tangent is drawn at a point and slope is calculated for a given step
size. Thus, this method works best with linear functions, but for other cases, there remains a
truncation error. To solve this problem the Modified Euler method is introduced. In this
method instead of a point, the arithmetic average
of the slope over an interval (xn, xn+1) is used.

Thus in the Predictor-Corrector method for each


step the predicted value of yn+1 is calculated first
using Euler’s method and then the slopes at the
points (xn, yn) and (xn+1, yn+1) is calculated and
the arithmetic average of these slopes are added
to yn to calculate the corrected value of yn+1.


𝑦𝑛+1 = yn + h 𝑦 ′𝑛 → 𝑦𝑛 + h f (xn, yn) … (1)

And the new value

ℎ ∗
𝑦𝑛+1 = yn + [f (𝑥𝑛 , 𝑦𝑛 ) + f (xn+1, 𝑦𝑛+1 )] … (2)
2

119
Numerical and Engineering Analysis – 3rd Stage M. Sc. Dina Sami

Example 4: Apply the modified Euler method with h = 0.1 to determine an approximation to the
solution to the initial-value problem, at x = 1

Sol:

𝑦𝑛+1 = yn + h 𝑦 ′𝑛

𝑦𝑛+1 = yn + 0.1(𝑦𝑛 − 𝑥𝑛 ) = 𝑦𝑛 + 0.1 𝑦𝑛 − 0.1 𝑥𝑛

𝑦𝑛+1 = 1.1 𝑦𝑛 −0.1 𝑥𝑛 …… (1)
ℎ ∗
𝑦𝑛+1 = yn + [f (xn, yn) + f (xn+1, 𝑦𝑛+1 )]
2

𝑦𝑛+1 = 𝑦𝑛 + 0.05 [𝑦𝑛 − 𝑥𝑛 + 1.1 𝑦𝑛 −0.1 𝑥𝑛 − 𝑥n+1 ]


= 𝑦𝑛 + 0.05 [2.1 𝑦𝑛 − 1.1 𝑥𝑛 − 𝑥n+1 ] = 𝑦𝑛 + 0.105 𝑦𝑛 − 0.055 𝑥𝑛 − 0.05𝑥n+1
𝑦𝑛+1 = 1.105 𝑦𝑛 − 0.055 𝑥𝑛 − 0.05𝑥n+1 ……. (2)

𝑥𝑛 0.055 𝑥𝑛 0.05𝑥n+1 𝑦𝑛 1.105 𝑦𝑛 𝑦𝑛+1 (eq. 2)


0 0 0.005 0.5 0.5525 0.5447
0.1 5.5×10-3 0.01 0.5447 0.6049 0.5894
0.2 0.011 0.015 0.5894 0.6514 0.6254
0.3 0.0165 0.02 0.6254 0.6911 0.6546
0.4 0.022 0.025 0.6546 0.7233 0.6763
0.5 0.0275 0.03 0.6763 0.7473 0.6898
0.6 0.033 0.035 0.6898 0.7622 0.6942
0.7 0.0385 0.04 0.6942 0.7671 0.6886
0.8 0.044 0.045 0.6886 0.7609 0.6719
0.9 0.0495 0.05 0.6719 0.7424 0.6429
1 0.6429 = y (1)

120
Numerical and Engineering Analysis – 3rd Stage M. Sc. Dina Sami

Example 5: Use the Euler’s modified method to solve the following of differential
equation.
𝑑𝑦 1
= x2 + 4x - y
𝑑𝑥 2
With y (0) = 4, for x = 0 (0.05) 0.2
Sol:

𝑦𝑛+1 = 𝑦𝑛 + h 𝑦 ′𝑛
∗ 1
𝑦𝑛+1 = 𝑦𝑛 + 0.05 (𝑥𝑛2 + 4 𝑥𝑛 - 𝑦𝑛 ) = 𝑦𝑛 + 0.05 𝑥𝑛2 + 0.2 𝑥𝑛 - 0.025 𝑦𝑛
2

𝑦𝑛+1 = 0.975 𝑦𝑛 + 0.2 𝑥𝑛 + 0.05𝑥𝑛2 ….. (1)
ℎ ∗
𝑦𝑛+1 = yn + [f (xn, yn) + f (xn+1, 𝑦𝑛+1 )]
2
0.05 1 2
= yn + [𝑥𝑛2 + 4 𝑥𝑛 - 𝑦𝑛 + 𝑥𝑛+1 + 4 𝑥𝑛+1 – 0.5 (0.975 𝑦𝑛 + 0.2 𝑥𝑛 + 0.05𝑥𝑛2 )]
2 2
2
= yn + 0.0244 𝑥𝑛2 + 0.0975 𝑥𝑛 + 0.025 𝑥𝑛+1 + 0.1 𝑥𝑛+1 – 0.025 𝑦𝑛
2
𝑦𝑛+1 = 0.975 yn + 0.0244 𝑥𝑛2 + 0.0975 𝑥𝑛 + 0.025 𝑥𝑛+1 + 0.1 𝑥𝑛+1 …… (2)

𝑥𝑛 0.0975 𝑥𝑛 0.0244 𝑥𝑛2 0.1 𝑥𝑛+1 2


0.025 𝑥𝑛+1 𝑦𝑛 0.975 yn 𝑦𝑛+1 (eq. 2)
0 0 0 5×10-3 6.25×10-5 4 3.9 3.905
0.05 4.875×10-3 6.1×10-5 0.01 2.5×10-4 3.905 3.807 3.823
0.1 9.75×10-3 2.44×10-4 0.015 5.625×10-4 3.823 3.727 3.753
0.15 0.01463 5.49×10-4 0.02 0.001 3.753 3.659 3.695
0.2 3.695 = y(0.2)

121
Numerical and Engineering Analysis – 3rd Stage M. Sc. Dina Sami

H.w 1: Find an approximate value of


8

 6 x dx
3

Using Euler’s method of solving an ordinary differential equation at y (5) = 0. Use a step size of h = 1.5
8

Hint: Given  6 x 3 dx , we can rewrite the integral as the solution of an ordinary differential
5

8
= 6 x 3 , y (5) = 0 , and
dy
 6 x dx = y(8) − y(5)
3
equation
dx 5

H.w 2: The concentration of salt x in a homemade soap maker is given as a function of time by
dx
= 37.5 − 3.5 x
dt
At the initial time, t = 0 , the salt concentration in the tank is 50 g/L. Using Euler’s method and a step size of
h = 1.5 min , what is the salt concentration after 3 minutes?

H.w3: solve the following differential equation numerically using Euler method and
modified Euler method. Find y (0.5) when 𝑦´ = 2 x + y, y (0) = 1. Take h = 0.1

Ans. (y (0.5) = 1.83153, y (0.5) 1.94234)

122

You might also like