Jump to content

Runge-Kutta method: Difference between revisions

Line 1,119:
 
=={{header|Excel}}==
<syntaxhighlight lang="Excel">PRINT "RungaKutta4λ(D)"</syntaxhighlight>
//Worksheet formula to manage looping
 
=LET(
Line 1,132:
)
 
//Lambda function passed to RK4RungaKutta4λ to evaluate derivatives
 
Dλ(y,t)
= LAMBDA(y,t, t * SQRT(y))
 
//Curried Lambda function with derivative function D and y, t as parameters
 
RungaKutta4λ(Dλ)
= LAMBDA(D,
LAMBDA(yᵣ, tᵣ,
LET(
δ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₃, tᵣ + δt),
yᵣ₊₁, yᵣ + (δy₁ + 2 * δy₂ + 2 * δy₃ + δy₄) / 6,
yᵣ₊₁
)
)
)
)
 
//Lambda function returning the exact solution
 
f(t)
= LAMBDA(t, (1 / 16) * (t ^ 2 + 4) ^ 2 )
</syntaxhighlight>
 
Results
{{out}}
<pre>
4

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.