# Administrative Information
- **Instructor**: Scott Strong
- **Office**: SH205
- **Office Hours**: MTWR, 3-4pm
- **Student Assessment**:
- 79% of the total final grade will be split amongst the following categories, which are given a base of 10% each, with students choosing how to distribute the remaining 29% by 7/10/2026:
- **Attendance**: I will quickly take daily attendance
- I will record audio and locally transcribe
- I will take pictures of the boards and make them available after class
- I will take the transcription and boards and use generative AI to make a record on my website
- **Lecture Reflection**: I will use the information from lectures to create Canvas "quizzes" with unlimited retakes.
- **Workbook:** I will make available one "check your understanding" question per 50-minute lecture, and students will submit their work and take Canvas "quizzes" with unlimited retakes.
- **Timed Quizzes:** I will regularly quiz from the workbook. At least 48 hours of notice will be given. Three grades will be given: complete/full-credit, incomplete w/ corrections requested, and incomplete.
- **Homeworks**: I will give homework assignments that use the course material to make deeper connections with mathematics and mathematical thinking.
These five categories together determine the first 79% of the course grade. Each category is guaranteed a minimum weight of 10%. The remaining 29 percentage points will be distributed by the student among these five categories. You will be asked for your distribution after 1/3 of the course has been completed, and we will have renegotiations(limited) after 1/2 of the course has been completed. After this period, weights become fixed for the remainder of the semester.
- To earn an A or a B in the course, you must complete several larger-scale contextualized and scaffolded *projects* relevant to STEM. Project points are added to the engagement grade. Since the engagement categories are capped at 79%, any grade in the B or A range necessarily requires successful completion of one or more projects. Each project contains four milestones, each worth 1%, for a maximum project contribution of 20% toward the final course grade. Milestones will be assessed as complete, incomplete with revisions requested, or incomplete, across the four categories:
1. Prospecting and Planning: What is the project asking, what mathematics and algorithms are necessary, why are these calculations important, or how are they being used?
2. Implementation and Testing: What is one figure, one computation, and one result from this project that you can explain?
3. Completion and Interpretation: Return to the original project questions, complete the required computations, and explain what your results show.
4. Peer Review, Revision, and Final Submission: Trade projects with someone, review and offer critique, revise accordingly prior to final submission.
The (+/-) breaks for final letter grades are:
- $80\%\leq B- < 84\%$
- $84\%\leq B < 88\%$
- $88\% \leq B+ < 92\%$
- $92\%\leq A- < 95\%$
- $A\geq 95\%$
- [[Teaching/MATH307/Projects/MATH307Su25 - Projects|307Su25 Project Examples]]
- **On the horizon**: [Overleaf live feed](https://www.overleaf.com/read/fhdgfpncsrsy#3d0e9e)
- [[(307Su26) Workbook 0 - Euler's Formula]]
- The previous link takes you to its solution. Have a look but the real point of this is for you to upload something to Canvas so that I can test my workflows.
- 🎯 [Canvas quiz about WB0](https://elearning.mines.edu/courses/79896/assignments/564375)
- Not worth credit - workflow testing
- 🎯 [Canvas upload for a handwritten work](https://elearning.mines.edu/courses/79896/assignments/564400)
- Not worth credit - workflow testing
- [[(307Su26) Workbook 1 - The geometry of Gaussian functions]]
- 🎯 [Canvas quiz about WB1](https://elearning.mines.edu/courses/79896/assignments/564376)
- July 10th, future upload of WBs.
- Homework 1 - Due: July 8th
- [[MATH307Su26-HW1.pdf]]
- Lecture reflection quizzes after lecture post-processing
- 🎯 [MATH 307 — Day 1 Lecture Reflection (Functions, Sampling, Plotting)](https://elearning.mines.edu/courses/79896/quizzes/116507)
# Lecture Boards + Transcript + GenAI
> [!info]- About this section
> A generative-AI record of the lecture, built from the local audio transcript and photos of the boards. The board scans are linked at the end. Math is set in LaTeX; major named concepts link out to references.
## Why scientific computing?
Most problems in [science and engineering](https://en.wikipedia.org/wiki/Computational_science) do **not** resolve into the tidy closed forms of a calculus textbook — those are the curated exceptions. Crash-test simulations, Boeing's wing-to-failure load tests, loudspeaker-array modeling at concerts, and the analog-to-digital story of recorded sound are all problems we solve by **computing with numbers** rather than antidifferentiating by hand. The recurring theme that opens the course is **sampling**: *if you can sample a continuous signal finely enough, you do not need every point — just enough of them.* That single idea — replace a continuous object by finitely many samples and reason about the gaps — runs through plotting, root-finding, interpolation, and integration for the rest of the term.
## The function as a map
**Recall.** A [function](https://en.wikipedia.org/wiki/Function_(mathematics)) is a rule that turns inputs into outputs. We write it as a **map** (equivalently a **mapping** or **transformation**):
$f : D \subseteq \mathbb{R} \to R \subseteq \mathbb{R}, \qquad x \mapsto f(x).$
Reading the notation piece by piece:
- The colon is read **"such that"** — $f$ such that *stuff goes in and stuff comes out*.
- $x$ is the **input** (the [independent variable](https://en.wikipedia.org/wiki/Dependent_and_independent_variables)); $f(x)$ is the **output** (the dependent variable — it *depends* on $f$).
- $\mathbb{R} = (-\infty, \infty)$ is the [real number system](https://en.wikipedia.org/wiki/Real_number), open at both ends.
- $D \subseteq \mathbb{R}$ is the [domain](https://en.wikipedia.org/wiki/Domain_of_a_function) — the inputs we are allowed to feed in ($\subseteq$ means [subset of](https://en.wikipedia.org/wiki/Subset)).
- The [range](https://en.wikipedia.org/wiki/Range_of_a_function) is the set of outputs actually produced; it lives inside the [codomain](https://en.wikipedia.org/wiki/Codomain) $\mathbb{R}$ (the whole target space, *all the places we could have landed*).
> [!note] Why bother with the formal language?
> We will not wield this symbology on the regular. But framing computation as *a map sending a domain of inputs to a range of outputs* is exactly the mental model a computer needs: feed it a grid of inputs, get back a grid of outputs.
### Domain, range, and "onto"
Two quick examples expose the gap between range and codomain:
$y = f_1(x) = x^2, \qquad D = \mathbb{R} = (-\infty,\infty), \qquad R = [0,\infty).$
Squaring **destroys the sign**, so no negative number is ever an output. The range $[0,\infty)$ is a *proper* subset of the codomain $\mathbb{R}$, so the mapping is **not [onto](https://en.wikipedia.org/wiki/Surjective_function)** $\mathbb{R}$ — there are real numbers nothing maps to.
$y = f_2(x) = \sqrt{x}, \qquad D = [0,\infty), \qquad R = [0,\infty).$
Here the *input* must be restricted (the square root of a negative real is not real). This is how the language of **subsets of the domain/range** arises naturally — we are constantly pulling from, or landing in, restricted sets.
## Worked example — sketching $f(x) = x^2 - x^4$ by hand
The central example of the day. The goal is to sketch a [polynomial](https://en.wikipedia.org/wiki/Polynomial) from its *structural properties* (the [Calculus I](https://en.wikipedia.org/wiki/Calculus) curve-sketching toolkit) — and then, in the second half, reproduce that sketch on a computer.
### Even symmetry
Substitute $-x$ for the input and see what the map does:
$f(-x) = (-x)^2 - (-x)^4 = x^2 - x^4 = f(x).$
The even power destroys the sign in both terms, so $f(-x) = f(x)$: $f$ has [**even symmetry**](https://en.wikipedia.org/wiki/Even_and_odd_functions), and its graph is symmetric about the $y$-axis. **Payoff:** get the right half of the graph and the left half comes for free.
### Roots
Factor and set to zero:
$f(x) = x^2 - x^4 = x^2(1 - x^2) = 0 \;\;\Longrightarrow\;\; x_0 = 0, \quad x_1 = 1, \quad x_2 = -1.$
### Critical points (first derivative)
$f'(x) = 2x - 4x^3 = 2x(1 - 2x^2) = 0 \;\;\Longrightarrow\;\; x^{*} = 0, \quad x^{*}_{\pm} = \pm\tfrac{1}{\sqrt{2}}.$
The [critical points](https://en.wikipedia.org/wiki/Critical_point_(mathematics)) are where the [tangent line](https://en.wikipedia.org/wiki/Tangent) is horizontal.
### Concavity and classification (second derivative)
$f''(x) = 2 - 12x^2.$
Apply the [second-derivative test](https://en.wikipedia.org/wiki/Second_derivative_test):
$f''(0) = 2 - 0 = 2 > 0 \;\Rightarrow\; \boxed{x^{*}=0 \text{ is a local min}}$
$f''\!\left(\pm\tfrac{1}{\sqrt 2}\right) = 2 - 12\cdot\tfrac{1}{2} = 2 - 6 = -4 < 0 \;\Rightarrow\; \boxed{x^{*}_{\pm}=\pm\tfrac{1}{\sqrt 2} \text{ are local maxima}}$
The natural escalation $f \to f' \to f''$ is the whole game: each derivative exposes a new layer of "special points."
### End behavior and the sketch
Since $\tfrac{1}{\sqrt 2}\approx \tfrac{1}{1.4}\approx 0.71$ sits between $0$ and $1$, and as $x \to \pm\infty$ the $-x^4$ term dominates $x^2$, the curve falls to $-\infty$ on both ends. Combined with even symmetry, the sketch rises from $-\infty$, crosses at $x=-1$, peaks at $-\tfrac{1}{\sqrt2}$, dips to the local min at the origin (also a root), peaks again at $+\tfrac{1}{\sqrt2}$, crosses at $x=1$, and falls to $-\infty$ — the twin-humped "M/W on its side" shape on the board.
## From a continuous curve to samples — discretization
Here is the conceptual hinge of the course. The smooth curve of $f$ contains **[uncountably many](https://en.wikipedia.org/wiki/Uncountable_set)** points — *"if we got all the fingers and toes in the universe, we still won't be able to cover all the points."* A computer cannot store that. So we **[sample](https://en.wikipedia.org/wiki/Sampling_(signal_processing))**: replace the curve by a finite string of dots and, in our minds, play *connect-the-dots*.
Because we discretize so often, there is a dedicated command, [`linspace`](https://en.wikipedia.org/wiki/Linspace), that builds a grid of **evenly (linearly) spaced** points:
$\texttt{linspace(a, b, N)} \;\longrightarrow\; N \text{ points evenly spaced across } [a,b].$
**How many points?** Watch the plot converge by eye:
| Samples on $[-1,1]$ | What you see |
|---|---|
| `linspace(-1,1,5)` → $-1,-0.5,0,0.5,1$ | crude; spurious "triangles" |
| 10 – 12 points | better, still malformed (note odd-vs-even count on a symmetric function) |
| 100 points | visually indistinguishable from the true curve |
> [!warning] What you are really looking at
> Even at 100 points you are **not** plotting a continuous curve — you are plotting 100 dots that happen to lie on it. Keep that distinction; the whole next lecture depends on it.
## List plots vs. line plots — what the computer actually stores
A [scatter / list plot](https://en.wikipedia.org/wiki/Scatter_plot) draws only the dots. A line plot adds the connecting segments — but those segments are **[interpolation](https://en.wikipedia.org/wiki/Interpolation) the software paints in for your eye.** The computer only ever knew the dots.
This sets up the problem we code next time: a root or critical point can fall **between** two sampled dots, so you cannot just read it off the grid. The fix is to detect a **[sign change](https://en.wikipedia.org/wiki/Sign_function)** between consecutive samples — if $f(x_i)$ and $f(x_{i+1})$ have opposite signs, a root lies in the bracket $[x_i, x_{i+1}]$. *(Coded up next class.)*
![[Teaching/MATH307/MATH307Su26/Lecture Notes/Media/Day 1/day1_f_and_fprime.png]]
> [!quote]- A few pedagogical asides from the room
> - **Analog → digital** (vinyl/cassette → CD) is the original sampling story: sample fast enough and you recover the sound from finitely many points.
> - **Animation as sampling**: a choppy flip-book is *under-sampled*; smoothing it by inventing in-between frames is *interpolation* (and bad interpolation invents garbage).
> - **Deliberate errors**: the `^`-vs-`.^` mistake below was written on purpose — *"let's see what it's like when it's not correct."*
> [!example]- Board scans (June 29, 2026)
> 
> 
> 
---
# Check Your Understanding
This is [[(307Su26) Workbook 1 - The geometry of Gaussian functions|Workbook #1]] — the same curve-sketching machinery from today's $x^2 - x^4$ example, now applied to the [Gaussian](https://en.wikipedia.org/wiki/Gaussian_function) that anchors Homework 1.
> [!question] CYU — Workbook #1: The geometry of Gaussian functions
> Given $y = f(x) = e^{-x^2}$, show that the function is
> 1. **even**,
> 2. **decreasing for $x > 0$**, and
> 3. **inflects at $x = \pm\tfrac{1}{\sqrt 2}$**.
>
> Knowing these geometric features, **plot $f$** for $x \in \left[-\tfrac{3\sqrt 2}{2},\, \tfrac{3\sqrt 2}{2}\right]$.
> [!tip]- How today's tools apply
> Everything you need is the $f \to f' \to f''$ escalation from the board, plus the sampling idea:
> - **Even:** substitute $-x$ into the map — $f(-x) = e^{-(-x)^2} = e^{-x^2} = f(x)$, so the graph is symmetric about the $y$-axis (sketch the right half, mirror it).
> - **Decreasing for $x>0$:** $f'(x) = -2x\,e^{-x^2}$; since $e^{-x^2} > 0$ always, the sign of $f'$ is the sign of $-2x$, which is negative for $x>0$.
> - **Inflections:** $f''(x) = 2(2x^2 - 1)\,e^{-x^2}$, which vanishes and changes sign at $2x^2 - 1 = 0 \Rightarrow x = \pm\tfrac{1}{\sqrt 2}$.
> - **The plot window** $\pm\tfrac{3\sqrt 2}{2} = \pm\tfrac{3}{\sqrt 2} \approx \pm 2.12$ is exactly *three inflection-widths* — wide enough to show the bell flattening into its tails. Sample it with `linspace` (try 50+ points) and connect the dots.
> [!note]- Workbook numbering
> The Workbook is numbered from 0: **WB0** = Euler's identity, **WB1** = this Gaussian-geometry problem (today), **WB2** = naive root finding, **WB3** = Taylor series of the Gaussian. The Canvas quiz for WB1 is linked in *On the horizon* above.
---
# Code Overview
> [!info]- How to use this section
> Today's live code was written in MATLAB (`LivePlotting_1.m`). Per the course's four-language policy, it is ported below to **Python (reference), MATLAB, R, and Mathematica**. Open only the callout for the language you are using — each walks the same five moves: **sample → evaluate element-wise → plot with markers → add the derivative → overlay**. The Python version is run and verified in the sandbox; the others are written to the porting conventions in `COURSE.md` and are for you to run locally. Runnable files live in `codes/01/day1_live/`.
**The task.** Reproduce the hand sketch of $f(x) = x^2 - x^4$ on $[-1,1]$ by sampling it, then overlay its derivative $f'(x) = 2x - 4x^3$.
> [!example]- Python (reference)
>
> **Step 1 — sample the domain.** `linspace` lays down the connect-the-dots grid.
> ```python
> import numpy as np
> import matplotlib.pyplot as plt
> x = np.linspace(-1, 1, 50) # 50 evenly spaced samples on [-1, 1]
> ```
> *Look for:* `x` is 50 points; `x[0] == -1`, `x[-1] == 1`.
>
> **Step 2 — evaluate element-wise.** In numpy `**` already acts on the whole array.
> ```python
> y = x**2 - x**4 # f(x)
> yp = 2*x - 4*x**3 # f'(x)
> ```
> *Look for:* `y` is even — `y` for $x$ and $-x$ agree.
>
> **Step 3 — plot $f$, Step 4 — add $f'$, Step 5 — overlay.** One `plt.plot` per series puts both on the same axes.
> ```python
> plt.figure()
> plt.plot(x, y, '-o', color='k', ms=3, label=r"$f(x)=x^2-x^4
quot;)
> plt.plot(x, yp, '-o', color='b', ms=3, label=r"$f'(x)=2x-4x^3quot;)
> plt.axhline(0, color='gray', lw=0.5)
> plt.xlabel("x"); plt.ylabel("y"); plt.legend(); plt.grid(True)
> plt.savefig("day1_f_and_fprime.png", dpi=150, bbox_inches="tight")
> plt.show()
> ```
> *Look for:* black $f$ with twin humps; blue $f'$ crossing zero three times, at $0$ and near $\pm0.707$.
> [!example]- MATLAB (as written in class)
>
> **Step 1 — sample.** The `;` suppresses the console echo.
> ```matlab
> x = linspace(-1, 1, 50);
> ```
> *Look for:* the Workspace pane shows `x` as 1×50.
>
> **Step 2 — evaluate element-wise (the `.^` lesson).**
> ```matlab
> % y = x^2 - x^4; % WRONG: '^' is MATRIX power -> dimension error
> y = x.^2 - x.^4; % '.^' raises every entry
> yp = 2*x - 4*x.^3; % explicit '*' required: 2*x, not 2x
> ```
> *Look for:* the commented line throws *"Incorrect dimensions for raising a matrix to a power"* — that is the whole point.
>
> **Steps 3–5 — plot and overlay with `hold`.**
> ```matlab
> hold on % build the overlay, then "smear" both on at once
> plot(x, y, '-ok') % f : solid line, circle markers, k = black
> plot(x, yp, '-ob') % f' : solid line, circle markers, b = blue
> hold off
> xlabel('x'); ylabel('y'); grid on
> legend('f(x)=x^2-x^4','f''(x)=2x-4x^3')
> ```
> *Look for:* `k` is black because `b` is already **blue**.
> [!example]- R
>
> **Step 1 — sample.** R's `linspace` is `seq(..., length.out=)`.
> ```r
> x <- seq(-1, 1, length.out = 50)
> ```
> **Step 2 — evaluate.** `^` is already element-wise in R.
> ```r
> y <- x^2 - x^4
> yp <- 2*x - 4*x^3
> ```
> **Steps 3–5 — plot and overlay.** `plot` opens the canvas; `lines`/`points` add to it.
> ```r
> draw <- function() {
> plot(x, y, type = "o", pch = 16, col = "black",
> xlab = "x", ylab = "y", ylim = range(y, yp))
> lines(x, yp, type = "o", pch = 16, col = "blue")
> abline(h = 0, col = "gray")
> legend("topright", legend = c("f", "f'"),
> col = c("black", "blue"), pch = 16)
> }
> if (interactive()) draw() # show on screen
> png("day1_f_and_fprime.png", width=900, height=700, res=150); draw(); dev.off()
> ```
> *Look for:* the `draw()`-closure pattern (from `COURSE.md`) shows on screen **and** saves under headless `Rscript`.
> [!example]- Mathematica (numerical only)
>
> **Step 1 — sample.** `Subdivide[a,b,n]` makes `n+1` points; wrap in `N` for machine numbers.
> ```wolfram
> x = N@Subdivide[-1, 1, 49]; (* 50 evenly spaced samples *)
> ```
> **Step 2 — evaluate.** Arithmetic is *listable* — it acts entrywise automatically.
> ```wolfram
> y = x^2 - x^4;
> yp = 2 x - 4 x^3;
> ```
> **Steps 3–5 — plot and overlay.** Pair coordinates and hand both lists to `ListLinePlot`.
> ```wolfram
> pts = Transpose[{x, y}]; ptsp = Transpose[{x, yp}];
> plot = ListLinePlot[{pts, ptsp}, Mesh -> All,
> PlotStyle -> {Black, Blue}, AxesLabel -> {"x", "y"},
> PlotLegends -> {"f", "f'"}];
> plot (* evaluate alone to display *)
> Export["day1_f_and_fprime.png", plot] (* writes to Directory[] *)
> ```
> *Look for:* `Mesh -> All` draws the actual sample dots; keep it **numerical** (no symbolic `D`/`Solve`).
> [!tip]- Beyond class (peek ahead)
> The fuller development — sampling on a fine grid, detecting roots of $f'$ by **sign change**, then classifying each with the second-derivative test and marking maxima/minima/inflections — is staged in `codes/01/plotting_01.py … plotting_05.py`. That is exactly the "find the point between the dots" problem flagged above, and it is where Day 2 picks up.