Numerical methods: practice problems with step-by-step solutions

Also called: numerical analysis · Newton’s method · Simpson’s rule · Euler’s method

Free Numerical methods practice problems with diagrams, hints and full worked solutions. New values every time, at three levels: roots and interpolation, trapezoid and Simpson rules, Euler, Heun and Runge–Kutta.

Free practice problemEasy
xyx₀ = 0

Apply Newton–Raphson to f(x) = e−x − x with the starting value x₀ = 0. Find x2.

f(x) = e−x − xf′(x) = −e−x − 1x₀ = 0
Next problem →

What you practise

  1. Easyroots and interpolation
  2. Mediumtrapezoid and Simpson rules
  3. HardEuler, Heun and Runge–Kutta

How to solve Numerical methods problems

  1. For a root: check the sign change for bisection, or compute f and f′ for Newton, and keep six or more digits in a table of iterates.
  2. For a table value: interpolate linearly between the two neighbouring points.
  3. For an integral: find h = (b − a)/n, list f at every node, apply the weights (1, 2, …, 2, 1 for trapezoid; 1, 4, 2, …, 4, 1 for Simpson with even n) and multiply by h/2 or h/3.
  4. For an ODE: step from t₀ with yₙ₊₁ = yₙ + h·f(tₙ, yₙ) (Euler) or the averaged slope (Heun), one row per step, until you reach the requested t.

Common mistakes

  • Keeping the wrong half of the bisection interval, or miscounting the steps.
  • Writing x − f′/f instead of x − f/f′ in Newton–Raphson.
  • Giving interior nodes weight 1 in the trapezoid rule, or using Simpson with an odd number of strips.
  • Rounding iterates too early.
  • Doing one Euler step too few or too many to reach the final time.

Key formulas

Bisection
c = (a + b)/2, width after n steps (b − a)/2ⁿ
Newton–Raphson
xn+1 = xₙ − f(xₙ)/f′(xₙ)
Linear interpolation
y = y₁ + (y₂ − y₁)(x − x₁)/(x₂ − x₁)
Trapezoid rule
T = (h/2)[f₀ + 2f₁ + … + 2fn−1 + fₙ], h = (b − a)/n
Simpson’s rule (n even)
S = (h/3)[f₀ + 4f₁ + 2f₂ + … + 4fn−1 + fₙ]
Trapezoid error bound
|E| ≤ (b − a)h²M/12, M = max|f″|
Euler
yn+1 = yₙ + h·f(tₙ, yₙ)
Heun
yn+1 = yₙ + (h/2)(k₁ + k₂), k₂ = f(tₙ + h, yₙ + hk₁)
RK4
yn+1 = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄)

Learn Numerical methods from scratch

Before this: Derivatives, Integrals, Differential equations

1Why numerical methods, and bisection

Many equations and integrals have no formula for their answer: x = cos x, ∫e−x²dx, or most differential equations. Numerical methods compute the answer step by step to any accuracy you need.

The bisection method finds a root of f(x) = 0 on an interval [a, b] where f changes sign. Take the midpoint c = (a + b)/2 and keep the half where the sign still changes.

Example: f(x) = x² − 2 on [1, 2]. c₁ = 1.5 gives f = 0.25 > 0, so keep [1, 1.5]. c₂ = 1.25 gives f = −0.4375 < 0, so keep [1.25, 1.5]. Then c₃ = 1.375.

Each step halves the interval, so after n steps its width is (b − a)/2ⁿ. Bisection is slow but it always works once you have a sign change.

Self-check Bisection starts on an interval of length 1. How wide is the interval after 10 steps?
  1. 1/100
  2. 1/1024
  3. 1/10
  4. 1/20

Answer: 1/1024. Every step halves it: 1/2¹⁰ = 1/1024 ≈ 0.001. Dividing by 10 or 20 treats the halving as if it were additive.

2Newton–Raphson

Newton–Raphson follows the tangent line down to the x-axis and uses that crossing as the next guess:

xn+1 = xₙ − f(xₙ)/f′(xₙ)
xx₀ = 2x₁ = 1.5√2f(x) = x² − 2

For f(x) = x² − 2 with f′(x) = 2x and x₀ = 2: x₁ = 2 − 2/4 = 1.5, x₂ = 1.5 − 0.25/3 = 1.416667, x₃ = 1.414216. The root is √2 = 1.414214.

Near the root, Newton roughly doubles the number of correct digits in every step. It can fail when f′(xₙ) is close to 0, or when the start is far from the root.

Keep at least six digits in every iterate; rounding early stops the method from improving.

Self-check One Newton step for f(x) = x² − 5 from x₀ = 2 gives…
  1. 1.75
  2. 2.25
  3. 2.2
  4. 2.5

Answer: 2.25. f(2) = −1 and f′(2) = 4, so x₁ = 2 − (−1)/4 = 2.25. Adding −1/4 instead of subtracting it gives 1.75.

3Linear interpolation

Tables give values only at certain points. Linear interpolation draws a straight line between the two neighbouring table points:

y = y₁ + (y₂ − y₁)·(x − x₁)/(x₂ − x₁)

Example: the table gives f(1) = 2.0 and f(2) = 2.6. At x = 1.4 the fraction is 0.4, so f(1.4) ≈ 2.0 + 0.6·0.4 = 2.24.

Inverse interpolation works the same way the other way round: to find where y = 2.3, the fraction is (2.3 − 2.0)/0.6 = 0.5, so x ≈ 1.5.

4Trapezoid rule and Simpson’s rule

To integrate f from a to b, split the interval into n strips of width h = (b − a)/n with nodes x₀, x₁, …, xₙ.

The trapezoid rule replaces the curve in each strip by a straight line. Every interior node belongs to two strips, so it counts twice:

T = (h/2)[f₀ + 2f₁ + 2f₂ + … + 2fn−1 + fₙ]
0.51y = x²x

Simpson’s rule fits parabolas through three nodes at a time. It needs an even n:

S = (h/3)[f₀ + 4f₁ + 2f₂ + 4f₃ + … + 4fn−1 + fₙ]

For ∫01 x² dx = 1/3 with n = 2 (h = 0.5): T = 0.25·(0 + 0.5 + 1) = 0.375, while S = (0.5/3)·(0 + 1 + 1) = 0.3333, exact.

The trapezoid error shrinks like h² and Simpson’s like h⁴: halving h makes Simpson about 16 times more accurate.

Self-check Which weights does the trapezoid rule give the nodes x₀, x₁, x₂, x₃?
  1. 1, 1, 1, 1
  2. 1, 2, 2, 1
  3. 1, 4, 2, 1
  4. 1, 4, 4, 1

Answer: 1, 2, 2, 1. The two end points belong to one strip and the interior points to two, so 1, 2, 2, 1 with the factor h/2. The 4s belong to Simpson’s rule.

5Euler and Heun for differential equations

For y′ = f(t, y) with y(t₀) = y₀, step forward in time with a step h. Euler’s method uses the slope at the start of each step:

yn+1 = yₙ + h·f(tₙ, yₙ)

Heun’s method (improved Euler) predicts with Euler, then averages the slopes at both ends: k₁ = f(tₙ, yₙ), k₂ = f(tₙ + h, yₙ + h·k₁), yn+1 = yₙ + (h/2)(k₁ + k₂).

Euler’s error is proportional to h, Heun’s to h². The classical Runge–Kutta method (RK4) uses four slopes and is accurate to h⁴.

Worked example

Solve y′ = y, y(0) = 1 with Euler’s method and h = 0.1 up to t = 0.3, and compare with the exact solution eᵗ.

1

Step 1

y₁ = 1 + 0.1·1 = 1.1
2

Step 2

y₂ = 1.1 + 0.1·1.1 = 1.21
3

Step 3

y₃ = 1.21 + 0.1·1.21 = 1.331
4

Compare

