Solving nonlinear equations · Lecture 10

Secant Method and Nonlinear Systems

Newton without derivatives, a final comparison of all five root-finding methods, and Newton's method for several equations at once: the idea behind GPS.

Md Mahbub E Noor · Assistant Professor
CSE-3107 Numerical Methods · B.Sc. 3rd Year 1st Semester
Department of CSE, University of Barishal

Why this lecture

The problem: a function with no formula

The game designer from Lecture 6 asks: at what launch speed vv does the ball land after exactly 3 seconds?

  • Define T(v)T(v) = landing time for launch speed vv. We need T(v)−3=0T(v) - 3 = 0
  • But T(v)T(v) has no formula: every evaluation is a whole bisection run (Lecture 6)
  • So there is no derivative T′(v)T'(v) for Newton, and each evaluation is expensive
  • We need a fast method that uses only values of the function
vv (m/s)T(v)T(v) (s)
102.7752
153.3912
204.0025
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
2 / 22

Today's goals

  • Derive the secant method from Newton's method and from the chord
  • Carry out the secant method by hand and compare it with false position
  • Compare all five methods: order, cost, safety; choose one for a given problem
  • Apply Newton's method to systems using the Jacobian matrix
  • Choose the right root-finding method for a problem: best and worst cases of all five
Last time

Newton: xn+1=xn−f(xn)/f′(xn)x_{n+1} = x_n - f(x_n)/f'(x_n), quadratic, but needs f′f' and a good start.


Today

Replace f′f' by a slope through two points (secant), then generalise Newton to vectors.

Solving nonlinear equations · you are hereBuilds on: L7, L9
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
3 / 22
Start here

The idea in one picture

xf(x)12x₀x₁x₂oldest point: droppedx₃x₄ = 1.531
Like Newton, but we do not know the slope (derivative).Take two starting points on the curve.Draw the straight line through them.Where it crosses the axis is the next point x₂.Forget the oldest point; keep the two newest.Line through the two newest points …… gives x₃.Drop the oldest again.The line through x₂ and x₃ is almost the tangent.x₄ = 1.531 (root 1.521): nearly as fast as Newton, with no derivative.
In plain words
  • Newton needs the derivative, which we often do not have
  • Replace the tangent by the line through the two latest points
  • Almost as fast, and only function values are needed
New words today
secant
a line through two points of a curve
open method
no bracket: fast, but not guaranteed
superlinear
faster than linear, slower than quadratic
Jacobian
the table of slopes used for systems of equations
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
4 / 22

The secant method

Replace the derivative by a slope through the last two pointsf′(xn)≈f(xn)−f(xn−1)xn−xn−1f'(x_n) \approx \frac{f(x_n) - f(x_{n-1})}{x_n - x_{n-1}}
Secant iterationxn+1=xn−f(xn) xn−xn−1f(xn)−f(xn−1)x_{n+1} = x_n - f(x_n)\,\frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}
  • Same formula as false position, but no bracket: always use the two most recent points
  • Needs two starting values x0x_0, x1x_1 (they need not bracket the root)
  • One new function evaluation per step (Newton needs ff and f′f')
  • Order ϕ=1+52≈1.618\phi = \frac{1 + \sqrt5}{2} \approx 1.618: superlinear
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
5 / 22
The method, step by step

The secant algorithm

  1. Choose two starting values x0x_0, x1x_1 near the root (they need not bracket it)
  2. Compute xn+1=xn−f(xn) xn−xn−1f(xn)−f(xn−1)x_{n+1} = x_n - f(x_n)\,\dfrac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}
  3. If f(xn)=f(xn−1)f(x_n) = f(x_{n-1}) (flat secant), stop
  4. Drop the oldest point: the pair (xn−1,xn)(x_{n-1}, x_n) becomes (xn,xn+1)(x_n, x_{n+1})
  5. Repeat until ∣xn+1−xn∣<ε|x_{n+1} - x_n| < \varepsilon; the answer is the last xx

Step 4 is the only difference from false position: no sign test, just keep the newest two points.

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
6 / 22

Explore: secant lines

  • The dashed line passes through the last two points
  • Its crossing is the next point; the oldest point is dropped
  • The first two steps equal false position; from step 3 the secant pulls ahead
  • Try x0=0x_0 = 0, x1=0.5x_1 = 0.5: both on the same side of the root
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
7 / 22

Problem 1: x3−x−2=0x^3 - x - 2 = 0, x0=1x_0 = 1, x1=2x_1 = 2

