Numerical Analysis

Foundations and Exercises

TANAKA, Kazuaki (田中 一成)

Institute for Mathematical Science, Waseda University

Before We Start

📥
Please clone (or pull) the course materials repository right now.
First time
git clone https://github.com/waseda-num-analysis-2026/materials
Already cloned
cd materials
git pull

💡 Not sure how? Just ask your AI — it can run these commands for you.

Today's materials are inside 020/2nd/:
2nd.qmd slides (this file)
2nd.html rendered slides — viewable in browser
2nd-handout.qmd editable handout — customise it!
2nd-handout.html rendered handout — viewable in browser
Also in 020/python_guidelines/: Python Guidelines document & notebook.

⚠️ GitHub Copilot Student — Important Update

📰
As of April 20, 2026, new sign-ups for GitHub Copilot Student are temporarily paused.
Source: GitHub Changelog — Apr 20, 2026
Already verified?
You keep Copilot Student access as-is
⚠️
Pending / not yet verified?
New sign-up temporarily blocked — check github.com/settings/copilot

If Copilot Is Not Available — Alternatives

💻 Editor-based
GitHub Copilot Free VS Code extension
50 premium requests/month — github.com/settings/copilot
Cursor / Antigravity standalone editors
AI-first editors (not VS Code extensions — separate apps). Free quota limited. cursor.com / antigravity.dev
ChatGPT paid → Codex extension ⭐
If you have ChatGPT Plus/Pro, install the Codex VS Code extension — chat & edit code directly inside VS Code.
💬 Chat-based (browser)
Gemini / ChatGPT / Claude
Paste 2nd-handout.qmd into a thread → ask questions in the same thread.
I personally find Gemini handy — but it depends on the task.
Have a paid plan? Use it — Gemini Advanced, ChatGPT Plus/Pro, or Claude Pro give much better results.
💡 Free quotas run out? Sign up for all three (Gemini, ChatGPT, Claude) and rotate between them. For Gemini, multiple Google accounts work fine too.

What is Numerical Analysis?

Σ
A Branch of Mathematics
Algorithms for solving mathematical problems
that cannot be solved analytically
🏛️
Deep Historical Roots
Dating back to 1800 BCE, with significant contributions from renowned mathematicians throughout history
🌍
Wide Applications
Across natural sciences, engineering, and even humanities & social sciences
💻
Computer-Driven
Modern numerical analysis relies on computer technology for practical computation

Process of Numerical Analysis

A Very Simple Application

What is the radius of the circle whose area is \(2\) ?

r 2

\[\pi r^2 = 2 \quad\Longrightarrow\quad r = \sqrt{\dfrac{2}{\pi}}\]

Mathematically exact
\(r = \sqrt{2/\pi} \text{ m}\)
…but can you draw this with a ruler?
Numerically useful
\(r \approx 0.797 \text{ m}\)
→ You can measure this. Engineering becomes possible.
One goal of numerical analysis: efficiently compute numerical approximations that are good enough for practical use.

Errors in Numerical Computation

Can you trust your computer’s arithmetic?

\[10^{40} + 500 - 10^{40} = \;?\]

\[8.3 - 8 = \;?\]

Q. What is the value of \(x\)?

x = 100
for i = 1 to 60
    x = sqrt(x)
end
for i = 1 to 60
    x = x^2
end
a. x = 1000
b. x = 1
c. x = 10
d. x = 100
e. x = 0

So… why?

Every real number lives in this form:
\( \pm \left(\dfrac{d_0}{\beta^0} + \dfrac{d_1}{\beta^1} + \dfrac{d_2}{\beta^2} + \cdots\right) \cdot \beta^{e} \)
\(\beta\): base  (e.g. 10 or 2) \(d_i\): digits  \((0 \leq d_i \leq \beta-1)\) \(e\): exponent
↑ but a computer can only store finitely many digits \(d_i\)
In base 10
\(0.2 = 2 \times 10^{-1}\)
finite
In base 2
\(0.2 = 0.0011\,0011\,0011\ldots_{(2)}\)
infinite!

Types of Errors

Age Estimator (1)

67 million years old (true age)
🧠
67.1 million years

\[\text{Error} = |67.1 - 67| = 0.1 \text{ million years} = 100{,}000 \text{ years}\]

Age Estimator (2)

37 years old (true age)
🧠
100,037 years

\[\text{Error} = |100{,}037 - 37| = 100{,}000 \text{ years}\]

Absolute Error and Relative Error — Definition

Let \(x\) be the true value and \(\hat{x}\) be its approximation.

Absolute Error (or simply, Error): \[ |x - \hat{x}| \]

Relative Error (for \(x \neq 0\)): \[ \left|\dfrac{x - \hat{x}}{x}\right| \quad\left(\;\approx \left|\dfrac{x - \hat{x}}{\hat{x}}\right|\;\right) \]

Absolute Error and Relative Error

Absolute Error
Relative Error
\(|67{,}100{,}000 - 67{,}000{,}000|\)
\(= 100{,}000\)
\(\dfrac{100{,}000}{67{,}000{,}000} \approx\)
0.00149 😊
\(|100{,}037 - 37|\)
\(= 100{,}000\)
\(\dfrac{100{,}000}{37} \approx\)
2702 😱
Same absolute error — but the relative errors tell a completely different story.

