This course contains the concepts of numerical method techniques for solving linear and nonlinear equations, interpolation and regression, differentiation and integration, and partial differential equations.
CSC212Semester III3 credit hours6 units72 solved questions920 study cardsFull study modes
This course contains the concepts of numerical method techniques for solving linear and nonlinear equations, interpolation and regression, differentiation and integration, and partial differential equations.
The free sample is open to everyone. Sign in for 2 free weeks of every answer, flashcards and progress.
Numerical methods replace exact analytical solutions with systematic arithmetic procedures that converge on an answer to a controlled accuracy. This chapter builds the error vocabulary needed to judge that accuracy, then develops the classical iterative methods used to solve a single nonlinear equation $f(x) = 0$ when no closed-form formula exists.
Every computed result differs from the true value by some amount, and this difference is called error. The true error $E_t$ is the true (exact) value minus the approximate value, $$E_t = \text{true value} - \text{approximate value}.$$ Since the true value is rarely known in a numerical calculation, the approximate error $E_a$ is used instead: the difference between the current and the previous approximation, $$E_a = \text{present approximation} - \text{previous approximation}.$$ Both errors are more meaningfully expressed relative to the value they are measured against. The true relative error is $E_{rt} = E_t / (\text{true value})$ and the approximate relative error is $E_{ra} = E_a / (\text{present approximation})$; multiplying either by 100 gives a percentage error. In iterative methods, $|E_{ra}|$ is the practical stopping test: iteration continues until $|E_{ra}|$ falls below a preset tolerance.
Worked example. For $f(x) = 7e^{0.5x}$ at $x = 2$, the derivative can be approximated by the forward difference $f'(x) \approx \dfrac{f(x+h) - f(x)}{h}$. With $h = 0.3$, $$f'(2) \approx \frac{f(2.3) - f(2)}{0.3} = \frac{22.107 - 19.028}{0.3} = 10.2646.$$ The exact derivative is $f'(x) = 3.5e^{0.5x}$, so $f'(2) = 9.5140$. The true error is $$E_t = 9.5140 - 10.2646 = -0.7506,$$ and the true relative error is $E_{rt} = -0.7506/9.5140 = -0.0789$, or $-7.89%$. Repeating with $h = 0.15$ gives $f'(2) \approx 9.8799$; the approximate error is $E_a = 9.8799 - 10.2646 = -0.3847$, so $|E_{ra}| = 0.3847/9.8799 = 3.89%$. Halving $h$ roughly halved the error, as expected of a first-order forward-difference approximation.
Two error sources dominate numerical computation. Round-off error arises because a computer stores only a finite number of digits, so numbers such as $1/3 = 0.3333\ldots$ must be truncated to a fixed word length; the stored value and the exact value then differ by a small residual at every arithmetic step, and this residual can accumulate over many operations. Truncation error arises from replacing an infinite or exact mathematical process with a finite approximation. The classic example is the Maclaurin series for $e^x$, $$e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots,$$ which has infinitely many terms; keeping only the first three gives $e^x \approx 1 + x + x^2/2!$, and the truncation error is the sum of the terms dropped, $\dfrac{x^3}{3!} + \dfrac{x^4}{4!} + \cdots$. Reducing truncation error (using more terms, a smaller step size) generally increases the number of arithmetic operations and so increases accumulated round-off error, which is why numerical methods must balance the two rather than minimize either alone.
When a calculation combines quantities that each carry their own uncertainty, the error propagates into the result. If $X = 1.50 \pm 0.05$ and $Y = 3.40 \pm 0.04$, the extreme values are $X \in [1.45, 1.55]$ and $Y \in [3.36, 3.44]$, so their sum satisfies $$1.45 + 3.36 \le X + Y \le 1.55 + 3.44 \quad\Rightarrow\quad 4.81 \le X + Y \le 4.99.$$ The bound width, $0.18$, is the sum of the two individual error widths ($0.10 + 0.08$), which is the general rule for addition: absolute errors add. For a general function $f(x_1, x_2, \ldots, x_n)$ of several uncertain inputs, first-order propagation gives $$\Delta f \approx \left|\frac{\partial f}{\partial x_1}\right|\Delta x_1 + \left|\frac{\partial f}{\partial x_2}\right|\Delta x_2 + \cdots + \left|\frac{\partial f}{\partial x_n}\right|\Delta x_n,$$ obtained by taking the total differential of $f$ and bounding each term by its absolute value.
Taylor's theorem expresses the value of a function at $x+h$ in terms of the function and its derivatives at $x$: $$f(x+h) = f(x) + f'(x)h + \frac{f''(x)}{2!}h^2 + \frac{f'''(x)}{3!}h^3 + \cdots,$$ provided all the derivatives exist and are continuous on the interval concerned. Setting $x = 0$ gives the special case known as the Maclaurin series, $$f(h) = f(0) + f'(0)h + \frac{f''(0)}{2!}h^2 + \frac{f'''(0)}{3!}h^3 + \cdots.$$ Worked example. Estimate $e^{0.25}$ using the first five terms of the Maclaurin series for $e^x$, all of whose derivatives equal $e^x$, so every derivative at $0$ equals $1$: $$e^{0.25} \approx 1 + 0.25 + \frac{0.25^2}{2!} + \frac{0.25^3}{3!} + \frac{0.25^4}{4!} = 1 + 0.25 + 0.03125 + 0.002604 + 0.000163 = 1.28402.$$ The true value to five significant figures is $1.28403$, so four terms of the series already reproduce it almost exactly, illustrating how quickly a Taylor expansion converges for small $h$.
A closely related result, the Mean Value Theorem, states that if $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$, there exists at least one point $c \in (a,b)$ such that $$f'(c) = \frac{f(b) - f(a)}{b-a},$$ that is, some point where the tangent is parallel to the secant joining the endpoints. It underlies the error and convergence analysis of every iterative method in this chapter.
An equation $f(x) = 0$ is non-linear if it is not of the form $ax+b=0$; this includes polynomial equations of degree two or higher and transcendental equations involving trigonometric, exponential or logarithmic terms (for example $2\sin x - x = 0$). Where no formula exists, the root must be located numerically. The crudest approach is the trial and error method: guess a value of $x$, evaluate $f(x)$, and if it is not sufficiently close to zero, refine the guess and repeat. It requires no theory beyond evaluating $f$, but converges unpredictably and gives no guarantee of finding a root at all. This motivates systematic iterative methods that use the shape of $f$ to choose each new guess: the bisection, Newton-Raphson, secant and fixed-point methods developed below.
The bisection method (also called the half-interval method) starts from two points $a$ and $b$ that bracket a root, meaning $f(a)$ and $f(b)$ have opposite signs, so the Intermediate Value Theorem guarantees a root somewhere in $(a,b)$. At each step the midpoint $x_m = (a+b)/2$ is tested: if $f(a)\cdot f(x_m) < 0$ the root lies in $(a, x_m)$ and $b$ is replaced by $x_m$; otherwise it lies in $(x_m, b)$ and $a$ is replaced by $x_m$. The interval width is halved every iteration, so the method always converges, though slowly.
Worked example. Solve $f(x) = x^2 - 4\cos x = 0$ on $[1, 2]$, stopping when the relative change in $x_m$ is below $0.01$:
| n | $a$ | $b$ | $x_m$ | $f(a)$ | $f(b)$ | $f(x_m)$ | error |
|---|---|---|---|---|---|---|---|
| 1 | 1.0000 | 2.0000 | 1.5000 | -1.1612 | 5.6646 | 1.9671 | - |
| 2 | 1.0000 | 1.5000 | 1.2500 | -1.1612 | 1.9671 | 0.3012 | 0.2000 |
| 3 | 1.0000 | 1.2500 | 1.1250 | -1.1612 | 0.3012 | -0.4591 | 0.1111 |
| 4 | 1.1250 | 1.2500 | 1.1875 | -0.4591 | 0.3012 | -0.0858 | 0.0526 |
| 5 | 1.1875 | 1.2500 | 1.2188 | -0.0858 | 0.3012 | 0.1061 | 0.0256 |
| 6 | 1.1875 | 1.2188 | 1.2031 | -0.0858 | 0.1061 | 0.0097 | 0.0130 |
| 7 | 1.1875 | 1.2031 | 1.1953 | -0.0858 | 0.0097 | -0.0381 | 0.0065 |
| 8 | 1.1953 | 1.2031 | 1.1992 | -0.0381 | 0.0097 | -0.0142 | 0.0033 |
(error $= |x_m^{(n)} - x_m^{(n-1)}|/x_m^{(n)}$; the interval containing the root at each step is the one whose endpoints give opposite-sign $f$ values). After 8 iterations $x_m = 1.1992$ to four decimal places, with error already below $1%$.
Convergence. After $n$ iterations, the bracket width shrinks from $b-a$ to $(b-a)/2^n$, so the maximum possible error is $E_n = (b-a)/2^n$. Consequently $E_{n+1} = E_n/2$: the error is exactly halved every iteration, which is called linear convergence. Bisection is always convergent because it never leaves the bracket, but it is slow: to gain one more decimal digit of accuracy requires roughly $3.3$ further iterations regardless of how close the current estimate already is.
Bisection algorithm
1. Choose a, b with f(a)*f(b) < 0, and a tolerance e.
2. Repeat:
xm = (a + b) / 2
if f(a) * f(xm) < 0 then b = xm
else a = xm
until |(xm_new - xm_old) / xm_new| < e
3. Report xm as the root.
The Newton-Raphson method uses the tangent line to $f$ at the current estimate $x_n$ to produce the next estimate: the tangent crosses the x-axis at $$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}.$$ This also follows from truncating the Taylor expansion $f(x_n + h) = f(x_n) + f'(x_n)h$ after the linear term and solving $f(x_n) + f'(x_n)h = 0$ for the step $h = x_{n+1}-x_n$.
Worked example. Solve $x^2 + 4x - 9 = 0$ from $x_0 = 4$:
| n | $x_n$ | $f(x_n)$ | $f'(x_n)$ | $x_{n+1}$ | error |
|---|---|---|---|---|---|
| 1 | 4.0000 | 23.0000 | 12.0000 | 2.0833 | 0.9200 |
| 2 | 2.0833 | 3.6736 | 8.1667 | 1.6335 | 0.2754 |
| 3 | 1.6335 | 0.2023 | 7.2670 | 1.6057 | 0.0173 |
| 4 | 1.6057 | 0.0008 | 7.2113 | 1.6056 | 0.0001 |
The root is $x = 1.6056$ (the positive root of $x^2+4x-9=0$, exactly $-2+\sqrt{13}$). Four iterations from a guess as far off as $x_0=4$ already give four correct decimals, in contrast to the eight bisection iterations above.
#include <stdio.h>
#include <math.h>
double f(double x) {
return x * x + 4 * x - 9;
}
double fprime(double x) {
return 2 * x + 4;
}
int main(void) {
double x0 = 4.0, x1, tol = 0.0001;
int iter = 0, maxIter = 50;
do {
x1 = x0 - f(x0) / fprime(x0);
iter++;
x0 = x1;
} while (fabs(f(x1)) > tol && iter < maxIter);
printf("Root = %.4f found in %d iterations\n", x1, iter);
return 0;
}
Convergence and drawbacks. Writing $e_n = x_r - x_n$ for the error at step $n$ and expanding $f$ by Taylor's theorem about $x_n$ around the true root $x_r$ gives, after simplification, $$e_{n+1} = -\frac{f''(\xi)}{2f'(x_n)},e_n^2$$ for some $\xi$ between $x_n$ and $x_r$: the new error is proportional to the square of the old error, so Newton-Raphson has quadratic convergence, the fastest of the methods in this chapter, provided $f'(x_n) \ne 0$ near the root. It fails or behaves badly when the derivative is zero or very small at an iterate (division by zero or a wildly overshooting step), and it can oscillate indefinitely between two points if the initial guess lands near a local turning point of $f$.
The secant method approximates $f'(x_n)$ by a finite difference through the two most recent iterates instead of an exact derivative, so it needs two starting values $x_0, x_1$ but no bracketing and no derivative formula: $$x_{n+1} = x_n - \frac{f(x_n)(x_n - x_{n-1})}{f(x_n) - f(x_{n-1})}.$$
Worked example. Solve $f(x) = x^3 - x - 2 = 0$ from $x_0 = 1$, $x_1 = 2$:
| n | $x_{n-1}$ | $x_n$ | $f(x_{n-1})$ | $f(x_n)$ | $x_{n+1}$ | error |
|---|---|---|---|---|---|---|
| 1 | 1.00000 | 2.00000 | -2.00000 | 4.00000 | 1.33333 | 0.50000 |
| 2 | 2.00000 | 1.33333 | 4.00000 | -0.96296 | 1.46269 | 0.08844 |
| 3 | 1.33333 | 1.46269 | -0.96296 | -0.33334 | 1.53117 | 0.04473 |
| 4 | 1.46269 | 1.53117 | -0.33334 | 0.05863 | 1.52093 | 0.00673 |
| 5 | 1.53117 | 1.52093 | 0.05863 | -0.00269 | 1.52138 | 0.00030 |
The root is $x = 1.52138$. Note the estimate is not monotone (it overshoots past the root at $n=1$ and corrects afterwards), unlike bisection which always tightens a bracket.
Convergence. A similar error analysis (using the Mean Value Theorem on the numerator and denominator) shows that the secant error obeys $e_{n+1} \approx C, e_n, e_{n-1}$ for a constant $C$ depending on $f''$ and $f'$. Assuming an order of convergence $p$ so that $e_{n+1} \propto e_n^{,p}$ leads to the equation $p^2 - p - 1 = 0$, whose positive root is $$p = \frac{1+\sqrt{5}}{2} \approx 1.618.$$ The secant method therefore converges faster than bisection (linear, $p=1$) but slower than Newton-Raphson (quadratic, $p=2$); this intermediate rate is called superlinear convergence. Its main practical advantage over Newton-Raphson is that it needs no derivative, at the cost of needing two starting points and a slightly slower rate.
The fixed-point iteration method rewrites $f(x) = 0$ algebraically as $x = g(x)$; any solution of the rewritten equation is also a root of the original equation, since the two are equivalent. Starting from a guess $x_0$, successive estimates are generated by $$x_{n+1} = g(x_n).$$ Geometrically, the root is the point where the curve $y = g(x)$ crosses the line $y = x$.
Worked example. Solve $x^2 - 6x + 8 = 0$ (roots $2$ and $4$). Adding $x$ to both sides gives the fixed-point form $x = x^2 - 5x + 8$, so $g(x) = x^2-5x+8$. From $x_0 = 1$, with tolerance $0.01$:
| n | $x_n$ | $x_{n+1}=g(x_n)$ | error |
|---|---|---|---|
| 1 | 1.0000 | 4.0000 | 0.7500 |
| 2 | 4.0000 | 4.0000 | 0.0000 |
The iteration lands exactly on the root $x=4$ after a single non-trivial step and confirms itself as a fixed point immediately after ($g(4) = 16-20+8=4$).
Convergence. Subtracting $x_f = g(x_f)$ from $x_{n+1} = g(x_n)$ and applying the Mean Value Theorem gives $x_f - x_{n+1} = g'(\xi)(x_f - x_n)$ for some $\xi$ between $x_n$ and $x_f$, so the error obeys $e_{n+1} = g'(\xi),e_n$. The iteration therefore converges, linearly, only when $|g'(x)| < 1$ near the root; if $|g'(x)| \ge 1$ the iterates move away from the root regardless of how close the initial guess is. This is why the algebraic rearrangement chosen for $g(x)$ matters: not every rearrangement of the same equation converges.
A polynomial of degree $n$ has $n$ roots (real or complex). Newton-Raphson finds one root at a time; after each root $x_r$ is found, the polynomial is deflated by dividing it by $(x - x_r)$ using synthetic division, giving a polynomial of degree $n-1$ whose remaining roots are exactly the remaining roots of the original polynomial. Repeating Newton-Raphson on the deflated polynomial, and deflating again, reduces the problem one degree at a time until a linear equation $ax+b=0$ remains, whose root is simply $-b/a$.
Worked example. Find all roots of $p(x) = x^4 - 2x^3 - 13x^2 + 38x - 24$.
Starting Newton-Raphson from $x_0 = 0.5$ on $p(x)$ itself:
| n | $x_n$ | $p(x_n)$ | $p'(x_n)$ | $x_{n+1}$ | error |
|---|---|---|---|---|---|
| 1 | 0.50000 | -8.43750 | 24.00000 | 0.85156 | 0.41284 |
| 2 | 0.85156 | -1.77687 | 13.97849 | 0.97868 | 0.12988 |
| 3 | 0.97868 | -0.21916 | 10.55709 | 0.99944 | 0.02077 |
| 4 | 0.99944 | -0.00564 | 10.01465 | 1.00000 | 0.00056 |
so $x_r = 1$ is a root. Deflating $p(x)$ by $(x-1)$ gives $q_1(x) = x^3 - x^2 - 14x + 24$. Repeating Newton-Raphson on $q_1$ from $x_0 = 1$ converges in the same way to $x_r = 2$; deflating $q_1$ by $(x-2)$ gives $q_2(x) = x^2 + x - 12$. Newton-Raphson on $q_2$ from $x_0 = 2.5$ converges to $x_r = 3$ in four iterations; deflating by $(x-3)$ leaves the linear factor $x + 4$, whose root is $-4$. The four roots of $p(x)$ are therefore $1, 2, 3, -4$, which can be checked directly: $(x-1)(x-2)(x-3)(x+4) = x^4 - 2x^3 - 13x^2 + 38x - 24$.
Horner's method (also the basis of synthetic division) evaluates a polynomial $p(x) = a_nx^n + a_{n-1}x^{n-1} + \cdots + a_1x + a_0$ using only $n$ multiplications and $n$ additions, by nesting it as $$p(x) = a_0 + x\big(a_1 + x\big(a_2 + x(\cdots + x(a_{n-1}+xa_n)\cdots)\big)\big).$$ Working from the highest coefficient down, a sequence $b_n = a_n$, $b_{k-1} = a_{k-1} + b_k,x$ is computed; the final value $b_0$ equals $p(x)$, and by the Remainder Theorem it also equals the remainder of dividing $p(x)$ by $(x-c)$ when evaluating at $x=c$. The intermediate $b$ values, read in order, are exactly the coefficients of the deflated (quotient) polynomial used in the previous section.
Worked example. Evaluate $p(x) = 3x^3 - 4x^2 + 5x - 6$ at $x = 2$: $$ \begin{aligned} b_3 &= 3 \ b_2 &= -4 + 3(2) = 2 \ b_1 &= 5 + 2(2) = 9 \ b_0 &= -6 + 9(2) = 12. \end{aligned} $$ So $p(2) = 12$, obtained with only 3 multiplications instead of the 6 that direct substitution of powers would need.
#include <stdio.h>
double hornerEval(double coeff[], int n, double x) {
double result = coeff[0];
for (int i = 1; i <= n; i++) {
result = result * x + coeff[i];
}
return result;
}
int main(void) {
double coeff[] = {3, -4, 5, -6};
int degree = 3;
double x = 2.0;
printf("p(%.1f) = %.4f\n", x, hornerEval(coeff, degree, x));
return 0;
}
The table below summarises the four iterative root-finding methods developed in this chapter.
| Method | Needs derivative? | Bracketing required? | Order of convergence | Cost per iteration |
|---|---|---|---|---|
| Bisection | No | Yes | 1 (linear) | 1 function evaluation |
| Fixed-point | No | No | 1 (linear, needs $\lvert g'\rvert<1$) | 1 function evaluation |
| Secant | No | No | $\approx 1.618$ (superlinear) | 1 function evaluation |
| Newton-Raphson | Yes | No | 2 (quadratic) | 1 function + 1 derivative evaluation |
Numerical Method for TU BSc CSIT is covered here in full, from syllabus notes to solved past questions. This subject has 6 chapters mapped to the official syllabus, and 72 past exam questions with written model answers. The opening of every note and answer is free, and the most-searched questions are free in full. A free account gets 2 free weeks of the whole program plus flashcards and progress tracking so weak topics come back before the exam.
This TU BSc CSIT Numerical Method guide covers Solution of Nonlinear Equations, Interpolation and Regression, Numerical Differentiation and Integration, Solving System of Linear Equations, Solution of Ordinary Differential Equations, Solution of Partial Differential Equations, across 6 chapters. It includes model answers to 72 past exam questions, plus flashcards for quick revision.
Numerical Method has 6 chapters mapped to the official syllabus.
Yes. Each of the 72 past questions comes with a written model answer; the most-searched ones are free in full, the rest open with a free account's 2 free weeks or a pass.
Free to start. The opening of every note and answer is free, the most-searched questions are free in full, and a free account gets 2 free weeks of the whole program plus flashcards and progress tracking. After that a program pass keeps everything open.
Based on the official syllabus.
Numerical methods replace exact analytical solutions with systematic arithmetic procedures that converge on an answer to a controlled accuracy. This chapter builds the error vocabulary needed to judge that accuracy, then develops the classical iterative methods used to solve a single nonlinear equation when no closed-form formula exists.
Every computed result differs from the true value by some amount, and this difference is called error. The true error is the true (exact) value minus the approximate value, Since the true value is rarely known in a numerical calculation, the approximate error is used instead: the difference between the current and the previous approximation, Both errors are more meaningfully expressed relative to the value they are measured against. The true relative error is and the approximate relative error is ; multiplying either by 100 gives a percentage error. In iterative methods, is the practical stopping test: iteration continues until falls below a preset tolerance.
Worked example. For at , the derivative can be approximated by the forward difference . With , The exact derivative is , so . The true error is and the true relative error is , or . Repeating with gives ; the approximate error is , so . Halving roughly halved the error, as expected of a first-order forward-difference approximation.
Two error sources dominate numerical computation. Round-off error arises because a computer stores only a finite number of digits, so numbers such as must be truncated to a fixed word length; the stored value and the exact value then differ by a small residual at every arithmetic step, and this residual can accumulate over many operations. Truncation error arises from replacing an infinite or exact mathematical process with a finite approximation. The classic example is the Maclaurin series for , which has infinitely many terms; keeping only the first three gives , and the truncation error is the sum of the terms dropped, . Reducing truncation error (using more terms, a smaller step size) generally increases the number of arithmetic operations and so increases accumulated round-off error, which is why numerical methods must balance the two rather than minimize either alone.
When a calculation combines quantities that each carry their own uncertainty, the error propagates into the result. If and , the extreme values are and , so their sum satisfies The bound width, , is the sum of the two individual error widths (), which is the general rule for addition: absolute errors add. For a general function of several uncertain inputs, first-order propagation gives obtained by taking the total differential of and bounding each term by its absolute value.
Taylor's theorem expresses the value of a function at in terms of the function and its derivatives at : provided all the derivatives exist and are continuous on the interval concerned. Setting gives the special case known as the Maclaurin series, Worked example. Estimate using the first five terms of the Maclaurin series for , all of whose derivatives equal , so every derivative at equals : The true value to five significant figures is , so four terms of the series already reproduce it almost exactly, illustrating how quickly a Taylor expansion converges for small .
A closely related result, the Mean Value Theorem, states that if is continuous on and differentiable on , there exists at least one point such that that is, some point where the tangent is parallel to the secant joining the endpoints. It underlies the error and convergence analysis of every iterative method in this chapter.
An equation is non-linear if it is not of the form ; this includes polynomial equations of degree two or higher and transcendental equations involving trigonometric, exponential or logarithmic terms (for example ). Where no formula exists, the root must be located numerically. The crudest approach is the trial and error method: guess a value of , evaluate , and if it is not sufficiently close to zero, refine the guess and repeat. It requires no theory beyond evaluating , but converges unpredictably and gives no guarantee of finding a root at all. This motivates systematic iterative methods that use the shape of to choose each new guess: the bisection, Newton-Raphson, secant and fixed-point methods developed below.
The bisection method (also called the half-interval method) starts from two points and that bracket a root, meaning and have opposite signs, so the Intermediate Value Theorem guarantees a root somewhere in . At each step the midpoint is tested: if the root lies in and is replaced by ; otherwise it lies in and is replaced by . The interval width is halved every iteration, so the method always converges, though slowly.
Worked example. Solve on , stopping when the relative change in is below :
| n | error | ||||||
|---|---|---|---|---|---|---|---|
| 1 | 1.0000 | 2.0000 | 1.5000 | -1.1612 | 5.6646 | 1.9671 | - |
| 2 | 1.0000 | 1.5000 | 1.2500 | -1.1612 | 1.9671 | 0.3012 | 0.2000 |
| 3 | 1.0000 | 1.2500 | 1.1250 | -1.1612 | 0.3012 | -0.4591 | 0.1111 |
| 4 | 1.1250 | 1.2500 | 1.1875 | -0.4591 | 0.3012 | -0.0858 | 0.0526 |
| 5 | 1.1875 | 1.2500 | 1.2188 | -0.0858 | 0.3012 | 0.1061 | 0.0256 |
| 6 | 1.1875 | 1.2188 | 1.2031 | -0.0858 | 0.1061 | 0.0097 | 0.0130 |
| 7 | 1.1875 | 1.2031 | 1.1953 | -0.0858 | 0.0097 | -0.0381 | 0.0065 |
| 8 | 1.1953 | 1.2031 | 1.1992 | -0.0381 | 0.0097 | -0.0142 | 0.0033 |
(error ; the interval containing the root at each step is the one whose endpoints give opposite-sign values). After 8 iterations to four decimal places, with error already below .
Convergence. After iterations, the bracket width shrinks from to , so the maximum possible error is . Consequently : the error is exactly halved every iteration, which is called linear convergence. Bisection is always convergent because it never leaves the bracket, but it is slow: to gain one more decimal digit of accuracy requires roughly further iterations regardless of how close the current estimate already is.
Bisection algorithm
1. Choose a, b with f(a)*f(b) < 0, and a tolerance e.
2. Repeat:
xm = (a + b) / 2
if f(a) * f(xm) < 0 then b = xm
else a = xm
until |(xm_new - xm_old) / xm_new| < e
3. Report xm as the root.
The Newton-Raphson method uses the tangent line to at the current estimate to produce the next estimate: the tangent crosses the x-axis at This also follows from truncating the Taylor expansion after the linear term and solving for the step .
Worked example. Solve from :
| n | error | ||||
|---|---|---|---|---|---|
| 1 | 4.0000 | 23.0000 | 12.0000 | 2.0833 | 0.9200 |
| 2 | 2.0833 | 3.6736 | 8.1667 | 1.6335 | 0.2754 |
| 3 | 1.6335 | 0.2023 | 7.2670 | 1.6057 | 0.0173 |
| 4 | 1.6057 | 0.0008 | 7.2113 | 1.6056 | 0.0001 |
The root is (the positive root of , exactly ). Four iterations from a guess as far off as already give four correct decimals, in contrast to the eight bisection iterations above.
#include <stdio.h>
#include <math.h>
double f(double x) {
return x * x + 4 * x - 9;
}
double fprime(double x) {
return 2 * x + 4;
}
int main(void) {
double x0 = 4.0, x1, tol = 0.0001;
int iter = 0, maxIter = 50;
do {
x1 = x0 - f(x0) / fprime(x0);
iter++;
x0 = x1;
} while (fabs(f(x1)) > tol && iter < maxIter);
printf("Root = %.4f found in %d iterations\n", x1, iter);
return 0;
}
Convergence and drawbacks. Writing for the error at step and expanding by Taylor's theorem about around the true root gives, after simplification, for some between and : the new error is proportional to the square of the old error, so Newton-Raphson has quadratic convergence, the fastest of the methods in this chapter, provided near the root. It fails or behaves badly when the derivative is zero or very small at an iterate (division by zero or a wildly overshooting step), and it can oscillate indefinitely between two points if the initial guess lands near a local turning point of .
The secant method approximates by a finite difference through the two most recent iterates instead of an exact derivative, so it needs two starting values but no bracketing and no derivative formula:
Worked example. Solve from , :
| n | error | |||||
|---|---|---|---|---|---|---|
| 1 | 1.00000 | 2.00000 | -2.00000 | 4.00000 | 1.33333 | 0.50000 |
| 2 | 2.00000 | 1.33333 | 4.00000 | -0.96296 | 1.46269 | 0.08844 |
| 3 | 1.33333 | 1.46269 | -0.96296 | -0.33334 | 1.53117 | 0.04473 |
| 4 | 1.46269 | 1.53117 | -0.33334 | 0.05863 | 1.52093 | 0.00673 |
| 5 | 1.53117 | 1.52093 | 0.05863 | -0.00269 | 1.52138 | 0.00030 |
The root is . Note the estimate is not monotone (it overshoots past the root at and corrects afterwards), unlike bisection which always tightens a bracket.
Convergence. A similar error analysis (using the Mean Value Theorem on the numerator and denominator) shows that the secant error obeys for a constant depending on and . Assuming an order of convergence so that leads to the equation , whose positive root is The secant method therefore converges faster than bisection (linear, ) but slower than Newton-Raphson (quadratic, ); this intermediate rate is called superlinear convergence. Its main practical advantage over Newton-Raphson is that it needs no derivative, at the cost of needing two starting points and a slightly slower rate.
The fixed-point iteration method rewrites algebraically as ; any solution of the rewritten equation is also a root of the original equation, since the two are equivalent. Starting from a guess , successive estimates are generated by Geometrically, the root is the point where the curve crosses the line .
Worked example. Solve (roots and ). Adding to both sides gives the fixed-point form , so . From , with tolerance :
| n | error | ||
|---|---|---|---|
| 1 | 1.0000 | 4.0000 | 0.7500 |
| 2 | 4.0000 | 4.0000 | 0.0000 |
The iteration lands exactly on the root after a single non-trivial step and confirms itself as a fixed point immediately after ().
Convergence. Subtracting from and applying the Mean Value Theorem gives for some between and , so the error obeys . The iteration therefore converges, linearly, only when near the root; if the iterates move away from the root regardless of how close the initial guess is. This is why the algebraic rearrangement chosen for matters: not every rearrangement of the same equation converges.
A polynomial of degree has roots (real or complex). Newton-Raphson finds one root at a time; after each root is found, the polynomial is deflated by dividing it by using synthetic division, giving a polynomial of degree whose remaining roots are exactly the remaining roots of the original polynomial. Repeating Newton-Raphson on the deflated polynomial, and deflating again, reduces the problem one degree at a time until a linear equation remains, whose root is simply .
Worked example. Find all roots of .
Starting Newton-Raphson from on itself:
| n | error | ||||
|---|---|---|---|---|---|
| 1 | 0.50000 | -8.43750 | 24.00000 | 0.85156 | 0.41284 |
| 2 | 0.85156 | -1.77687 | 13.97849 | 0.97868 | 0.12988 |
| 3 | 0.97868 | -0.21916 | 10.55709 | 0.99944 | 0.02077 |
| 4 | 0.99944 | -0.00564 | 10.01465 | 1.00000 | 0.00056 |
so is a root. Deflating by gives . Repeating Newton-Raphson on from converges in the same way to ; deflating by gives . Newton-Raphson on from converges to in four iterations; deflating by leaves the linear factor , whose root is . The four roots of are therefore , which can be checked directly: .
Horner's method (also the basis of synthetic division) evaluates a polynomial using only multiplications and additions, by nesting it as Working from the highest coefficient down, a sequence , is computed; the final value equals , and by the Remainder Theorem it also equals the remainder of dividing by when evaluating at . The intermediate values, read in order, are exactly the coefficients of the deflated (quotient) polynomial used in the previous section.
Worked example. Evaluate at :
So , obtained with only 3 multiplications instead of the 6 that direct substitution of powers would need.
#include <stdio.h>
double hornerEval(double coeff[], int n, double x) {
double result = coeff[0];
for (int i = 1; i <= n; i++) {
result = result * x + coeff[i];
}
return result;
}
int main(void) {
double coeff[] = {3, -4, 5, -6};
int degree = 3;
double x = 2.0;
printf("p(%.1f) = %.4f\n", x, hornerEval(coeff, degree, x));
return 0;
}
The table below summarises the four iterative root-finding methods developed in this chapter.
| Method | Needs derivative? | Bracketing required? | Order of convergence | Cost per iteration |
|---|---|---|---|---|
| Bisection | No | Yes | 1 (linear) | 1 function evaluation |
| Fixed-point | No | No | 1 (linear, needs ) | 1 function evaluation |
| Secant | No | No | (superlinear) | 1 function evaluation |
| Newton-Raphson | Yes | No | 2 (quadratic) | 1 function + 1 derivative evaluation |