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

Numerical Methods Worked Out Problems (1)

Uploaded by

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

Numerical Methods Worked Out Problems (1)

Uploaded by

nikhil.hoskoti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Problem 1: Euler's Method

Given the differential equation:

dy
=x+y
dx

with the initial condition y(0) = 1, use Euler's method to approximate y(0.2) and y(0.4) using a
step size h = 0.2.

Problem 2: Heun's Method (Improved Euler)


Given the differential equation:

dy
=x−y
dx

with the initial condition y(0) = 2, use Heun's method to approximate y(0.1) and y(0.2) using a
step size h = 0.1.

Problem 3: Runge-Kutta 4th Order (RK4)


Given the differential equation:

dy
= sin(x) + y
dx

with the initial condition y(0) = 0, use RK4 to approximate y(0.1) and y(0.2) using a step size
h = 0.1.
Problem 1: Euler’s Method
Given:

dy
= x + y, y(0) = 1
dx

Step size: h = 0.2

The formula for Euler’s method is:

yn+1 = yn + h ⋅ f (xn , yn )
​ ​ ​ ​

where f (xn , yn )
​ ​ = xn + yn .
​ ​

Step 1: From x0 ​ = 0 to x1 = 0.2


y0 = 1

f (0, 1) = 0 + 1 = 1
y1 = y0 + h ⋅ f (0, 1) = 1 + 0.2 ⋅ 1 = 1.2
​ ​

Step 2: From x1 ​ = 0.2 to x2 = 0.4 ​

y1 = 1.2

f (0.2, 1.2) = 0.2 + 1.2 = 1.4


y2 = y1 + h ⋅ f (0.2, 1.2) = 1.2 + 0.2 ⋅ 1.4 = 1.48
​ ​

Thus, the approximate values are:


y(0.2) ≈ 1.2
y(0.4) ≈ 1.48

Problem 2: Heun’s Method (Improved Euler)


Given:

dy
= x − y, y(0) = 2
dx

Step size: h = 0.1

Heun's method is a two-step process. The predictor (Euler's method) is used to estimate an intermediate value,
and the corrector improves upon this estimate.

The formula for Heun's method is:

h
yn+1 = yn + ⋅ (f (xn , yn ) + f (xn+1 , ypredicted ))
2
​ ​ ​ ​ ​ ​ ​

Step 1: From x0 ​ = 0 to x1 = 0.1


y0 = 2

f (0, 2) = 0 − 2 = −2
Predictor:
ypred = y0 + h ⋅ f (0, 2) = 2 + 0.1 ⋅ (−2) = 1.8
​ ​

f (0.1, 1.8) = 0.1 − 1.8 = −1.7


Corrector:
0.1
y1 = y0 +​ ​

2
​ ⋅ (−2 + (−1.7)) = 2 + 0.05 ⋅ (−3.7) = 2 − 0.185 = 1.815

Step 2: From x1 ​
= 0.1 to x2 = 0.2 ​

y1 = 1.815

f (0.1, 1.815) = 0.1 − 1.815 = −1.715


Predictor:
ypred = y1 + h ⋅ f (0.1, 1.815) = 1.815 + 0.1 ⋅ (−1.715) = 1.815 − 0.1715 = 1.6435
​ ​

f (0.2, 1.6435) = 0.2 − 1.6435 = −1.4435


Corrector:
0.1
y2 = y1 +​ ​

2
​ ⋅ (−1.715 + (−1.4435)) = 1.815 + 0.05 ⋅ (−3.1585) = 1.815 − 0.157925 = 1.6571

Thus, the approximate values are:


y(0.1) ≈ 1.815
y(0.2) ≈ 1.6571

Problem 3: Runge-Kutta 4th Order (RK4)


Given:

dy
= sin(x) + y, y(0) = 0
dx

Step size: h = 0.1

The RK4 method uses four evaluations of the derivative at each step:

h
yn+1 = yn + (k1 + 2k2 + 2k3 + k4 )
6
​ ​ ​ ​ ​ ​ ​

where:

h h h h
k1 = f (xn , yn ), k2 = f (xn + , yn + k1 ), k3 = f (xn + , yn + k2 ), k4 = f (xn + h, yn + hk3 )
2 2 2 2
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​

Step 1: From x0 ​
= 0 to x1 = 0.1 ​

y0 = 0 ​

k1 = f (0, 0) = sin(0) + 0 = 0

k2 = f (0.05, 0 + 0.05 ⋅ 0) = sin(0.05) + 0 = 0.04998


k3 = f (0.05, 0 + 0.05 ⋅ 0.04998) = sin(0.05) + 0.002499 = 0.05248


k4 = f (0.1, 0 + 0.1 ⋅ 0.05248) = sin(0.1) + 0.005248 = 0.10478



Now, update y1 : ​

0.1 0.1
y1 = 0 + (0 + 2(0.04998) + 2(0.05248) + 0.10478) = ⋅ (0.30918) = 0.005153
6 6
​ ​ ​

Step 2: From x1 ​ = 0.1 to x2 = 0.2


k1 = f (0.1, 0.005153) = sin(0.1) + 0.005153 = 0.10479


k2 = f (0.15, 0.005153 + 0.05 ⋅ 0.10479) = sin(0.15) + 0.010393 = 0.15975


k3 = f (0.15, 0.005153 + 0.05 ⋅ 0.15975) = sin(0.15) + 0.013141 = 0.16289


k4 = f (0.2, 0.005153 + 0.1 ⋅ 0.16289) = sin(0.2) + 0.021442 = 0.21980


Now, update y2 : ​

0.1
y2 = 0.005153 + (0.10479 + 2(0.15975) + 2(0.16289) + 0.21980) = 0.005153 + 0.01657 = 0.02172
6
​ ​

Thus, the approximate values are:


y(0.1) ≈ 0.005153
y(0.2) ≈ 0.02172

You might also like