σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Calculus skill›Module 3 · Approximation and dynamics›Topic 3.2·~50 minIntermediate

Differential equations: Euler and RK4

Skill positionModule 3 of 4 · Topic 2 of 2
3.2 Differential equations: Euler and RK4
—Lab score— / 100Total XP—Streak—

Following a rate of change

A differential equation states how fast a quantity changes: dydt=f(t,y)\frac{dy}{dt}=f(t,y)dtdy​=f(t,y). Money growing at a continuous rate rrr obeys dydt=ry\frac{dy}{dt}=rydtdy​=ry, with solution y0erty_0e^{rt}y0​ert. A short rate pulled back to a long-run level θ\thetaθ obeys drdt=κ(θ−r)\frac{dr}{dt}=\kappa(\theta-r)dtdr​=κ(θ−r). Few equations have a formula for the solution, so we step through time numerically.

yn+1=yn+h f(tn,yn)y_{n+1}=y_n+h\,f(t_n,y_n)yn+1​=yn​+hf(tn​,yn​)(1)

Euler's method follows the tangent for one short step hhh: new value = old value + step × slope. It is simple but only first-order accurate: halving hhh halves the error. Runge–Kutta of order 4 (RK4) samples the slope four times per step and blends them, yn+1=yn+h6(k1+2k2+2k3+k4)y_{n+1}=y_n+\frac{h}{6}(k_1+2k_2+2k_3+k_4)yn+1​=yn​+6h​(k1​+2k2​+2k3​+k4​), and its error shrinks like h4h^4h4: halving hhh divides it by 16.

Growth at rate 1, two waysSolve y′=yy'=yy′=y, y(0)=1y(0)=1y(0)=1 up to t=1t=1t=1 with h=0.5h=0.5h=0.5. Euler: y1=1+0.5⋅1=1.5y_1=1+0.5\cdot1=1.5y1​=1+0.5⋅1=1.5, y2=1.5+0.5⋅1.5=2.25y_2=1.5+0.5\cdot1.5=2.25y2​=1.5+0.5⋅1.5=2.25, against e=2.7183e=2.7183e=2.7183, an error of 0.4683. RK4 for one step to t=0.5t=0.5t=0.5: k1=1k_1=1k1​=1, k2=1.25k_2=1.25k2​=1.25, k3=1.3125k_3=1.3125k3​=1.3125, k4=1.65625k_4=1.65625k4​=1.65625, so y=1+0.56(1+2.5+2.625+1.65625)=1.6484y=1+\frac{0.5}{6}(1+2.5+2.625+1.65625)=1.6484y=1+60.5​(1+2.5+2.625+1.65625)=1.6484, against the true e0.5=1.6487e^{0.5}=1.6487e0.5=1.6487.
  • Euler: yn+1=yn+h f(tn,yn)y_{n+1}=y_n+h\,f(t_n,y_n)yn+1​=yn​+hf(tn​,yn​), first-order accurate.
  • RK4: four slopes per step blended with weights 1, 2, 2, 1; fourth-order accurate.
  • Truncation error: what is lost by stepping instead of solving exactly.
A smaller step is not freeHalving the step doubles the number of steps. Past a point, rounding error grows while truncation error no longer matters, and some stiff equations blow up unless the step is small enough. Compare two step sizes to estimate the error before you trust a result.

Lab · what's graded

  • Two Euler steps15 pts
  • The Euler error15 pts
  • One RK4 step20 pts
  • Orders of accuracy10 pts
  • Halving the step15 pts
  • The Euler loop10 pts
  • Why RK4 beats Euler15 pts
0/ 7 answered
Tasks
1Numeric answer15 ptsNot answered

Consider y′=yy'=yy′=y with y(0)=1y(0)=1y(0)=1 and step h=0.5h=0.5h=0.5. Take two Euler steps and give y2y_2y2​ (the estimate of y(1)y(1)y(1)).

y2=y_2 =y2​=accepted: ± 0.001
2Numeric answer15 ptsNot answered

Consider y′=yy'=yy′=y with y(0)=1y(0)=1y(0)=1 and step h=0.5h=0.5h=0.5. The exact solution is y(1)=e=2.7183y(1)=e=2.7183y(1)=e=2.7183. How far is the Euler estimate y2=2.25y_2=2.25y2​=2.25 from it?

error=\text{error} =error=accepted: ± 0.001
3Numeric answer20 ptsNot answered

Consider y′=yy'=yy′=y with y(0)=1y(0)=1y(0)=1 and step h=0.5h=0.5h=0.5. Take one RK4 step from t=0t=0t=0 and give y1y_1y1​, the estimate of y(0.5)y(0.5)y(0.5), to 4 decimals. For f(t,y)=yf(t,y)=yf(t,y)=y: k1=ynk_1=y_nk1​=yn​, k2=yn+h2k1k_2=y_n+\frac{h}{2}k_1k2​=yn​+2h​k1​, k3=yn+h2k2k_3=y_n+\frac{h}{2}k_2k3​=yn​+2h​k2​, k4=yn+hk3k_4=y_n+hk_3k4​=yn​+hk3​.

y1=y_1 =y1​=accepted: ± 0.0002
4Choice10 ptsNot answered

What are the orders of accuracy of Euler's method and of RK4?

5Numeric answer15 ptsNot answered

Euler's method has error 0.08 with step h=0.1h=0.1h=0.1. About what error do you expect with h=0.05h=0.05h=0.05?

error=\text{error} =error=accepted: ± 0.005
6Order the steps10 ptsNot answered

Put the steps of one Euler iteration in order.

Drag to reorder, or focus an item, press Space to lift it, the arrow keys to move it and Space to drop it.

  1. 1Update y←y+h⋅slopey\leftarrow y+h\cdot\text{slope}y←y+h⋅slope
  2. 2Start from the initial values t0t_0t0​ and y0y_0y0​
  3. 3Advance time t←t+ht\leftarrow t+ht←t+h and repeat
  4. 4Compute the slope f(t,y)f(t,y)f(t,y) at the current point
7Explain in words15 ptsNot answered

In two or three sentences, explain why RK4 is usually more accurate than Euler for the same step size and what it costs.

Math modeKeyboard or LaTeX inputTask 1 of 7 · Ctrl ⏎ to check

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub