You are on page 1of 17

Short Report:

yi(Rk4) yi(Euler's) yi(Heun's) yi(Analytical)

1 1 1 1
1.3368985 1.25 1.334631373 1.336914063
1.8905812 1.6692627 1.883644838 1.890625
2.7430734 2.3152625 2.727723074 2.743164063
3.9998397 3.2662617 3.970990733 4
Euler’s, Heun’s (improved Euler’s method), and Classical RK4 procedure are numerical methods that
are used to solve first-order ordinary differential equations. Based on the result of the machine
exercise, it has been observed that the values obtained are precise and accurate when compared to
each method and from the true value obtained using the Analytical procedure. The table below shows
the relationship of values obtained using the said methods.
Table 1: Values obtained using Classical RK4, Euler’s, Heun’s, and Analytical method.
The values obtained using the Analytical method serve as the true value for the first order ODE that
served as the baseline for the three numerical methods. The analytical values obtained with the given x
boundary of 0 to 1 has a minimum y value of 1 and a maximum of 4. From the data, the classical RK4
procedure produced the most accurate value followed by Heun’s and Euler's method. It is true that
theoretically, the RK4 procedure (fourth-order Runge Kutta method) gives more stable results though it
is quite complex in the iterations, encompassing an analysis of 4 slopes to approximate the point
desired. Note that Euler's error is linearly reduced with the step size, while Heun's is quadratically
reduced and RK4 is quartically reduced. To furtherly explained, Heun’s method used a predictor and
corrector value which by its name is an improved Euler’s method such that it produces a lesser error
compare to the latter method. The idea is that in this method, the corrector value is used to correct the
original values obtained through Euler’s method.
ui(x'i) u'i(x"i) ui(x'i) u'i(x"i)
1 -1 1 -1
0.9 -1.289 0.885962 -1.26992
0.7711 -1.51085 0.748565 -1.46381 
0.620015 -1.64257 0.596148 -1.56975
0.455757 -1.67847 0.437415  -1.59206 
0.287911 -1.63086 0.279971 -1.54747

Table 2: Values obtained for the second-order ODE using Euler’s method(left), classical RK4(right)
Euler's method and Classical RK4 procedure is used to solve the second-order ODE. The same
process is done in determining values of x using the given condition however it includes values of the
first and second derivative of x with respect to t. As observed, the values show precision since the
resulting values are closer to each other. For the classical RK4, the methods are a little bit complex
since the derivation is up to the second derivative.
In situation 3, wherein using the same ODE, derivation of the finite difference equation is done to solve
the given ODE. However, the different condition is given in this situation that is used to derive the
equation. By using central difference approximation for the first and second derivative and by
substitution of the given condition through variable manipulation, the equation is obtained. By
substituting values of i from the derived equation the resulted values are as follows:
At i=1 At i=2
x1=2 ¿ ¿ x2=2 ¿ ¿
At i=3 At i=4
x3=2 ¿ ¿ x4=2 ¿ ¿
Situation 1:
Algorithm (Analytical solution)
Step 1: Input given ODE
Step 2: Read condition: x= [0,1]; y(x=0) =1; step size h=0.25
Step 3: Perform variable separable: Isolate dy and dx.
Step 4: Display new function
Step 5: Solve for x: if xi not equals to one, continue solving for x, hence solve for y.
Step 6: Solve for yi using function from step 4.
Step 7: Display output, y. Stop.

Pseudocode:
Step 1: Input given ODE.
Step 2: Read condition:
x= [0,1]; y(x=0) =1
step size h=0.25
Step 3: Perform variable separable:
Ny y’=M(x)
dy
(dx )
=( 1+2 x ) √ y ( dx)
dy
=( ( 1+2 x ) √ y dx )¿ / √ y
√y
dy
∫ √ y =∫ ( 1+ 2 x ) dx

2 √ y=x+ x2 +c
Get the value of c by using; y(0)=1
2 √ 1=0+0+ c
c=2
Substitute to the equation:
2 √ y=x+ x2 +2
x+ x 2 +2 2
y=( )
2
Step 4: Display new function
Step 5: Solve for x:
xi+1=i+h if x=1 solve for y, if not continue solving for x.
Step 6: Solve for y:
yi=[(xi+xi2)/2]2
Step 7: Display output y. Stop
Flowchart:

Start

Input given ODE

Read condition:
x=[0,1]; y(x=0)=1
step size h=0.25

Perform variable
separable:
Ny y’=M(x)

Display new
function

Solve for x:
xi+1=i+h

Is x=1?
No

Yes

Solve for y:
yi=[(xi+xi2)/2]2

Display
output y End
Algorithm (Euler’s Method)
Step 1: Input given ODE
Step 2: Read condition: x=[ 0,1 ] when y ( 0 ) =1 and step size h=0.25
Step 3: Input Euler’s formula
Step 4: Solve for x: if xi not equals to one, continue solving for x, hence solve for y i+1.
Step 5: Solve for yi+1 using Euler’s formula.
Step 6: Display output y
Step 7: Solve for error
Step 8: Display output e. Stop.

Pseudocode:
Step 1: Input given ODE
Step 2: Read condition:
x=[ 0,1 ] when y ( 0 ) =1 and h=0.25
Step 3: Input Euler’s formula:
‫ݕ‬௜ାଵ ൌ
‫ݕ‬௜ ൅ ݄‫݂ כ‬ሺ
‫ݔ‬௜ǡ‫ݕ‬௜ሻ

Step 4: Solve for x:


xi+1=i+h .If x=1 solve for y, if not continue solving for x.
Step 5: Solve for y using:
yi+1= yi*+h*(1+2xi)sqrt(yi)
Step 6: Display output y
Step 7: Solve for error:
ABS(yi(analytic)-yi(euler’s))/yi(analytic)
Step 8: Display output e. Stop.
Flowchart

Start

Input given ODE

Read condition:
x=[ 0,1 ] when y ( 0 ) =1∧h=0.25

Input Euler’s
formula:
‫ݕ‬௜ାଵ ൌ
‫ݕ‬௜ ൅ ݄‫݂ כ‬ሺ‫ݔ‬௜ǡ‫ݕ‬௜ሻ

Solve for x:
xi+1=i+h

No

Is x=1?

Yes

Solve for y using:


yi+1= yi*+h*(1+2xi)sqrt(yi)

Display
output y

Display
output y

Solve for error:


ABS(yi(analytic)-yi(euler’s))/yi(analytic)

Display
End
output: e
Algorithm (Heun’s method)
Step 1: Input given ODE
Step 2: Read condition: x=[ 0,1 ] when y ( 0 ) =1 and step size h=0.25
Step 3: Input Heun’s formula
Step 4: Solve for x: if xi not equals to one, continue solving for x, hence solve for y* i+1.
Step 5: Solve for y*i+1 using Euler’s formula for predictor value.
Step 6: Display output y*i+1.
Step 7: Solve for yi+1 using Euler’s formula for corrector value.
Step 8: Display output y*i+1.
Step 9: Solve for error
Step 10: Display output e. Stop.

Pseudocode:
Step 1: Input given ODE
Step 2: Read condition: x=[ 0,1 ] when y ( 0 ) =1 and step size h=0.25
Step 3: Input Heun’s formula

Step 4: Solve for x:


xi+1=xi+h. If x=1 solve for y, if not continue solving for x.
Step 5: Solve for y*i+1: y*i+1=yi + hf(xi, yi)
Step 6: Display output y*i+1.
Step 7: Solve for yi+1=yi+1=yi+h[f(xi,yi)+ f(xi+1,yi+1)/2)]
Step 8: Display output yi+1.
Step 9: Solve for error:
ABS(yi(analytic)-yi(heun’s))/yi(analytic)
Step 10: Display output e.
Flowchart:
Start

