lots of cleanup

This commit is contained in:
jverzani
2026-08-11 17:17:08 -04:00
parent ae461659e0
commit 253295ff6e
91 changed files with 18284 additions and 7872 deletions

View File

@@ -3,13 +3,12 @@
{{< include ../_common_code.qmd >}}
In this section we will use these add-on packages:
In this section we will use this add-on package:
```{julia}
using CalculusWithJulia
using Plots
plotly()
plotly();
```
---
@@ -37,8 +36,9 @@ Why is this useful? When available, it can help us solve equations. If we can wr
Let's explore when we can "solve" for an inverse function.
Consider this graph of the function $f(x) = 2^x$
Consider @fig-plot-2-x-showing-x-to-y-and-y-to-x showing a graph of the function $f(x) = 2^x$.
::: {#fig-plot-2-x-showing-x-to-y-and-y-to-x}
```{julia}
#| echo: false
p = let
@@ -84,12 +84,15 @@ plotly()
p
```
The graph of a function is a representation of points $(x,f(x))$, so to *find* $y = f(c)$ from the graph, we begin on the $x$ axis at $c$, move vertically to the graph (the point $(c, f(c))$), and then move horizontally to the $y$ axis, intersecting it at $y = f(c)$. The figure shows this for $c=2$, from which we can read that $f(c)$ is about $4$. This is how an $x$ is associated to a single $y$.
Plot of $f(x) = 2^x$ illustrating how to graphically start from $x=c$ to find $f(c)$ and how to start from $y=f(d)$ to find $d$
:::
The graph of a function is a representation of points $(x,f(x))$, so to *find* $y = f(c)$ from the graph, we begin on the $x$ axis at $c$, move vertically to the graph (the point $(c, f(c))$), and then move horizontally to the $y$ axis, intersecting it at $y = f(c)$. This is how an $x$ is associated to a single $y$.
If we were to *reverse* the direction, starting at $y = f(d)$ on the $y$ axis and then moving horizontally to the graph, and then vertically to the $x$-axis we end up at a value $d$ with the correct value of $f(d)$. This allows solving for $x$ knowing $y$ in $y=f(x)$.
The operation described will form a function **if** the initial movement horizontally is guaranteed to find *no more than one* value on the graph. That is, to have an inverse function, there can not be two $x$ values corresponding to a given $y$ value. This observation is often visualized through the "horizontal line test" - the graph of a function with an inverse function can only intersect a horizontal line at most in one place.
The operation described will form a function **if** the initial movement horizontally is guaranteed to find *no more than one* value on the graph. That is, to have an inverse function, there can not be two $x$ values corresponding to a given $y$ value. This observation is often visualized through the "horizontal line test"---the graph of a function with an inverse function can only intersect a horizontal line at most in one place.
More formally, a function is called *one-to-one* *if* for any two $a \neq b$, it must be that $f(a) \neq f(b)$. Many functions are one-to-one, many are not. Familiar one-to-one functions are linear functions ($f(x)=a \cdot x + b$ with $a\neq 0$), odd powers of $x$ ($f(x)=x^{2k+1}$), and functions of the form $f(x)=x^{1/n}$ for $x \geq 0$. In contrast, all *even* functions are *not* one-to-one, as $f(x) = f(-x)$ for any nonzero $x$ in the domain of $f$.
@@ -183,7 +186,7 @@ y - 2 &= (x-1)^5\\
\end{align*}
$$
We see that $f^{-1}(x) = 1 + (x - 2)^{1/5}$. The fact that the power $5$ is an odd power is important, as this ensures a unique (real) solution to the fifth root of a value, in the above $y-2$.
We see that $f^{-1}(x) = (x - 2)^{1/5} + 1$. The fact that the power $5$ is an odd power is important, as this ensures a unique (real) solution to the fifth root of a value, in the above $y-2$.
In the section on [polynomial roots](../precalc/polynomial_roots.html) we introduce the `solve` function of `SymPy`, which can algebraically solve for inverse functions in easier cases.
@@ -196,7 +199,7 @@ In the section on [polynomial roots](../precalc/polynomial_roots.html) we intro
The function $f(x) = x^x, x \geq 1/e$ is strictly increasing. However, trying to algebraically solve for an inverse function will quickly run into problems (without using specially defined functions). The existence of an inverse does not imply there will always be luck in trying to find a mathematical rule defining the inverse.
In the section on the [intermediate value theorem](../limits/intermediate_value_theorem.html#the-find_zero-function) we will see how to *numerically* solve for an inverse function.
In the section on the intermediate value theorem we will see how to *numerically* solve for an inverse function.
## Functions which are not always invertible
@@ -205,7 +208,7 @@ In the section on the [intermediate value theorem](../limits/intermediate_value_
Consider the function $f(x) = x^2$. The graph---a parabola---is clearly not *monotonic*. Hence no inverse function exists. Yet, we can solve equations $y=x^2$ quite easily: $y=\sqrt{x}$ *or* $y=-\sqrt{x}$. We know the square root undoes the squaring, but we need to be a little more careful to say the square root is the inverse of the squaring function.
The issue is there are generally *two* possible answers. To avoid this, we might choose to only take the *non-negative* answer. To make this all work as above, we restrict the domain of $f(x)$ and now consider the related function $f(x)=x^2, x \geq 0$. This is now a monotonic function, so will have an inverse function. This is clearly $f^{-1}(x) = \sqrt{x}$. (The $\sqrt{x}$ being defined as the principle square root or the unique *non-negative* answer to $u^2-x=0$.)
The issue in this case is there are generally *two* possible answers. To avoid this, we might choose to only take the *non-negative* answer. To make this all work as above, we restrict the domain of $f(x)$ and now consider the related function $f(x)=x^2, x \geq 0$. This is now a monotonic function, so will have an inverse function. This is clearly $f^{-1}(x) = \sqrt{x}$. (The $\sqrt{x}$ being defined as the principle square root or the unique *non-negative* answer to $u^2-x=0$.)
The [inverse function theorem](https://en.wikipedia.org/wiki/Inverse_function_theorem) basically says that if $f$ is *locally* monotonic, then an inverse function will exist *locally*. By "local" we mean in a neighborhood of $c$.
@@ -234,7 +237,7 @@ Then $f^{-1}(x) = \sqrt{(1-x)/x}$ where $0 < x \leq 1$. The somewhat complicated
Consider again the graph of a monotonic function, in this case $f(x) = x^2 + 2, x \geq 0$:
::: {#fig-plot-xsquared-plus-2-domain-range}
```{julia}
#| hold: true
f(x) = x^2 + 2
@@ -243,25 +246,31 @@ plot(f, 0, 4; yticks=[2,4,8,16],
plot!([(2,0), (2, f(2)), (0, f(2))])
```
Plot of $f(x) = x^2 + 2$ over $[0,4]$
:::
The graph is shown over the interval $(0,4)$, but the *domain* of $f(x)$ is all $x \geq 0$. The *range* of $f(x)$ is clearly $2 \leq y \leq \infty$.
The lines layered on the plot show how to associate an $x$ value to a $y$ value or vice versa (as $f(x)$ is one-to-one). The domain then of the inverse function is all the $y$ values for which a corresponding $x$ value exists: this is clearly all values bigger or equal to $2$. The *range* of the inverse function can be seen to be all the images for the values of $y$, which would be all $x \geq 0$. This gives the relationship:
> * the *domain* of $f^{-1}(x)$ is the *range* of $f(x)$;
> * the *range* of $f^{-1}(x)$ is the *domain* of $f(x)$;
::: {.relationship title="The domain and range"}
The *domain* of $f^{-1}(x)$ is the *range* of $f(x)$.
The *range* of $f^{-1}(x)$ is the *domain* of $f(x)$.
:::
From this we can see if we start at $x$, apply $f$ we get $y$, if we then apply $f^{-1}$ we will get back to $x$ so we have:
> For all $x$ in the domain of $f$: $f^{-1}(f(x)) = x$.
::: {.relationship title = "Composition with an inverse"}
For all $x$ in the domain of $f$: $f^{-1}(f(x)) = x$.
Similarly, were we to start on the $y$ axis, we would see:
> For all $x$ in the domain of $f^{-1}$: $f(f^{-1}(x)) = x$.
For all $x$ in the domain of $f^{-1}$: $f(f^{-1}(x)) = x$.
In short $f^{-1} \circ f$ and $f \circ f^{-1}$ are both identity functions, though on possibly different domains.
:::
## The graph of the inverse function
@@ -269,37 +278,41 @@ In short $f^{-1} \circ f$ and $f \circ f^{-1}$ are both identity functions, thou
The graph of $f(x)$ is a representation of all values $(x,y)$ where $y=f(x)$. As the inverse flips around the role of $x$ and $y$ we have:
> If $(x,y)$ is a point on the graph of $f(x)$, then $(y,x)$ will be a point on the graph of $f^{-1}(x)$.
::: {.relationship title="Mirror points"}
If $(x,y)$ is a point on the graph of $f(x)$, then $(y,x)$ will be a point on the graph of $f^{-1}(x)$.
:::
Let's see this in action. Take the function $2^x$. We can plot it by generating points to plot as follows:
::: {#fig-plot-2-to-x-and-inverse-with-xs-ys}
```{julia}
#| hold: true
f(x) = 2^x
xs = range(0, 2, length=50)
ys = f.(xs)
plot(xs, ys; color=:blue, label="f",
aspect_ratio=:equal, framestyle=:origin, xlims=(0,4))
plot(xs, ys; aspect_ratio=:equal, framestyle=:origin,
xlims=(0,4),
color=:blue, label="f")
plot!(ys, xs; color=:red, label="f⁻¹") # the inverse
```
Plot of $f(x) = 2^x$ using `plot(xs, ys)` and its inverse produced with `plot!(ys, xs)`
:::
By flipping around the $x$ and $y$ values in the `plot!` command, we produce the graph of the inverse function---when viewed as a function of $x$. We can see that the domain of the inverse function (in red) is clearly different from that of the function (in blue).
The inverse function graph can be viewed as a symmetry of the graph of the function. Flipping the graph for $f(x)$ around the line $y=x$ will produce the graph of the inverse function: Here we see for the graph of $f(x) = x^{1/3}$ and its inverse function:
The inverse function graph can be viewed as a symmetry of the graph of the function. Flipping the graph for $f(x)$ around the line $y=x$ will produce the graph of the inverse function: @fig-plot-cbrt-and-its-inverse show the graph of $f(x) = x^{1/3}$ and its inverse function:
::: {#fig-plot-cbrt-and-its-inverse}
```{julia}
#| hold: true
f(x) = cbrt(x)
xs = range(-2, 2, length=150)
ys = f.(xs)
plot(xs, ys; color=:blue,
aspect_ratio=:equal, legend=false)
plot(xs, ys; aspect_ratio=:equal, legend=false,
line=(:blue,))
plot!(ys, xs; line=(:red,))
plot!(identity; line=(:green, :dash))
x = 1/4
@@ -307,11 +320,15 @@ y = f(x)
plot!([(x,y), (y,x)]; line=(:green, :dot))
```
We drew a line connecting $(1/4, f(1/4))$ to $(f(1/4),1/4)$. We can see that it crosses the line $y=x$ perpendicularly, indicating that points are symmetric about this line. (The plotting argument `aspect_ratio=:equal` ensures that the $x$ and $y$ axes are on the same scale, so that this type of line will look perpendicular.)
Plot of $f(x) = x^{1/3}$ and its inverse
:::
In @fig-plot-cbrt-and-its-inverse we drew a line connecting $(1/4, f(1/4))$ to $(f(1/4),1/4)$. We can see that this line crosses the line $y=x$ perpendicularly, indicating that points are symmetric about the $y=x$ line. (The plotting argument `aspect_ratio=:equal` ensures that the $x$ and $y$ axes are on the same scale, so that this type of line will look perpendicular.)
One consequence of this symmetry, is that if $f$ is strictly increasing, then so is its inverse.
::: {.callout-note}
## `cbrt(x)` is different from `x^(1/3)`
In the above we used `cbrt(x)` and not `x^(1/3)`. The latter usage assumes that $x \geq 0$ as it isn't guaranteed that for all real exponents the answer will be a real number. The `cbrt` function knows there will always be a real answer and provides it.
:::
@@ -321,12 +338,12 @@ In the above we used `cbrt(x)` and not `x^(1/3)`. The latter usage assumes that
The slope of $f(x) = 9/5 \cdot x + 32$ is clearly $9/5$ and the slope of the inverse function $f^{-1}(x) = 5/9 \cdot (x-32)$ is clearly $5/9$ - or the reciprocal. This makes sense, as the slope is the rise over the run, and by flipping the $x$ and $y$ values we merely flip over the rise and the run.
Now consider the graph of the *tangent line* to a function. This concept will be better defined later, for now, it is a line "tangent" to the graph of $f(x)$ at a point $x=c$.
Now consider the graph of the *tangent line* to a function. This concept will be better defined later.
For concreteness, we consider $f(x) = \sqrt{x}$ at $c=2$. The tangent line will have slope $1/(2\sqrt{2})$ and will go through the point $(2, f(2))$. We graph the function, its tangent line, and their inverses:
For concreteness, we consider $f(x) = \sqrt{x}$ at $c=2$. The tangent line will have slope $1/(2\sqrt{2})$ and will go through the point $(2, f(2))$. In @fig-plot-sqrt-x-its-inverse-two-tangent-lines we graph the function, its tangent line, and their inverses.
::: {#fig-plot-sqrt-x-its-inverse-two-tangent-lines}
```{julia}
#| hold: true
f(x) = sqrt(x)
@@ -339,8 +356,13 @@ plot(xs, ys, color=:blue, legend=false)
plot!(xs, zs, color=:blue) # the tangent line
plot!(ys, xs, color=:red) # the inverse function
plot!(zs, xs, color=:red) # inverse of tangent line
scatter!([(c, f(c))], marker=(:blue, 3))
scatter!([(f(c),c)], marker=(:red, 3))
```
Plot of $f(x) = \sqrt{x}$, its inverse, and two related tangent lines
:::
What do we see? In blue, we can see the familiar square root graph along with a "tangent" line through the point $(2, f(2))$. The red graph of $f^{-1}(x) = x^2, x \geq 0$ is seen and, perhaps surprisingly, a tangent line. This is at the point $(f(2), 2)$. We know the slope of this tangent line is the reciprocal of the slope of the red tangent line. This gives this informal observation:
@@ -493,8 +515,8 @@ Is it possible that a function have two different inverses?
#| echo: false
choices = [L"No, for all $x$ in the domain and an inverse, the value of any inverse will be the same, hence all inverse functions would be identical.",
L"Yes, the function $f(x) = x^2, x \geq 0$ will have a different inverse than the same function $f(x) = x^2, x \leq 0$"]
answ = 1
radioq(choices, answ)
answer = 1
buttonq(choices, answer)
```
###### Question
@@ -509,8 +531,8 @@ A function takes a value $x$ adds $1$, divides by $2$, and then subtracts $1$. I
choices = [L"Yes, the function is the linear function $f(x)=(x+1)/2 - 1$ and so is monotonic.",
L"No, the function is $1$ then $2$ then $1$, but not \"one-to-one\""
]
answ = 1
radioq(choices, answ)
answer = 1
buttonq(choices, answer)
```
###### Question
@@ -525,8 +547,8 @@ Is the function $f(x) = x^5 - x - 1$ one-to-one?
choices=[L"Yes, a graph over $(-100, 100)$ will show this.",
L"No, a graph over $(-2,2)$ will show this."
]
answ = 2
radioq(choices, answ)
answer = 2
buttonq(choices, answer)
```
###### Question
@@ -560,15 +582,17 @@ yesnoq(false)
A function is defined by its graph.
::: {#fig-function-x-sinx-defined-by-graph}
```{julia}
#| hold: true
#| echo: false
f(x) = x - sin(x)
plot(f, 0, 6pi)
```
Plot of $f(x)$ over $[0, 6\pi]$
:::
Over the domain shown, is the function one-to-one?
Over the domain shown in @fig-function-x-sinx-defined-by-graph , is the function one-to-one?
```{julia}
@@ -590,8 +614,8 @@ What is $g(x) = (f(x))^{-1}$?
#| hold: true
#| echo: false
choices = ["``g(x) = x``", "``g(x) = x^{-1}``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
What is $g(x) = f^{-1}(x)$?
@@ -601,8 +625,8 @@ What is $g(x) = f^{-1}(x)$?
#| hold: true
#| echo: false
choices = ["``g(x) = x``", "``g(x) = x^{-1}``"]
answ = 2
radioq(choices, answ)
answer = 2
radioq(choices, answer)
```
###### Question
@@ -674,8 +698,8 @@ L"The function that multiplies by $2$, subtracts $1$ and then squares the value.
L"The function that divides by $2$, adds $1$, and then takes the square root of the value.",
L"The function that takes square of the value, then subtracts $1$, and finally multiplies by $2$."
]
answ = 1
radioq(choices, answ)
answer = 1
buttonq(choices, answer)
```
###### Question
@@ -744,8 +768,8 @@ choices = [
"``f^{-1}(x) = (5x-4)^3``",
"``f^{-1}(x) = 5/(x^3 + 4)``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -762,8 +786,8 @@ raw"``f^{-1}(x) = (x-e)^{1/\pi}``",
raw"``f^{-1}(x) = (x-\pi)^{e}``",
raw"``f^{-1}(x) = (x-e)^{\pi}``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -779,8 +803,8 @@ choices = [
raw"``[7, \infty)``",
raw"``(-\infty, \infty)``",
raw"``[0, \infty)``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -796,8 +820,8 @@ choices = [
raw"``[7, \infty)``",
raw"``(-\infty, \infty)``",
raw"``[0, \infty)``"]
answ = 3
radioq(choices, answ)
answer = 3
radioq(choices, answer)
```
###### Question
@@ -805,7 +829,7 @@ radioq(choices, answ)
From the plot, are blue and red inverse functions?
::: {#fig-plot-of-blue-red-inverse-maybe-1}
```{julia}
#| hold: true
#| echo: false
@@ -816,6 +840,8 @@ plot(xs, ys, color=:blue, legend=false)
plot!(ys, xs, color=:red)
plot!(x->x, linestyle=:dash)
```
Plot of two functions, one in blue, one in red along with the line $y=x$.
:::
```{julia}
#| hold: true
@@ -825,7 +851,7 @@ yesnoq(true)
From the plot, are blue and red inverse functions?
::: {#fig-plot-of-blue-red-inverse-maybe-2}
```{julia}
#| hold: true
#| echo: false
@@ -836,6 +862,8 @@ plot(xs, ys, color=:blue, legend=false)
plot!(-xs, -ys, color=:red)
plot!(x->x, linestyle=:dash)
```
Plot of two functions, one in blue, one in red along with the line $y=x$.
:::
```{julia}
#| hold: true
@@ -849,10 +877,13 @@ yesnoq(false)
The function $f(x) = (ax + b)/(cx + d)$ is known as a [Mobius](http://tinyurl.com/oemweyj) transformation and can be expressed as a composition of $4$ functions, $f_4 \circ f_3 \circ f_2 \circ f_1$:
* where $f_1(x) = x + d/c$ is a translation,
* where $f_2(x) = x^{-1}$ is inversion and reflection,
* where $f_3(x) = ((bc-ad)/c^2) \cdot x$ is scaling,
* and $f_4(x) = x + a/c$ is a translation.
* where $f_1(x) = x + d/c$ is a translation,
* where $f_2(x) = x^{-1}$ is inversion and reflection,
* where $f_3(x) = ((bc-ad)/c^2) \cdot x$ is scaling,
* and $f_4(x) = x + a/c$ is a translation.
For $x=10$, $a=1$, $b=2$, $c=3$ and $d=5$, what is $f(10)$?
@@ -886,8 +917,8 @@ choices = [
L"As $f_4(f_3(f_2(f_1(x))))=(f_1 \circ f_2 \circ f_3 \circ f_4)(x)$",
"As the latter is more complicated than the former."
]
answ=1
radioq(choices, answ)
answer=1
radioq(choices, answer)
```
Let $g_1$, $g_2$, $g_3$, and $g_4$ denote the inverse functions. Clearly, $g_1(x) = x- d/c$ and $g_4(x) = x - a/c$, as the inverse of adding a constant is subtracting the constant.
@@ -900,8 +931,8 @@ What is $g_2(x)=f_2^{-1}(x)$?
#| hold: true
#| echo: false
choices = ["``g_2(x) = x^{-1}``", "``g_2(x) = x``", "``g_2(x) = x -1``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
What is $g_3(x)=f_3^{-1}(x)$?
@@ -914,8 +945,8 @@ choices = [
raw"``c^2/(b\cdot c - a\cdot d) \cdot x``",
raw"``(b\cdot c-a\cdot d)/c^2 \cdot x``",
raw"``c^2 x``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
Given these, what is the value of $g_4(g_3(g_2(g_1(f_4(f_3(f_2(f_1(10))))))))$?