How to resolve the algorithm Runge-Kutta method step by step in the Crystal programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Runge-Kutta method step by step in the Crystal programming language
Table of Contents
Problem Statement
Given the example Differential equation: With initial condition: This equation has an exact solution:
Demonstrate the commonly used explicit fourth-order Runge–Kutta method to solve the above differential equation.
Starting with a given
y
n
{\displaystyle y_{n}}
and
t
n
{\displaystyle t_{n}}
calculate: then:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Runge-Kutta method step by step in the Crystal programming language
Source code in the crystal programming language
y, t = 1, 0
while t <= 10
k1 = t * Math.sqrt(y)
k2 = (t + 0.05) * Math.sqrt(y + 0.05 * k1)
k3 = (t + 0.05) * Math.sqrt(y + 0.05 * k2)
k4 = (t + 0.1) * Math.sqrt(y + 0.1 * k3)
printf("y(%4.1f)\t= %12.6f \t error: %12.6e\n", t, y, (((t**2 + 4)**2 / 16) - y )) if (t.round - t).abs < 1.0e-5
y += 0.1 * (k1 + 2 * (k2 + k3) + k4) / 6
t += 0.1
end
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Julia programming language
You may also check:How to resolve the algorithm Empty program step by step in the Delphi programming language
You may also check:How to resolve the algorithm Catamorphism step by step in the BASIC programming language
You may also check:How to resolve the algorithm Hostname step by step in the Crystal programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Icon and Unicon programming language