Runge-Kutta method: Difference between revisions

Content deleted Content added
Grondilu (talk | contribs)
m →‎{{header|C++}}: remove useless header (it was considered as an alternative to WHOLE_TOLERANCE)
Alextretyak (talk | contribs)
Added 11l
Line 24: Line 24:
:<math>t_{n+1} = t_n + \delta t\quad</math>
:<math>t_{n+1} = t_n + \delta t\quad</math>
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Python}}

<lang 11l>F rk4(f, x0, y0, x1, n)
V vx = [0.0] * (n + 1)
V vy = [0.0] * (n + 1)
V h = (x1 - x0) / Float(n)
V x = x0
V y = y0
vx[0] = x
vy[0] = y
L(i) 1..n
V k1 = h * f(x, y)
V k2 = h * f(x + 0.5 * h, y + 0.5 * k1)
V k3 = h * f(x + 0.5 * h, y + 0.5 * k2)
V k4 = h * f(x + h, y + k3)
vx[i] = x = x0 + i * h
vy[i] = y = y + (k1 + k2 + k2 + k3 + k3 + k4) / 6
R (vx, vy)

F f(Float x, Float y) -> Float
R x * sqrt(y)

V (vx, vy) = rk4(f, 0.0, 1.0, 10.0, 100)
L(x, y) zip(vx, vy)[(0..).step(10)]
print(‘#2.1 #4.5 #2.8’.format(x, y, y - (4 + x * x) ^ 2 / 16))</lang>

{{out}}
<pre>
0.0 1.00000 0.00000000
1.0 1.56250 -1.45721892e-7
2.0 4.00000 -9.194792e-7
3.0 10.56250 -0.00000291
4.0 24.99999 -0.00000623
5.0 52.56249 -0.00001082
6.0 99.99998 -0.00001659
7.0 175.56248 -0.00002352
8.0 288.99997 -0.00003157
9.0 451.56246 -0.00004072
10.0 675.99995 -0.00005098
</pre>


=={{header|Ada}}==
=={{header|Ada}}==