Read this lesson as text

Euler's Method Examples

Numerical Analysis · Axiom Academy

EXAMPLE Euler's Method: Solving an ODE Step-by-step walkthrough of numerical ODE solving Solve the initial value problem using Euler's method: Use step size h = 0.25 from t = 0 to t = 1 . Compare with the exact solution . Step 1: Setup - Identify the Components Euler's method uses the formula: For our problem y' = -2y with y(0) = 1 and h = 0.25, identify f(t, y): f(t, y) = -2y (the right-hand side of the ODE) Initial condition: t 0 = 0, y 0 = 1 Number of steps: (1 - 0) / 0.25 = 4 steps Step 2: First Step (t = 0 to t = 0.25) Calculate y 1 using Euler's formula: With t 0 = 0, y 0 = 1, h = 0.25, and f(t, y) = -2y, what is y 1 ? Evaluate f(t 0 , y 0 ) = f(0, 1) = -2(1) = -2 Multiply by step size: h * f = 0.25 * (-2) = -0.5 Add to current value: y 1 = 1 + (-0.5) = 0.5 Exact value: e -0.5 = 0.6065... (Euler underestimates!) Step 3: Second Step (t = 0.25 to t = 0.5) Now use y 1 = 0.5 at t 1 = 0.25 to find y 2 : Evaluate f(t 1 , y 1 ) = f(0.25, 0.5) = -2(0.5) = -1 Multiply by step size: h * f = 0.25 * (-1) = -0.25 Add to current value: y 2 = 0.5 + (-0.25) = 0.25 Exact value: e -1 = 0.3679... (Error growing!) Step 4: Complete Steps 3 and 4 Following the same pattern, what are y 3 and y 4 ? Recall: y n+1 = y n + h * (-2y n ) = y n (1 - 2h) = y n (0.5) Each step multiplies by (1 - 2h) = (1 - 0.5) = 0.5: y 3 = 0.25 * 0.5 = 0.125 at t = 0.75 y 4 = 0.125 * 0.5 = 0.0625 at t = 1.0 Step 5: Comparison with Exact Solution

This is the written version of the interactive lesson above. See the full Numerical Analysis course.