nnxn−1x_{n-1}xnx_nf(xn−1)f(x_{n-1})f(xn)f(x_n)xn+1x_{n+1}f(xn+1)f(x_{n+1})
112−241.333333−0.962963
221.3333334−0.9629631.462687−0.333339
31.3333331.462687−0.962963−0.3333391.531169+0.058626
41.4626871.531169−0.333339+0.0586261.520926−0.002693
51.5311691.520926+0.058626−0.0026931.521376−0.000020
61.5209261.521376−0.002693−0.0000201.5213800.000000

Row 3 uses two points with f<0f < 0: false position would never do that. Root 1.521380 after 6 steps (false position: 12 steps for the same accuracy).

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
8 / 22

How fast is "superlinear"?

  • Secant on ex−3xe^{x} - 3x from 0,10, 1: errors 1.6×10−11.6\times10^{-1}, 1.2×10−11.2\times10^{-1}, 1.7×10−21.7\times10^{-2}, 1.5×10−31.5\times10^{-3}, 2.1×10−52.1\times10^{-5}, 2.6×10−82.6\times10^{-8}, 4.4×10−134.4\times10^{-13}
  • Each error ≈ (previous)1.6: between linear (×constant) and quadratic (squared)
  • Efficiency per function evaluation: Newton gains order 2 per 2 evaluations (2=1.41\sqrt2 = 1.41 per evaluation); secant gains 1.618 per evaluation
  • So when f′f' costs as much as ff, secant is often faster than Newton in practice
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
9 / 22

Systems: Newton's method in two variables

Solve f1(x,y)=0f_1(x, y) = 0, f2(x,y)=0f_2(x, y) = 0 simultaneously. Linearise both with Taylor series:

Jacobian matrixJ=(∂f1/∂x∂f1/∂y∂f2/∂x∂f2/∂y)J = \begin{pmatrix} \partial f_1/\partial x & \partial f_1/\partial y \\ \partial f_2/\partial x & \partial f_2/\partial y \end{pmatrix}
Newton stepJ(xn) Δ=−F(xn),xn+1=xn+ΔJ(\mathbf{x}_n)\,\Delta = -\mathbf{F}(\mathbf{x}_n), \qquad \mathbf{x}_{n+1} = \mathbf{x}_n + \Delta
  • One-variable Newton: divide by f′f'. Many variables: solve a linear system with JJ
  • For 2×2, solve JΔ=−FJ\Delta = -F with the school formula (Cramer's rule); larger systems: Lectures 11–14
  • Still quadratic near a solution where det⁡J≠0\det J \ne 0
  • For nn unknowns, each step costs an n×nn\times n solve (Lectures 11–14)
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
10 / 22
The method, step by step

Newton for systems, step by step

  1. Write F=(f1,f2)\mathbf{F} = (f_1, f_2) and the Jacobian JJ (four partial derivatives)
  2. Choose a starting guess (x0,y0)(x_0, y_0)
  3. Evaluate F\mathbf{F} and JJ at the current point
  4. Solve the linear system J Δ=−FJ\,\Delta = -\mathbf{F} (2×2: Cramer's rule)
  5. Update xn+1=xn+Δ\mathbf{x}_{n+1} = \mathbf{x}_n + \Delta
  6. Repeat until ∥Δ∥<ε\|\Delta\| < \varepsilon; the answer is the last x\mathbf{x}

Same loop as one-variable Newton; "divide by f′f'" became "solve with JJ" (step 4).

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
11 / 22

Problem 2: one Newton step for x2+y2=4x^2 + y^2 = 4, xy=1xy = 1

Start from (x0,y0)=(2,0.5)(x_0, y_0) = (2, 0.5). Do one Newton step.
1
F=(x2+y2−4xy−1)=(0.250)F = \begin{pmatrix} x^2 + y^2 - 4 \\ xy - 1 \end{pmatrix} = \begin{pmatrix} 0.25 \\ 0 \end{pmatrix}, J=(2x2yyx)=(410.52)\quad J = \begin{pmatrix} 2x & 2y \\ y & x \end{pmatrix} = \begin{pmatrix} 4 & 1 \\ 0.5 & 2 \end{pmatrix}
2
Solve (410.52)(ΔxΔy)=(−0.250)\begin{pmatrix} 4 & 1 \\ 0.5 & 2 \end{pmatrix}\begin{pmatrix} \Delta x \\ \Delta y\end{pmatrix} = \begin{pmatrix} -0.25 \\ 0 \end{pmatrix}; det⁡J=8−0.5=7.5\det J = 8 - 0.5 = 7.5
3
Cramer: Δx=(−0.25)(2)−(1)(0)7.5=−0.066667\Delta x = \dfrac{(-0.25)(2) - (1)(0)}{7.5} = -0.066667,   Δy=(4)(0)−(0.5)(−0.25)7.5=0.016667\;\Delta y = \dfrac{(4)(0) - (0.5)(-0.25)}{7.5} = 0.016667
4
(x1,y1)=(1.933333,0.516667)(x_1, y_1) = (1.933333, 0.516667); two more steps give (2+3,2−3)\left(\sqrt{2+\sqrt3}, \sqrt{2-\sqrt3}\right)
Solution (1.931852,0.517638)(1.931852, 0.517638) in three steps: quadratic convergence again.
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
12 / 22
Classical vs numerical

Same system, two approaches: x2+y2=4x^2 + y^2 = 4, xy=1xy = 1

Algebra

Classical (exact formula)

  • Substitute y=1/xy = 1/x: x2+1/x2=4⇒x4−4x2+1=0x^2 + 1/x^2 = 4 \Rightarrow x^4 - 4x^2 + 1 = 0
  • Quadratic in x2x^2: x2=2±3x^2 = 2 \pm \sqrt3
  • (x,y)=(2+3,2−3)=(1.931852,0.517638)(x, y) = \left(\sqrt{2+\sqrt3}, \sqrt{2-\sqrt3}\right) = (1.931852, 0.517638)
vs
Algorithm

Numerical (Newton for systems)

  • Jacobian (2x2yyx)\begin{pmatrix} 2x & 2y \\ y & x\end{pmatrix}, start (2,0.5)(2, 0.5)
  • 3 iterations: (1.931852,0.517638)(1.931852, 0.517638)
  • No substitution trick needed: the same code works for any 2×2 system
When the classical approach cannot work

Landing time T(v)=3T(v) = 3: a function with no formula

Each value of T(v)T(v) comes from running bisection; there is nothing to substitute or rearrange. Secant: v=11.8267v = 11.8267 m/s in 4 steps. Most real systems (circuits, GPS, robots) are like this: many equations, no substitution trick.

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
13 / 22

Newton for systems in Python and C

  • Each step: evaluate FF and JJ, solve the 2×2 system by Cramer's rule
  • Stop when the step ∥Δ∥\|\Delta\| is tiny
  • Try the start (0.5,2)(0.5, 2): a different solution
  • Change to x2+y=11x^2 + y = 11, x+y2=7x + y^2 = 7 from (3.5,1.5)(3.5, 1.5): converges to (3,2)(3, 2)
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
14 / 22
Practice

Practice problem

Problem 3"Explain how the Secant method removes the requirement of an analytical derivative and identify one drawback it introduces in exchange." Also: compare the iteration methods for solving f(x)=0f(x) = 0.
How to write a complete answer
  • Secant replaces f′(xn)f'(x_n) by the finite-difference slope f(xn)−f(xn−1)xn−xn−1\dfrac{f(x_n) - f(x_{n-1})}{x_n - x_{n-1}} through the last two iterates
  • Drawbacks (any one): needs two starting values; order drops from 2 to 1.618; no bracket, so it can diverge; f(xn)≈f(xn−1)f(x_n) \approx f(x_{n-1}) causes division by a tiny number
  • Comparison: use the five-row table (needs, order, cost, guarantee)
  • Mention the efficiency index: per function evaluation, secant (1.618) beats Newton (1.414)
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
15 / 22

When the secant method fails

  • Divergence: tan⁡−1x\tan^{-1}x from 2, 3 jumps to −5.80, −1.15, 6.15, … 38.6
  • Flat secant: cos⁡(−1)=cos⁡(1)\cos(-1) = \cos(1), the line is horizontal: division by zero
  • Wandering: x3−2x+2x^3 - 2x + 2 from 0, 0.5 jumps around for many steps before settling
  • No bracket means no guarantee: same weakness as Newton
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
16 / 22
When to use it

Secant method: method profile

Best case
  • Smooth ff, two good starting values: superlinear, order 1.618; x3−x−2x^3 - x - 2 in 7 steps
  • Expensive ff with no derivative: one evaluation per step, the most efficient per evaluation
  • The ball problem: 4 steps, each a full simulation
Worst case
  • f(xn)≈f(xn−1)f(x_n) \approx f(x_{n-1}): a nearly flat secant throws the next point far away
  • Poor starting values: divergence (tan⁡−1x\tan^{-1}x from 2, 3)
  • Cancellation in f(xn)−f(xn−1)f(x_n) - f(x_{n-1}) near convergence limits the final accuracy slightly
Best suited for
  • Black-box functions: simulations, measurements, outputs of other solvers
  • Inside hybrid solvers (Brent's method, scipy.optimize.brentq)
  • When f′f' costs as much as ff
Avoid when
  • A guaranteed result is needed (bracket it, or use Brent)
  • The function is noisy (secant slopes amplify noise; use bisection)
  • A cheap derivative is available and starts are good (Newton is slightly faster per iteration)

Rule of thumb: no derivative → secant; no guarantee needed → plain; guarantee needed → Brent (bracket + secant + bisection).

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
17 / 22

All five methods side by side

MethodNeedsOrderPer stepGuaranteed?Iterations for x3−x−2x^3 - x - 2, 10−610^{-6}
Bisectionbracket1 (rate ½)1 evalyes20 from [1, 2]
False positionbracket1 (often fast)1 evalyes (can be slow)12 from [1, 2]
Fixed pointx=g(x)x = g(x), x0x_01 (rate ∣g′(r)∣|g'(r)|)1 evalonly if ∣g′∣<1|g'| < 17 with g=(x+2)1/3g = (x+2)^{1/3}
Newton–Raphsonf′f', x0x_022 evalsno (needs good x0x_0)3 from 1.5
Secantx0x_0, x1x_11.6181 evalno7 from 1, 2

Practical choice: bracketing when safety matters or ff is noisy; Newton when f′f' is cheap and x0x_0 is good; secant when f′f' is unavailable. Libraries (e.g. Brent's method, scipy.optimize.brentq) combine bisection's safety with secant-like speed.

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
18 / 22
Roadmap

End of Module 2: what is still missing

We can now solve any single equation, and small systems. Large systems need new tools:

What it does well (keep this)
  • Five root-finding methods with known best and worst cases
  • Hybrid strategy: bracket, then a fast method
  • Newton for systems: linearise, solve, repeat
  • Convergence orders 1, 1.618 and 2
LimitationHow it is overcomeWhere
Each Newton step for nn equations needs an n×nn\times n linear solve
→
Gaussian elimination, LU and Cholesky
Lecture 12 →
Cramer's rule is far too slow beyond 3×3
→
Cost analysis of Cramer and the inverse
Lecture 11 →
Huge sparse systems (millions of unknowns)
→
Iterative methods: Jacobi, Gauss–Seidel (fixed point with matrices)
Lecture 14 →
Finding the best parameters for data, not a root
→
Least squares, then optimisation for ML
Lecture 23 →
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
19 / 22
Applications

Where this method runs in the real world

Click a card to see Newton's method for systems, or the secant idea, inside a real system.

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
20 / 22

Checkpoint

Checkpoint · think, then discuss with your neighbourSecant method with x0=1x_0 = 1, x1=2x_1 = 2 for f(x)=x2−3f(x) = x^2 - 3. What is x2x_2?
A1.5
B1.6667
C1.7321
D1.75
B. f(1)=−2f(1) = -2, f(2)=1f(2) = 1: x2=2−1⋅2−11−(−2)=2−13=1.6667x_2 = 2 - 1\cdot\dfrac{2 - 1}{1 - (-2)} = 2 - \tfrac13 = 1.6667. Then x3=1.7273x_3 = 1.7273, x4=1.7321=3x_4 = 1.7321 = \sqrt3.
Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
21 / 22

Summary

Key points
  • Secant: xn+1=xn−f(xn)xn−xn−1f(xn)−f(xn−1)x_{n+1} = x_n - f(x_n)\dfrac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}; no derivative, order 1.618
  • Like false position but uses the latest two points: faster, not guaranteed
  • Choose: bracketing for safety; Newton when f′f' is cheap; secant otherwise; hybrids in libraries
  • Systems: solve JΔ=−FJ\Delta = -F each step; quadratic near a solution with det⁡J≠0\det J \ne 0
Opening problem: solved

Secant on T(v)−3T(v) - 3 from v=10,20v = 10, 20: 11.8317, 11.8267, 11.826709 m/s. Four steps, each a full bisection run inside; no derivative was needed.

Homework
  1. Solve x3−5x+1=0x^3 - 5x + 1 = 0 by the secant method with x0=0x_0 = 0, x1=1x_1 = 1, to 5 decimal places.
  2. Do two Newton steps for x2+y=11x^2 + y = 11, x+y2=7x + y^2 = 7 from (3.5,1.5)(3.5, 1.5) by hand.
  3. Modify the secant program to stop when ∣f(xn)∣<10−10|f(x_n)| < 10^{-10} and count evaluations. Compare with Newton.
  4. Write a one-page comparison of the five root-finding methods (use the table and your own examples).
Next lecture

Module 3: systems of linear equations. Ax=bA\mathbf{x} = \mathbf{b} with Cramer's rule and the inverse, and why both are too slow for real problems.

Md Mahbub E Noor
Lecture 10: Secant Method and Nonlinear Systems
University of Barishal
22 / 22