Input given ODE

Read condition:
ሾͲǡͳሿ‫ݕ ݄݊݁ݓ‬ሺͲሻ ൌ
‫ݔ‬ൌ ͳܽ݊݀ ݄ൌ
ͲǤʹ ͷ

Input Heun’s formula:

Solve for x:
xi+1=xi+h

No
Is x=1?

Yes

Solve for y*i+1 using:

Display output y*i+1

Solve for yi+1 using:

Display output yi+1

Solve for error: Display


ABS(yi(analytic)-yi(heun’s))/yi(analytic) output: e

End
Algorithm: (Classical RK4 method)

Step 1: Input given ODE


Step 2: Read condition: x=[ 0,1 ] when y ( 0 ) =1 and step size h=0.25
Step 3: Solve for x: if xi not equals to one, continue solving for x, hence solve for y i+1.
Step 4: Input classical RK4 method.
Step 5: Solve for yi+1 using the previous step.
Step 6: Display output: yi+1
Step 7: Solve for error
Step 8: Display output: e. Stop.

Pseudocode:
Step 1: Input given ODE
Step 2: Read condition: x=[ 0,1 ] when y ( 0 ) =1 and step size h=0.25
Step 3: Solve for x:
xi+1=xi+h. If x=1 solve for y, if not continue solving for x.
Step 4: Input classical RK4 method:
k 1=hf ( x i , y i )
h k
(
:k 2=hf x i + , y i + i
2 2 )
h k
(
:k 3=hf x i + , y i + 2
2 2 )
:k 4=hf ( x i +h , y i+ k 3 )
1
:Y i+1 =Y i+
6 ( k 1 + 2 k 2+ 2 k 3 + k 4 )
Step 5: Solve for yi+1 using step 4.
Step 6: Display output: yi+1
Step 7: Solve for error:
ABS(yi(analytic)-yi(RK4))/yi(analytic)
Step 8: Display output: e. Stop.

