benchmarks.wiki / Public workspace

SciCode / 78.2 / Write a fourth-order fixed-time-step Runge-Kutta (RK4) integrator from scratch…

Problem

Answer published by the source. Consult the official source to check your work against its answer.

step description prompt

Write a fourth-order fixed-time-step Runge-Kutta (RK4) integrator from scratch in Python, to calculate θ\theta and ω\omega at any certain timepoint. The output of this procedure — a series of state vectors representing the n-point state-space trajectory emanating from ~x(t0). Do not use any canned numerical integration routines, commands, functions.
Plain-text mathematical notation (without MathML)
Write a fourth-order fixed-time-step Runge-Kutta (RK4) integrator from scratch in Python, to calculate θ and ω at any certain timepoint. The output of this procedure — a series of state vectors representing the n-point state-space trajectory emanating from ~x(t0). Do not use any canned numerical integration routines, commands, functions.
Original LaTeX notation
Write a fourth-order fixed-time-step Runge-Kutta (RK4) integrator from scratch in Python, to calculate $\theta$ and $\omega$ at any certain timepoint. The output of this procedure — a series of state vectors representing the n-point state-space trajectory emanating from ~x(t0). Do not use any canned numerical integration routines, commands, functions.

step background

Background Given an initial value problem of the form: dydt=f(t,y),y(t0)=y0 \frac{dy}{dt} = f(t, y), \quad y(t_0) = y_0 the RK4 method updates the solution yy from time tt to t+Δtt + \Delta t using the following steps: **2.1 Calculate intermediate slopes:** - k1=f(t,y)k_1 = f(t, y) - k2=f(t+Δt2,y+k1Δt2)k_2 = f(t + \frac{\Delta t}{2}, y + \frac{k_1 \Delta t}{2}) - k3=f(t+Δt2,y+k2Δt2)k_3 = f(t + \frac{\Delta t}{2}, y + \frac{k_2 \Delta t}{2}) - k4=f(t+Δt,y+k3Δt)k_4 = f(t + \Delta t, y + k_3 \Delta t) **2.2 Update the solution:** y(t+Δt)=y(t)+Δt6(k1+2k2+2k3+k4) y(t + \Delta t) = y(t) + \frac{\Delta t}{6} (k_1 + 2k_2 + 2k_3 + k_4) In our case, *yy* represents the state vector of the system, which includes the angle *θ\theta* and the angular velocity *ω\omega*.
Plain-text mathematical notation (without MathML)
Background

Given an initial value problem of the form:

(dy)/(dt)=f(t,y), y(t₀)=y₀

the RK4 method updates the solution y from time t to t+Δt using the following steps:

**2.1 Calculate intermediate slopes:**
   - k₁=f(t,y)
   - k₂=f(t+(Δt)/(2),y+(k₁Δt)/(2))
   - k₃=f(t+(Δt)/(2),y+(k₂Δt)/(2))
   - k₄=f(t+Δt,y+k₃Δt)

**2.2 Update the solution:**

   y(t+Δt)=y(t)+(Δt)/(6)(k₁+2k₂+2k₃+k₄)

In our case, *y* represents the state vector of the system, which includes the angle *θ* and the angular velocity *ω*.
Original LaTeX notation
Background

Given an initial value problem of the form:

$$
\frac{dy}{dt} = f(t, y), \quad y(t_0) = y_0
$$

the RK4 method updates the solution $y$ from time $t$ to $t + \Delta t$ using the following steps:

**2.1 Calculate intermediate slopes:**
   - $k_1 = f(t, y)$
   - $k_2 = f(t + \frac{\Delta t}{2}, y + \frac{k_1 \Delta t}{2})$
   - $k_3 = f(t + \frac{\Delta t}{2}, y + \frac{k_2 \Delta t}{2})$
   - $k_4 = f(t + \Delta t, y + k_3 \Delta t)$

**2.2 Update the solution:**

   $$
   y(t + \Delta t) = y(t) + \frac{\Delta t}{6} (k_1 + 2k_2 + 2k_3 + k_4)
   $$

In our case, *$y$* represents the state vector of the system, which includes the angle *$\theta$* and the angular velocity *$\omega$*.

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import