The exact value is e0.3 = 1.349859, so the global error is 0.0189. One Heun step from y₀ would give 1 + 0.05·(1 + 1.1) = 1.105 against e0.1 = 1.105171.

Answer

y(0.3) ≈ 1.331 with Euler; the error 0.019 shrinks roughly in proportion to h.

6Common mistakes and exam questions

  • Counting the first bisection midpoint as step 0, or keeping the wrong half of the interval.
  • Writing x − f′/f instead of x − f/f′ in Newton’s method.
  • Forgetting the factor 2 on interior nodes, or using h instead of h/2 in the trapezoid rule.
  • Using Simpson’s rule with an odd number of strips.
  • In Euler’s method, using the slope at the end of the step, or doing one step too few.

Easy: bisection, Newton iterations and interpolation in a table. Medium: the trapezoid and Simpson rules, their error and the number of strips needed. Hard: Euler, Heun and Runge–Kutta steps for differential equations.

Self-check y′ = 2y with y(0) = 1. What does one Euler step with h = 0.2 give?
  1. 1.2
  2. 1.49
  3. 1.4
  4. 2.4

Answer: 1.4. y₁ = 1 + 0.2·(2·1) = 1.4. Forgetting the factor 2 in the slope gives 1.2; 1.49 is the exact value e0.4.

Learn it step by step in the appLearn it step by step in the app

Worked examples

Example 1Easy

The bisection method starts on an interval of length 4. Every step halves the interval. How many steps n are needed at least before the interval is shorter than 0.0001?

b − a = 4ε = 0.0001

Find n

Show hints
  1. After n steps the interval has length (b − a)/2ⁿ.
  2. Solve 4/2ⁿ < 0.0001, so 2ⁿ > 40000.
  3. n > log₂(40000) = 15.29
Show the answer and the step-by-step solution

Root finding and interpolation: bisection keeps an interval [a, b] on which f changes sign; each step takes the midpoint c = (a + b)/2 and keeps the half where the sign still changes, so after n steps the interval is (b − a)/2ⁿ wide. Newton–Raphson follows the tangent line to the axis: xn+1 = xn − f(xn)/f′(xn); near a simple root it roughly doubles the number of correct digits per step. Linear interpolation between two table points: y = y₁ + (y₂ − y₁)(x − x₁)/(x₂ − x₁).

Condition

4/2ⁿ < 0.0001 → 2ⁿ > 40000

Logarithm

n > ln(40000)/ln 2 = 15.29
n = 16

Check

2¹⁵ = 32768 < 40000 < 2¹⁶ = 65536

Answer

n = 16
Example 2Medium
xy00.511.5

Approximate ∫01.5 √(1 + x³) dx with the trapezoid rule using n = 3 strips. Give T.

f(x) = √(1 + x³)[a, b] = [0, 1.5]n = 3

Find T

Show hints
  1. h = (1.5 − 0)/3 = 0.5; the nodes are 0, 0.5, 1, 1.5.
  2. Weights: 1, 2, 2, …, 2, 1; T = (h/2)·Σ wᵢfᵢ.
  3. The weighted sum is Σ wᵢfᵢ = 8.041398.
Show the answer and the step-by-step solution

Numerical integration: split [a, b] into n strips of width h = (b − a)/n with nodes x₀ … xₙ. Trapezoid rule: T = (h/2)[f₀ + 2f₁ + 2f₂ + … + 2fn−1 + fₙ]. Simpson's rule (n even): S = (h/3)[f₀ + 4f₁ + 2f₂ + 4f₃ + … + 4fn−1 + fₙ]. The trapezoid error shrinks like h² (bound (b − a)h²·M/12 with M = max|f″|), Simpson's like h⁴, so Simpson is usually far more accurate for the same nodes.

ixᵢf(xᵢ)weight001110.51.060662211.414214231.52.091651

Nodes and values

h = 0.5
Σ wᵢfᵢ = 1 + 2·1.06066 + 2·1.414214 + 2.09165 = 8.041398