Flowchart:
Start

Input given ODE

Read condition:
ሾͲǡͳሿ‫ݕ ݄݊݁ݓ‬ሺͲሻ ൌ
‫ݔ‬ൌ ͳܽ݊݀ ݄ൌ
ͲǤʹ ͷ

Solve for x:
xi+1=xi+h

No
Is x=1?
Yes

k 1=hf ( x i , y i )

h k
(
k 2=hf x i + , y i + i
2 2 )
h k
(
k 3=hf x i + , y i + 2
2 2 )
k 4=hf ( x i +h , y i+ k 3 )

1
Y i+1 =Y i+
6 ( k 1 + 2 k 2+ 2 k 3 + k 4 )

Solve for yi+1 using:

Display output: yi+1

Solve for error:


ABS(yi(analytic)-yi(RK4))/yi(analytic)

Display output: e

End
Situation 2:
Algorithm (Euler’s method for second order ODE)
Step 1: Input given ODE
Step 2: Read condition:
1 dx
[ ]
t= 0 , , when x ( t=0 ) ( t=0 )=1 ; h=0.1
2
nd
dt
Step 3: Derived the given 2 order ODE.
Step 4: Solve for t: if ti not equals to one, continue solving for t, hence proceed to the next step.
Step 5: Solve for xi and display output.
Step 6: Solve for ui(x’i). Display output.
Step 7: Solve for u’i(x’’i): u'i(x"i)
Step 8: Display output of second order ODE: u'i(x"i). Stop.

Pseudocode:
Step 1: Input given ODE
Step 2: Read condition:
1 dx
[ ]
t= 0 , , when x ( t=0 ) ( t=0 )=1 ; h=0.1
2 dt
Step 3: Derived the second order ODE
d2 x 2 dx
: 2 −( 1−x ) + x=0
dt dt
2
d x 2 dx
: 2 =( 1−x ) −x
dt dt
2
d x dx 2 dx
: 2 = −x −x
dt dt dt
Step 4: Solve for t:
ti+1=ti+h. If t=0.5 proceed to the next step, hence continue solving for t.
Step 5: Solve for xi: xi+1=xi+h*ui(x’i)
Step 6: Solve for ui(x’i): [u(x’)]i+1=ui(x’i)+ h*ui(x’’i)
Step 7: Solve for u’i(x’’i): u'i(x"i)= x i + ui(x’i)
Step 8: Display output: u'i(x"i). Stop.
Flowchart:

Start

Input given ODE

Read condition:
1 dx
[ ]
t= 0 ,
2
, when x ( t=0 ) ( t=0 )=1 ; h=0.1
dt

Derived the second order


ODE

Solve for t:
ti+1=ti+h

No
Is t=0.5?

Yes

Solve for xi: xi+1=xi+h*ui(x’i)

Solve for ui(x’i): [u(x’)]i+1=ui(x’i)+ h*ui(x’’i)

Solve for u’i(x’’i): u'i(x"i)= xi + ui(x’i)

Display output of second


order ODE: u'i(x"i)

