Foundations of numerical computing · Lecture 1

Why Numerical Methods?

When no formula exists, we compute the answer step by step: guess, improve, repeat, and stop when it is good enough.

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

Today's goals

  • Explain why many real problems have no exact formula and need numerical methods
  • Describe the modelling pipeline: problem → model → algorithm → program → answer
  • Distinguish an analytical (exact) solution from a numerical (approximate) one
  • Run an iteration by hand and in code, and choose a sensible stopping rule
  • Compare bracketing and open iteration methods and their limitations
Today

A numerical method replaces "find the exact formula" with "compute a number that is as close as we need". Today: why, and the basic loop behind almost every method in this course.

Lab PCs: open the course folder and index.html. Everything works offline.

Foundations of numerical computing · you are here
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
2 / 17
Start here

The idea in one picture

Guessx = 1Improvex ← ½(x + 2/x)Close enough?did x stop changing?no: go round againthe guesses:11.51.4166671.4142161.414214Answer: √2 ≈ 1.4142yes
Start with any reasonable guess for √2.Apply a rule that makes the guess better.Check: has the value stopped changing?Not yet, so go round the loop again.Each trip round the loop adds correct digits.Four trips: the digits have almost stopped moving.Two guesses in a row now agree to 5 decimals.Stop and report the answer. That loop is "iteration".
In plain words
  • A numerical method is a recipe of simple arithmetic steps, repeated
  • Each repeat (iteration) improves the answer a little
  • We stop when the answer is good enough for our purpose
New words today
algorithm
a finite list of steps a computer can follow
iteration
one trip round the loop
converge
the guesses settle towards one value
tolerance
how small a change we accept before stopping
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
3 / 17

Many problems have no formula to plug into

Each of these is easy to state and has an answer, yet no finite formula gives it exactly.

Equation

Solve x=cos⁡xx = \cos x

No algebra isolates xx. The answer is x≈0.739085x \approx 0.739085, found only by computing.

Polynomial

Solve x5−x−1=0x^5 - x - 1 = 0

Abel (1824): there is no general formula for polynomials of degree 5 or more.

Integral

∫01e−x2 dx\int_0^1 e^{-x^2}\,dx

e−x2e^{-x^2} has no elementary antiderivative, yet the area is a definite number ≈ 0.746824.

Differential equation

Pendulum θ′′=−gLsin⁡θ\theta'' = -\frac{g}{L}\sin\theta

No formula for θ(t)\theta(t) in elementary functions; games and simulators step it forward numerically.

Large system

Ax=bA\mathbf{x} = \mathbf{b} with 10610^6 unknowns

Cramer's rule would need about 106!10^{6}! operations. Elimination or iteration is the only way.

Data

Fit a line to 10,000 points

The data have noise; no line passes through all points. We compute the best line (least squares).

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
4 / 17

Analytical vs numerical solution

Analytical (exact)

  • A formula or symbolic expression
  • Exact: x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2-4ac}}{2a}
  • Works for every input of that form at once
  • Often impossible for real problems
  • Example: ∫01x2 dx=13\int_0^1 x^2\,dx = \tfrac{1}{3}
vs

Numerical (approximate)

  • An algorithm: a finite list of arithmetic steps
  • A number: x≈0.739085x \approx 0.739085
  • Must be re-run for each new input
  • Works on almost any problem a computer can evaluate
  • Comes with an error we must estimate and control

An algorithm, an error estimate and a stopping rule: those three things together make a numerical method.

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
5 / 17

The modelling pipeline

Numerical methods sit in the middle of every computational project. Errors can enter at every arrow.

Real problemHow hot will this CPU get?
→
Mathematical modelHeat equation, material constants
→
Numerical methodFinite differences, an iteration
→
ProgramPython, C, NumPy
→
Result + check87 °C ± 2 °C. Does it match a measurement?

Modelling error

The model ignores something real (air flow, friction).

Truncation error

The method stops early: finite steps instead of an infinite process. This course.

Round-off error

The computer keeps only about 16 digits. Lecture 2.

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
6 / 17

Where numerical methods run every day in CSE

Machine learning

Training = optimisation

Gradient descent takes thousands of small steps downhill on a loss function. That is Lecture 25.

Graphics and games

Ray tracing and physics

Where does a light ray hit a curved surface? A root-finding problem (Lecture 9). Game physics steps ODEs with Euler-type methods (Lecture 21).