Trapezoid rule

T = (0.5/2)·8.041398 = 2.01

Answer

T = 2.01

This integral has no elementary antiderivative, which is exactly when a numerical rule is needed.

Example 3Hard
00.10.20.30.40.40.60.81ty(0, 0.5)

Use Heun's method (improved Euler) with h = 0.2 for y′ = 1 + sin(ty), y(0) = 0.5 to estimate y2 ≈ y(0.4).

y′ = 1 + sin(ty)y(0) = 0.5h = 0.2

Find y2

Show hints
  1. Each step: k₁ = f(tₙ, yₙ), k₂ = f(tₙ + h, yₙ + h·k₁), yn+1 = yₙ + (h/2)(k₁ + k₂).
  2. Step 1: k₁ = 1, k₂ = 1.139543, y₁ = 0.713954.
  3. You need 2 steps to reach t = 0.4.
Show the answer and the step-by-step solution

Numerical solution of y′ = f(t, y): Euler's method steps along the slope at the start of each step: yn+1 = yₙ + h·f(tₙ, yₙ). Heun's method (improved Euler) averages the slope at the start and at an Euler prediction: k₁ = f(tₙ, yₙ), k₂ = f(tₙ + h, yₙ + h·k₁), yn+1 = yₙ + (h/2)(k₁ + k₂). The classical Runge–Kutta method (RK4) combines four slopes: yn+1 = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄). The global error of Euler is proportional to h, Heun's to h², RK4's to h⁴.

ntₙyₙk₁k₂yₙ₊₁000.511.1395430.71395410.20.7139541.1423061.3681010.964995

Heun steps

y₁ = 0.5 + (0.2/2)(1 + 1.139543) = 0.713954
y₂ = 0.713954 + (0.2/2)(1.142306 + 1.368101) = 0.964995
00.10.20.30.40.40.60.81ty

Graph

y2 = 0.965

Answer

y2 = 0.965

Questions and answers

What is Numerical methods?

Many equations and integrals have no formula for their answer: x = cos x, ∫e−x²dx, or most differential equations. Numerical methods compute the answer step by step to any accuracy you need.

The bisection method finds a root of f(x) = 0 on an interval [a, b] where f changes sign. Take the midpoint c = (a + b)/2 and keep the half where the sign still changes.

How do I solve Numerical methods problems step by step?
  1. For a root: check the sign change for bisection, or compute f and f′ for Newton, and keep six or more digits in a table of iterates.
  2. For a table value: interpolate linearly between the two neighbouring points.
  3. For an integral: find h = (b − a)/n, list f at every node, apply the weights (1, 2, …, 2, 1 for trapezoid; 1, 4, 2, …, 4, 1 for Simpson with even n) and multiply by h/2 or h/3.
  4. For an ODE: step from t₀ with yₙ₊₁ = yₙ + h·f(tₙ, yₙ) (Euler) or the averaged slope (Heun), one row per step, until you reach the requested t.
What are common mistakes in Numerical methods?
  • Keeping the wrong half of the bisection interval, or miscounting the steps.
  • Writing x − f′/f instead of x − f/f′ in Newton–Raphson.
  • Giving interior nodes weight 1 in the trapezoid rule, or using Simpson with an odd number of strips.
  • Rounding iterates too early.
  • Doing one Euler step too few or too many to reach the final time.
What do the Numerical methods exercises cover?
  • Easy: roots and interpolation
  • Medium: trapezoid and Simpson rules
  • Hard: Euler, Heun and Runge–Kutta

Every problem has new values, so you learn the method instead of an answer. Stuck? Open a small hint first, and the full explanation only when you need it.

How practising works

  • Every problem has new values, so you learn the method instead of an answer.
  • Stuck? Open a small hint first, and the full explanation only when you need it.
  • Your progress, mistakes and saved problems are kept, so you can review before the exam.

Topics before and after this one

Learn first

Courses with this topic

More topics in Mathematics & statistics

Printable worksheet