End
Algorithm: Second order RK4
Step 1: Input given ODE
Step 2: Read the given condition
Step 3: Let initial x equals to x and ui(x’i) equals the derivative of x with respect to t.
Step 4: Derived the second-order ODE and display output.
Step 5: Solve for t, if t equals 0.5 proceed to the next step, hence continue solving for t.
Step 6: Solve for the second-order derivative using the initial condition.
Step 7: Input: k11(i+1)a and k11(i+1)b equals to the first and derivative of x with respect to t respectively.
Step 8: Display output for k11(i+1)a and k11(i+1)b
Step 9: Solve for k21
Step 10: Display output for k21a and k21(b)
Step 11: Solve for k31
Step 12: Display output for k31a and k31(b)
Step 13: Solve for k41
Step 14: Display output for k41a and k41(b)
Step 15: Solve for k using classical RK4 formula.
Step 16: Display output ka and kb
Step 17: Solve for x(i+1) and display output.
Step 18. Solve for [u'(x)](i+1) and display output. Stop.

Pseudocode:
Step 1: Input given ODE
Step 2: Read condition:
1 dx
[ ]
t= 0 , , when x ( t=0 ) ( t=0 )=1 ; h=0.1
2 dt
dx
Step 3: Let xi=x; ui(x’i)=
dt
Step 4: Derived the second order ODE
d2 x 2 dx
: 2 −( 1−x ) + x=0
dt dt
2
d x 2 dx
: 2 =( 1−x ) −x
dt dt
2
d x dx 2 dx
: 2 = −x −x
dt dt dt
Step 5: Solve for t: ti+1=ti+h. If t=0.5 proceed to the next step, hence continue solving for t.
dx dx
Step 6: Solve for u’i(x’’i): u’i(x’’i)= −x2 −x
dt dt
Step 7: Input: k11(i+1)a= ui(x’i)
k11(i+1)b= u’i(x’’i)
Step 8: Display output:
K11(i+1)a; k11(i+1)b
Step 9: Solve for K21:
h
k21(i+1)a=ui(x’i)+ (k11(i+1)b)
2
h h
k21(i+1)b=k21(i+i)a- k21(i+1)a*(xi+ ∗¿k11(i+1)a)2-(xi+ ∗¿k11(i+1)a)
2 2
Step 10: Display output:
k21(i+1)a; k21(i+1)b
Step 11: Solve for K31:
h
k31(i+1)a=ui(x’i)+ (k21(i+1)b)
2
h h
k31(i+1)b=k31(i+i)a- k31(i+1)a*(xi+ ∗¿k21(i+1)a)2-(xi+ ∗¿k21(i+1)a)
2 2
Step 12: Display output:
K31(i+1)a; k31(i+1)b
Step 13: Solve for k41:
k41(i+1)a=ui(x’i)+h*k31(i+1)b
h h
k41(i+1)b= k41(i+1)a- k41(i+1)a*[(xi+ *k31(i+1)a)2-(xi+ *k31(i+1)a)2]
2 2
Step 14: Display output:
k41(i+1)a; k41(i+1)b
Step 15: Input RK4 formula
1
Y i+1 =Y i+ and solve for k.
6 ( k 1 + 2 k 2+ 2 k 3+ k 4 )
Step 16: Display output:
k(i+1)a; k(i+1)b
Step 17: Solve for x: x(i+1)=xi+h*k(i+1)a and display output x(i+1)
Step 18: Solve for [u'(x)](i+1)=u’(x)i+h*k(i+1)b and display output [u'(x)](i+1).Stop.
Flowchart:

Start

Input given ODE

Read condition:
1 dx
[ ]
t= 0 , , when x ( t=0 ) ( t=0 )=1 ; h=0.1
2 dt

Let xi=x; ui(x’i)=


dx
dt
Derived the second order ODE

Output:
2
d x dx 2 dx
= −x −x
dt 2 dt dt

Solve for t: ti+1=ti+h

No
Is t=0.5?

Yes
Solve for u’i(x’’i) using:

Input:
k11(i+1)a= ui(x’i)
k11(i+1)b= u’i(x’’i)

Solve for K21:


h
k21(i+1)a=ui(x’i)+ (k11(i+1)b)
2
h h
k21(i+1)b=k21(i+i)a- k21(i+1)a*(xi+ ∗¿k11(i+1)a)2-(xi+ ∗¿k11(i+1)a)
2 2
Display output:
k21(i+1)a; k21(i+1)b

Solve for K31:


h
k31(i+1)a=ui(x’i)+ (k21(i+1)b)
2
h h
k31(i+1)b=k31(i+i)a- k31(i+1)a*(xi+ ∗¿k21(i+1)a)2-(xi+ ∗¿k21(i+1)a)
2 2
Display output:
K31(i+1)a; k31(i+1)b

Solve for k41:


k41(i+1)a=ui(x’i)+h*k31(i+1)b
h
k41(i+1)b= k41(i+1)a- k41(i+1)a*[(xi+ *k31(i+1)a)2-
2
h
(xi+ *k31(i+1)a)2]
2
Display output:
K41(i+1)a; k41(i+1)b

Input RK4 formula


1
Y i+1 =Y i+
6 ( k 1 + 2 k 2+ 2 k 3 + k 4 )

Solve for K

Display output:
k(i+1)a; k(i+1)b

Solve for x:
x(i+1)=xi+h*k(i+1)a

Display output:
x(i+1)
Solve for [u'(x)]
(i+1)=u’(x)i+h*k(i+1)b

Display output:
[u'(x)](i+1)

End

You might also like