Speech and signals

Filters and the FFT

Speech enhancement fits filters by least squares (Lecture 23); spectra come from numerical integration and the FFT.

Web search

PageRank

Google's original ranking solves a linear system with billions of unknowns by repeated iteration (Lecture 14).

Navigation

GPS position

Your phone solves a nonlinear system of 4 equations (distance to satellites) with Newton's method (Lecture 10).

Data science

Regression and interpolation

Trend lines, filling missing sensor values, smooth curves through points (Lectures 15–18 and 23–24).

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
7 / 17

The core idea: iteration

Start with a guess, apply a rule that improves it, repeat.

  • To find N\sqrt{N}: if xx is too big, then N/xN/x is too small, so average them
  • Rule: xk+1=12(xk+Nxk)x_{k+1} = \tfrac{1}{2}\left(x_k + \dfrac{N}{x_k}\right) (Babylonian / Heron's method, about 1800 BC)
  • Every step uses only ++, ÷\div and ×12\times\tfrac12: things a computer does well
  • Press Next step: the number of correct digits roughly doubles each time
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
8 / 17

By hand: 2\sqrt{2} starting from x0=1x_0 = 1

Problem 1Use xk+1=12(xk+2/xk)x_{k+1} = \tfrac{1}{2}(x_k + 2/x_k) with x0=1x_0 = 1. Stop when two successive values agree to 4 decimal places.
1
x1=12(1+21)=12(3)=1.5x_1 = \tfrac12\left(1 + \tfrac{2}{1}\right) = \tfrac12(3) = 1.5
2
x2=12(1.5+21.5)=12(1.5+1.333333)=1.416667x_2 = \tfrac12\left(1.5 + \tfrac{2}{1.5}\right) = \tfrac12(1.5 + 1.333333) = 1.416667
3
x3=12(1.416667+21.416667)=12(1.416667+1.411765)=1.414216x_3 = \tfrac12\left(1.416667 + \tfrac{2}{1.416667}\right) = \tfrac12(1.416667 + 1.411765) = 1.414216
4
x4=12(1.414216+21.414216)=1.414214x_4 = \tfrac12\left(1.414216 + \tfrac{2}{1.414216}\right) = 1.414214;   ∣x4−x3∣=0.000002<0.00005\;|x_4 - x_3| = 0.000002 < 0.00005, so stop
2≈1.4142\sqrt{2} \approx 1.4142 (true value 1.41421356…). Four steps, using only arithmetic.
kxkx_k∣xk−xk−1∣|x_k - x_{k-1}|
01.000000—
11.5000000.500000
21.4166670.083333
31.4142160.002451
41.4142140.000002
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
9 / 17

The same loop in Python and C

  • Press ▶ Run, then switch the tab to C and run again: same numbers
  • Change N to 10 and run
  • Change x (the first guess) to 1000: how many more steps?
  • Make tol 1e-20. What happens, and why? (Lecture 2)
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
10 / 17

When do we stop iterating?

An iteration never reaches the exact answer, so we must decide when it is close enough.

Absolute change∣xk+1−xk∣<ε|x_{k+1} - x_k| < \varepsilon
Relative change (scale-free)∣xk+1−xk∣∣xk+1∣<ε\dfrac{|x_{k+1} - x_k|}{|x_{k+1}|} < \varepsilon
Residual (for f(x) = 0)∣f(xk+1)∣<ε|f(x_{k+1})| < \varepsilon
  • Use relative change when xx may be very large or very small
  • A small change does not guarantee a small error, but for converging methods it is a good estimate
  • Always add a maximum number of iterations: if the method diverges, the loop must still end
  • "Correct to dd decimal places" means ∣xk+1−xk∣<0.5×10−d|x_{k+1} - x_k| < 0.5 \times 10^{-d}
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
11 / 17

What makes a numerical method good?

Accurate

The error can be made as small as we need, and we can estimate it.

Efficient

Few operations per step and few steps. Cost matters when n=106n = 10^6.

Stable

Small round-off errors stay small instead of growing (Lecture 5).

Robust

Works for many inputs; fails loudly, not silently.

No method wins on all four. Bisection is robust but slow; Newton is fast but can fail. Choosing the method for the problem is the skill this course builds.

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
12 / 17
Key summary

Types of iteration methods and their limitations

FamilyMethodsNeedsStrengthLimitation
BracketingBisection, False PositionAn interval [a,b][a,b] with f(a)f(b)<0f(a)f(b)<0Always convergesSlow; needs a sign change; misses double roots like (x−1)2(x-1)^2
Open: fixed pointIteration method x=g(x)x = g(x)A rewrite x=g(x)x = g(x) and x0x_0Very simpleConverges only if ∣g′(x)∣<1|g'(x)| < 1 near the root
Open: Newton–RaphsonTangent linef′(x)f'(x) and x0x_0Very fast (digits double)Fails if f′(x)≈0f'(x) \approx 0; may diverge from a poor x0x_0
Open: SecantChord through last two pointsx0x_0, x1x_1 (no derivative)Fast, no derivativeMay diverge; division by f(x1)−f(x0)≈0f(x_1)-f(x_0) \approx 0
Linear systemsJacobi, Gauss–SeidelAx=bA\mathbf{x}=\mathbf{b}, a starting vectorCheap for huge sparse systemsConverges only for e.g. diagonally dominant AA

Lectures 6–10 study each root-finding method in detail; Lecture 14 covers iterative methods for linear systems.

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
13 / 17
Beyond the classroom

Where this shows up in CSE and machine learning

🧠

Training a neural network

Each epoch is one iteration wk+1=wk−η∇L(wk)w_{k+1} = w_k - \eta \nabla L(w_k). The stopping rule is a tolerance on the loss or a maximum number of epochs: exactly today's two tests.

🎮

Game physics at 60 frames per second

Every frame advances positions with a numerical ODE step. Too large a step and objects fly through walls: a stability failure.

📈

Recommendation and ranking

PageRank and many recommender systems repeat xk+1=Mxkx_{k+1} = Mx_k until the vector stops changing.

🔊

Speech processing

Pitch tracking finds roots of a correlation function; enhancement solves least-squares problems frame by frame.

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
14 / 17
Practice

Practice problem

Problem 2"Why do we need to study numerical methods in CSE? Briefly describe different types of iteration methods and the limitations of each one of these."
Another wording: "Why are numerical methods considered indispensable in computer science, and how do they address challenges posed by mathematical functions that lack analytical solutions?"
How to write a complete answer
  • Open with a definition: an algorithm of finite arithmetic steps that computes an approximate answer with a controlled error
  • Give two or three concrete reasons with examples: no closed form (x=cos⁡xx=\cos x, quintics), huge systems, data with noise, ODEs
  • Name the families: bracketing (bisection, false position) and open (fixed point, Newton, secant)
  • One limitation each, in a small table
  • Finish with one CSE example (ML training, graphics, GPS)
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
15 / 17

Checkpoint

Checkpoint · think, then discuss with your neighbourWhich one of these problems needs a numerical method?
ASolve 2x+3=72x + 3 = 7
BSolve x=cos⁡xx = \cos x
CArea of a circle of radius 3
DDerivative of x2x^2
B. The others have exact formulas (x=2x=2, 9π9\pi, 2x2x). For x=cos⁡xx=\cos x we iterate: try xk+1=cos⁡xkx_{k+1} = \cos x_k from x0=1x_0 = 1 in the lab and watch it settle at 0.739085.
Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
16 / 17

Summary

Key points
  • Many problems (equations, integrals, ODEs, big systems, noisy data) have no exact formula
  • A numerical method = algorithm + error estimate + stopping rule
  • Iteration: guess → improve → check → repeat; Babylonian N\sqrt{N} doubles the correct digits each step
  • Stop on absolute or relative change, or residual, and always cap the iterations
  • Bracketing methods are safe but slow; open methods are fast but can diverge
Homework
  1. By hand, find 5\sqrt{5} with x0=2x_0 = 2 until 4 decimal places agree. Show the table.
  2. In the lab, run xk+1=cos⁡xkx_{k+1} = \cos x_k from x0=1x_0 = 1. How many iterations until 6 decimals agree? Compare with Babylonian 2\sqrt{2}.
  3. Write a half-page answer to Problem 2 with your own CSE example.
Next lecture

Floating-point numbers. Why does 0.1+0.2≠0.30.1 + 0.2 \ne 0.3 in Python and C? How many digits does a computer really keep, and what is machine epsilon?

Md Mahbub E Noor
Lecture 1: Why Numerical Methods?
University of Barishal
17 / 17