Runge-Kutta method: Difference between revisions

Content added Content deleted
Line 1,119: Line 1,119:


=={{header|Excel}}==
=={{header|Excel}}==
<syntaxhighlight lang="Excel">PRINT "RungaKutta4λ(D)"</syntaxhighlight>
<syntaxhighlight lang="Excel">
Worksheet formula to manage looping
//Worksheet formula to manage looping


=LET(
=LET(
Line 1,132: Line 1,132:
)
)


Lambda function passed to RK4 to evaluate derivatives
//Lambda function passed to RungaKutta4λ to evaluate derivatives


Dλ(y,t)
Dλ(y,t)
= LAMBDA(y,t, t * SQRT(y))
= LAMBDA(y,t, t * SQRT(y))


Curried Lambda function with derivative function and y, t as parameters
//Curried Lambda function with derivative function D and y, t as parameters

RungaKutta4λ(Dλ)
RungaKutta4λ(Dλ)
= LAMBDA(D,
= LAMBDA(D,
LAMBDA(yᵣ, tᵣ,
LAMBDA(yᵣ, tᵣ,
LET(
LET(
δy₁, δt * D(yᵣ, tᵣ),
δy₁, δt * D(yᵣ, tᵣ),
δy₂, δt * D(yᵣ + δy₁ / 2, tᵣ + δt / 2),
δy₂, δt * D(yᵣ + δy₁ / 2, tᵣ + δt / 2),
δy₃, δt * D(yᵣ + δy₂ / 2, tᵣ + δt / 2),
δy₃, δt * D(yᵣ + δy₂ / 2, tᵣ + δt / 2),
δy₄, δt * D(yᵣ + δy₃, tᵣ + δt),
δy₄, δt * D(yᵣ + δy₃, tᵣ + δt),
yᵣ₊₁, yᵣ + (δy₁ + 2 * δy₂ + 2 * δy₃ + δy₄) / 6,
yᵣ₊₁, yᵣ + (δy₁ + 2 * δy₂ + 2 * δy₃ + δy₄) / 6,
yᵣ₊₁
yᵣ₊₁
)
)
)
)
)
)


Lambda function returning the exact solution
//Lambda function returning the exact solution

f(t)
f(t)
= LAMBDA(t, (1 / 16) * (t ^ 2 + 4) ^ 2 )
= LAMBDA(t, (1/16) * (t^2 + 4)^2 )
</syntaxhighlight>


Results
{{out}}
{{out}}
<pre>
<pre>