Error Propagation & Cancellation

ADDITION  /  SUBTRACTION
Absolute errors add up:
\( \bigl|e_{x+y}\bigr| \;\le\; |e_x| + |e_y| \)
MULTIPLICATION  /  DIVISION
Relative errors add up:
\( \left|\dfrac{e_{xy}}{xy}\right| \;\lesssim\; \left|\dfrac{e_x}{x}\right| + \left|\dfrac{e_y}{y}\right| \)
⚠️ CANCELLATION (LOSS OF SIGNIFICANT DIGITS)
When subtracting two close values \(x \approx y\), the relative error is amplified by \( \left|\dfrac{x}{x-y}\right| \) — possibly huge.
\( \left|\dfrac{(x - y) - (\hat{x} - \hat{y})}{x - y}\right| = \left|\dfrac{x}{x-y}\cdot \dfrac{e_x}{x} \;+\; \dfrac{y}{x-y}\cdot \dfrac{e_y}{y}\right| \)

Exercise 2.0 — Evolve the Handout with AI

Repository: same as Ex 2.1   |   Submit: 2nd-handout.qmd (your edited copy)   |   Deadline: Apr 30 (Wed), 23:59

While studying 2nd-handout.qmd, insert at least 3 Q&A blocks of your own — questions you actually had while reading, answered with the help of GitHub Copilot (or another AI) following the protocol in AI_TUTOR.md.

How to submit

  1. Copy materials/020/2nd-handout.qmd into the root of your Ex 2 repository
  2. Open it in VS Code, then for each question:
    • Highlight the line you don’t understand
    • Ask Copilot using the prompt in AI_TUTOR.md § Student Prompt Cookbook
    • Verify the AI’s answer, then commit the inserted Q&A block
  3. Repeat for ≥ 3 distinct questions, then git push

💡 The Q&A block format and an English example are at the top of 2nd-handout.qmd.

Exercise 2.1 — Absolute / Relative Error Functions

Repository: Ex 2 — GitHub Classroom   |   Edit: ex2-1.qmd   |   Deadline: Apr 24 (today), 23:59

Write two Python functions that take two real numbers and return the absolute error and the relative error, respectively:

  • abs_error(a, b)\(|a - b|\)
  • rel_error(a, b)\(|a - b| / |a|\)

where a is the true value and b is the approximate value.

Test your functions on at least 3 pairs of your own choice (e.g. compare math.pi with truncated decimals).

Exercise 2.2 — Cancellation in \(\dfrac{1}{1-\sqrt{x}}\)

Repository: same as Ex 2.1   |   Edit: ex2-2.qmd   |   Deadline: Apr 24 (today), 23:59

Consider \(\;f(x) = \dfrac{1}{1 - \sqrt{x}}\), which becomes numerically unstable as \(x \to 1\).

  1. Implement the function f1(x) exactly as given.
  2. Derive an algebraically equivalent but more stable expression and implement it as f2(x).
  3. Compare f1(x) and f2(x) for \(x = 0.9,\ 0.99,\ 0.999,\ 0.9999,\ 0.99999\).
  4. Report the relative difference between the two implementations for each \(x\).

Hint. Rationalize the denominator: multiply numerator and denominator by \(1 + \sqrt{x}\).

Exercise 2.3 — Quadratic Equation without Cancellation

Repository: same as Ex 2.1   |   Edit: ex2-3.qmd   |   Deadline: Apr 30 (Wed), 23:59

Write a Python function solve_quadeq(a, b, c) that returns the two solutions of \(ax^2 + bx + c = 0\ (a \neq 0)\), avoiding cancellation as much as possible.

Apply your function to:

\[ a = 1,\ b = 10^{15},\ c = 10^{14} \qquad\text{and}\qquad a = 1,\ b = -10^{15},\ c = 10^{14} \]

Discuss in your notebook:

  1. Why the standard quadratic formula suffers from cancellation in these cases.
  2. How your implementation avoids it.
  3. Compare the accuracy of your method with the direct formula.

Assignments and Preparation for Next Lecture

1

Accept the Ex 2 GitHub Classroom link once — one repository for all four parts

  • Edit ex2-1.qmd, ex2-2.qmd, ex2-3.qmd + your copy of 2nd-handout.qmd for Ex 2.0 (all .qmd)
  • Ex 2.1 & 2.2: Apr 24 (today), 23:59
  • Ex 2.0 & 2.3: Apr 30 (Wed), 23:59
  • Submit by git push — the last commit before each deadline is graded
2

Record a 5-minute explanatory video for Ex 2.3 and paste its URL into ex2-3.qmd

  • YouTube unlisted (限定公開) recommended; otherwise any link-shareable service (Google Drive, Dropbox, OneDrive, …)
  • Use Zoom, QuickTime, or OBS to record
  • Do not commit the MP4 file directly to the repository — paste a URL instead
3

Next class: "pair work" for Ex 2.3

  • You will be assigned to pairs (announced later)
  • Each person will watch the partner's video
  • Discuss strengths and areas for improvement together
  • Both members submit separate feedback sheets
  • 📻 Please bring your earphones
Evaluated on 5 axes
  1. Accuracy & Depth of Content
  2. Clarity of Explanation
  3. Structure & Time Management
  4. Audience Engagement
  5. Effective Use of Visual Aids