From d55e4802fb000e55771233a8cb0724a59d803a48 Mon Sep 17 00:00:00 2001 From: Fang Liu Date: Sun, 4 May 2025 15:08:47 +0800 Subject: [PATCH 01/11] some typos --- quarto/misc/julia_interfaces.qmd | 2 +- quarto/precalc/julia_overview.qmd | 2 +- quarto/precalc/polynomial.qmd | 8 ++++---- quarto/precalc/polynomial_roots.qmd | 4 ++-- quarto/precalc/polynomials_package.qmd | 8 ++++---- quarto/precalc/rational_functions.qmd | 6 +++--- quarto/precalc/trig_functions.qmd | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/quarto/misc/julia_interfaces.qmd b/quarto/misc/julia_interfaces.qmd index cf6d9ee..c527f59 100644 --- a/quarto/misc/julia_interfaces.qmd +++ b/quarto/misc/julia_interfaces.qmd @@ -80,7 +80,7 @@ Pluto has a built-in package management system that manages the installation of "Project [Jupyter](https://jupyter.org/) exists to develop open-source software, open-standards, and services for interactive computing across dozens of programming languages." The `IJulia` package allows `Julia` to be one of these programming languages. This package must be installed prior to use. -The Jupyter Project provides two web-based interfaces to `Julia`: the Jupyter notebook and the newer JupyterLab. The [binder](https://mybinder.org/) project use Juptyer notebooks for their primary interface to `Julia`. To use a binder notebook, follow this link: +The Jupyter Project provides two web-based interfaces to `Julia`: the Jupyter notebook and the newer JupyterLab. The [binder](https://mybinder.org/) project use Jupyter notebooks for their primary interface to `Julia`. To use a binder notebook, follow this link: [launch binder](https://mybinder.org/v2/gh/CalculusWithJulia/CwJScratchPad.git/master) diff --git a/quarto/precalc/julia_overview.qmd b/quarto/precalc/julia_overview.qmd index dc2e40e..6f34e92 100644 --- a/quarto/precalc/julia_overview.qmd +++ b/quarto/precalc/julia_overview.qmd @@ -97,7 +97,7 @@ julia> 2 + 2 * An IDE. For programmers, an integrated development environment is often used to manage bigger projects. `Julia` has `Juno` and `VSCode`. - * A notebook. The [Project Juptyer](https://jupyter.org/) provides a notebook interface for interacting with `Julia` and a more `IDE` style `jupyterlab` interface. A jupyter notebook has cells where commands are typed and immediately following is the printed output returned by `Julia`. The output of a cell depends on the state of the kernel when the cell is computed, not the order of the cells in the notebook. Cells have a number attached, showing the execution order. The `Juypter` notebook is used by `binder` and can be used locally through the `IJulia` package. This notebook has the ability to display many different types of outputs in addition to plain text, such as images, marked up math text, etc. + * A notebook. The [Project Juptyer](https://jupyter.org/) provides a notebook interface for interacting with `Julia` and a more `IDE` style `jupyterlab` interface. A jupyter notebook has cells where commands are typed and immediately following is the printed output returned by `Julia`. The output of a cell depends on the state of the kernel when the cell is computed, not the order of the cells in the notebook. Cells have a number attached, showing the execution order. The `Jupyter` notebook is used by `binder` and can be used locally through the `IJulia` package. This notebook has the ability to display many different types of outputs in addition to plain text, such as images, marked up math text, etc. * The [Pluto](https://github.com/fonsp/Pluto.jl) package provides a *reactive* notebook interface. Reactive means when one "cell" is modified and executed, the new values cascade to all other dependent cells which in turn are updated. This is very useful for exploring a parameter space, say. Pluto notebooks can be exported as HTML files which make them easy to read online and – by clever design – embed the `.jl` file that can run through `Pluto` if it is downloaded. diff --git a/quarto/precalc/polynomial.qmd b/quarto/precalc/polynomial.qmd index 8b09cad..e59151b 100644 --- a/quarto/precalc/polynomial.qmd +++ b/quarto/precalc/polynomial.qmd @@ -39,7 +39,7 @@ A *polynomial* is a sum of monomials. After combining terms with same powers, a $$ -a_n x^n + a_{n-1}x^{n-1} + \cdots a_1 x + a_0, \quad a_n \neq 0 +a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1 x + a_0, \quad a_n \neq 0 $$ ```{julia} @@ -343,7 +343,7 @@ pp = lambdify(p) pp(2) ``` -The `lambdify` function uses the name of the similar `SymPy` function which is named after Python's convention of calling anoynmous function "lambdas." The use above is straightforward. Only slightly more complicated is the use when there are multiple symbolic values. For example: +The `lambdify` function uses the name of the similar `SymPy` function which is named after Python's convention of calling anonymous function "lambdas." The use above is straightforward. Only slightly more complicated is the use when there are multiple symbolic values. For example: ```{julia} @@ -379,7 +379,7 @@ This graph illustrates the key features of polynomial graphs: * there may be values for `x` where the graph crosses the $x$ axis (real roots of the polynomial); - * there may be peaks and valleys (local maxima and local minima) + * there may be peaks and valleys (local maxima and local minima); * except for constant polynomials, the ultimate behaviour for large values of $|x|$ is either both sides of the graph going to positive infinity, or negative infinity, or as in this graph one to the positive infinity and one to negative infinity. In particular, there is no *horizontal asymptote*. @@ -513,7 +513,7 @@ This observation is the start of Descartes' rule of [signs](http://sepwww.stanfo Among numerous others, there are two common ways of representing a non-zero polynomial: - * expanded form, as in $a_n x^n + a_{n-1}x^{n-1} + \cdots a_1 x + a_0, a_n \neq 0$; or + * expanded form, as in $a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1 x + a_0, a_n \neq 0$; or * factored form, as in $a\cdot(x-r_1)\cdot(x-r_2)\cdots(x-r_n), a \neq 0$. diff --git a/quarto/precalc/polynomial_roots.qmd b/quarto/precalc/polynomial_roots.qmd index 8f5dd79..7d760eb 100644 --- a/quarto/precalc/polynomial_roots.qmd +++ b/quarto/precalc/polynomial_roots.qmd @@ -523,7 +523,7 @@ A polynomial with real coefficients may or may not have real roots. The followin The study of polynomial roots is an old one. In $1637$ Descartes published a *simple* method to determine an upper bound on the number of *positive* real roots of a polynomial. -> [Descartes' rule of signs](http://en.wikipedia.org/wiki/Descartes%27_rule_of_signs): if $p=a_n x^n + a_{n-1}x^{n-1} + \cdots a_1x + a_0$ then the number of positive real roots is either equal to the number of sign differences between consecutive nonzero coefficients, or is less than it by an even number. Repeated roots are counted separately. +> [Descartes' rule of signs](http://en.wikipedia.org/wiki/Descartes%27_rule_of_signs): if $p=a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1x + a_0$ then the number of positive real roots is either equal to the number of sign differences between consecutive nonzero coefficients, or is less than it by an even number. Repeated roots are counted separately. @@ -553,7 +553,7 @@ N.(solve(j ~ 0, x)) ### Cauchy's bound on the magnitude of the real roots. -Descartes' rule gives a bound on how many real roots there may be. Cauchy provided a bound on how large they can be. Assume our polynomial is monic (if not, divide by $a_n$ to make it so, as this won't effect the roots). Then any real root is no larger in absolute value than $|a_0| + |a_1| + |a_2| + \cdots + |a_n|$, (this is expressed in different ways.) +Descartes' rule gives a bound on how many real roots there may be. Cauchy provided a bound on how large they can be. Assume our polynomial is monic (if not, divide by $a_n$ to make it so, as this won't effect the roots). Then any real root is no larger in absolute value than $|a_0| + |a_1| + |a_2| + \cdots + |a_{n-1}| + 1$, (this is expressed in different ways.) To see precisely [why](https://captainblack.wordpress.com/2009/03/08/cauchys-upper-bound-for-the-roots-of-a-polynomial/) this bound works, suppose $x$ is a root with $|x| > 1$ and let $h$ be the bound. Then since $x$ is a root, we can solve $a_0 + a_1x + \cdots + 1 \cdot x^n = 0$ for $x^n$ as: diff --git a/quarto/precalc/polynomials_package.qmd b/quarto/precalc/polynomials_package.qmd index 288bd31..2cfae53 100644 --- a/quarto/precalc/polynomials_package.qmd +++ b/quarto/precalc/polynomials_package.qmd @@ -454,18 +454,18 @@ numericq(4) The identification of a collection of coefficients with a polynomial depends on an understood **basis**. A basis for the polynomials of degree $n$ or less, consists of a minimal collection of polynomials for which all the polynomials of degree $n$ or less can be expressed through a combination of sums of terms, each of which is just a coefficient times a basis member. The typical basis is the $n+1$ polynomials $1, x, x^2, \dots, x^n$. However, though every basis must have $n+1$ members, they need not be these. -A basis used by [Lagrange](https://en.wikipedia.org/wiki/Lagrange_polynomial) is the following. Let there be $n+1$ points distinct points $x_0, x_1, \dots, x_n$. For each $i$ in $0$ to $n$ define +A basis used by [Lagrange](https://en.wikipedia.org/wiki/Lagrange_polynomial) is the following. Let there be $n+1$ distinct points $x_0, x_1, \dots, x_n$. For each $i$ in $0$ to $n$ define $$ l_i(x) = \prod_{0 \leq j \leq n; j \ne i} \frac{x-x_j}{x_i - x_j} = -\frac{(x-x_1)\cdot(x-x_2)\cdot \cdots \cdot (x-x_{i-1}) \cdot (x-x_{i+1}) \cdot \cdots \cdot (x-x_n)}{(x_i-x_1)\cdot(x_i-x_2)\cdot \cdots \cdot (x_i-x_{i-1}) \cdot (x_i-x_{i+1}) \cdot \cdots \cdot (x_i-x_n)}. +\frac{(x-x_0)\cdot(x-x_1)\cdot \cdots \cdot (x-x_{i-1}) \cdot (x-x_{i+1}) \cdot \cdots \cdot (x-x_n)}{(x_i-x_0)\cdot(x_i-x_1)\cdot \cdots \cdot (x_i-x_{i-1}) \cdot (x_i-x_{i+1}) \cdot \cdots \cdot (x_i-x_n)}. $$ That is $l_i(x)$ is a product of terms like $(x-x_j)/(x_i-x_j)$ *except* when $j=i$. -What is is the value of $l_0(x_0)$? +What is the value of $l_0(x_0)$? ```{julia} @@ -578,7 +578,7 @@ choices = [ It is ``0\cdot T_0(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = 0`` """ raw""" -It is ``0\cdot T_0(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = -2 - 8\cdot x + 4\cdot x^2 + 12\cdot x^3``` +It is ``0\cdot T_0(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = -2 - 8\cdot x + 4\cdot x^2 + 12\cdot x^3`` """] radioq(choices, 3) ``` diff --git a/quarto/precalc/rational_functions.qmd b/quarto/precalc/rational_functions.qmd index fe4a6fb..f74b6af 100644 --- a/quarto/precalc/rational_functions.qmd +++ b/quarto/precalc/rational_functions.qmd @@ -159,7 +159,7 @@ Similarly, a plot over $[-100, -10]$ would show decay towards $0$, though in tha We can easily do most of this analysis without needing a computer or algebra. First, we should know the four eventual shapes of a polynomial, that the graph of $y=mx$ is a line with slope $m$, the graph of $y = c$ is a constant line at height $c$, and the graph of $y=c/x^m$, $m > 0$ will decay towards $0$ as $x \rightarrow \pm\infty$. The latter should be clear, as $x^m$ gets big, so its reciprocal goes towards $0$. -The factored form, as $p$ is presented, is a bit hard to work with, rather we use the expanded form, which we get through the `cancel` function +The factored form, as $h$ is presented, is a bit hard to work with, rather we use the expanded form, which we get through the `cancel` function ```{julia} @@ -179,7 +179,7 @@ The terms $(1 - 4/x + 5/x^2 - 2/x^3)$ and $(1 - 9/x^2)$ go towards $1$ as $x \ri Just by looking at the ratio of the two leading terms, the behaviour as $x \rightarrow \pm \infty$ can be discerned. If this ratio is of: - * the form $c x^m$ with $m > 1$ then the shape will follow the polynomial growth of of the monomial $c x^m$. + * the form $c x^m$ with $m > 1$ then the shape will follow the polynomial growth of the monomial $c x^m$. * the form $c x^m$ with $m=1$ then there will be a line with slope $c$ as a *slant asymptote*. * the form $cx^0$ with $m=0$ (or just $c$) then there will be a *horizontal asymptote* $y=c$. * the form $c/x^{m}$ with $m > 0$ then there will be a horizontal asymptote $y=0$, or the $y$ axis. @@ -266,7 +266,7 @@ $$ \frac{(x-2)^3\cdot(x-4)\cdot(x-3)}{(x-5)^4 \cdot (x-6)^2}. $$ -By looking at the powers we can see that the leading term of the numerator will the $x^5$ and the leading term of the denominator $x^6$. The ratio is $1/x^1$. As such, we expect the $x$-axis as a horizontal asymptote: +By looking at the powers we can see that the leading term of the numerator will the $x^5$ and the leading term of the denominator $x^6$. The ratio is $1/x^1$. As such, we expect the $x$-axis as a horizontal asymptote. #### Partial fractions diff --git a/quarto/precalc/trig_functions.qmd b/quarto/precalc/trig_functions.qmd index 0b4d15f..b3f32b8 100644 --- a/quarto/precalc/trig_functions.qmd +++ b/quarto/precalc/trig_functions.qmd @@ -168,7 +168,7 @@ sin(theta)^2 ``` -These values are floating point approximations, as can be seen clearly in the computation of `sin(pi/2)`, which is mathematically $0$. Symbolic math can be usedby using `PI` for `pi` if exactness matters: +These values are floating point approximations, as can be seen clearly in the computation of `cos(pi/2)`, which is mathematically $0$. Symbolic math can be used by using `PI` for `pi` if exactness matters: ```{julia} cos.([0, PI/6, PI/4, PI/3, PI/2]) @@ -732,7 +732,7 @@ $$ \cos((n+1)\theta) = 2 \cos(\theta) \cos(n\theta) - \cos((n-1)\theta). $$ -Let $T_n(x) = \cos(n \arccos(x))$. Note $T_1(x) = \cos(x)$. By identifying $\theta$ with $\arccos(x)$ for $-1 \leq x \leq 1$, we get a relation between these functions: +Let $T_n(x) = \cos(n \arccos(x))$. Note $T_1(x) = x$. By identifying $\theta$ with $\arccos(x)$ for $-1 \leq x \leq 1$, we get a relation between these functions: $$ From 1518e3b9be46a414231b5fadfe15bde5e0a0212a Mon Sep 17 00:00:00 2001 From: jverzani Date: Wed, 7 May 2025 12:05:34 -0400 Subject: [PATCH 02/11] add back file --- quarto/precalc/julia_overview.qmd | 693 ++++++++++++++++++++++++++++++ 1 file changed, 693 insertions(+) create mode 100644 quarto/precalc/julia_overview.qmd diff --git a/quarto/precalc/julia_overview.qmd b/quarto/precalc/julia_overview.qmd new file mode 100644 index 0000000..bac1c2d --- /dev/null +++ b/quarto/precalc/julia_overview.qmd @@ -0,0 +1,693 @@ +# Overview of Julia commands + + +{{< include ../_common_code.qmd >}} + +```{julia} +#| echo: false +#| results: "hidden" +using CalculusWithJulia + +nothing +``` + +The [`Julia`](http://www.julialang.org) programming language is well suited as a computer accompaniment while learning the concepts of calculus. The following overview covers the language-specific aspects of the pre-calculus part of the [Calculus with Julia](calculuswithjulia.github.io) notes. + + +## Installing `Julia` + + +`Julia` is an *open source* project which allows anyone with a supported computer to use it free of charge. + +To install locally, the [downloads](https://julialang.org/downloads/) page has directions to use the `Juliaup` utility for managing an installation. There are also links to several different binaries for manual installation. Additionally, the downloads page contains a link to a docker image. `Julia` can also be compiled from source. + + +`Julia` can also be run through the web. + +The [https://mybinder.org/](https://mybinder.org/) service in particular allows free access, though limited in terms of allotted memory and with a relatively short timeout for inactivity. + +* [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jverzani/CalculusWithJuliaBinder.jl/main?labpath=blank-notebook.ipynb) (Image without SymPy) + + +* [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jverzani/CalculusWithJuliaBinder.jl/sympy?labpath=blank-notebook.ipynb) (Image with SymPy, longer to load) + + +[Google colab](https://colab.research.google.com/) offers a free service with more computing power than `binder`, though setup is a bit more fussy. To use `colab` along with these notes, you need to execute a command that downloads `Julia` and installs the `CalculusWithJulia` package and a plotting package. (Modify the `pkg"add ..."` command to add other desired packages; update the julia version as necessary): + +``` +# Installation cell +%%capture +%%shell +if ! command -v julia 3>&1 > /dev/null +then + wget -q 'https://julialang-s3.julialang.org/bin/linux/x64/1.10/julia-1.10.2-linux-x86_64.tar.gz' \ + -O /tmp/julia.tar.gz + tar -x -f /tmp/julia.tar.gz -C /usr/local --strip-components 1 + rm /tmp/julia.tar.gz +fi +julia -e 'using Pkg; pkg"add IJulia CalculusWithJulia; precompile;"' +julia -e 'using Pkg; Pkg.add(url="https://github.com/mth229/BinderPlots.jl")' +echo 'Now change the runtime type' +``` + + (The `BinderPlots` is a light-weight, barebones, plotting package that uses `PlotlyLight` to render graphics with commands mostly following those of the `Plots` package. Though suitable for most examples herein, the `Plots` package could instead be installed) + + +After this executes (which can take quite some time, as in a few minutes) under the `Runtime` menu select `Change runtime type` and then select `Julia`. + +After that, in a cell execute these commands to load the two installed packages: + +``` +using CalculusWithJulia +using BinderPlots +``` + +As mentioned, other packages can be chosen for installation. + + + +## Interacting with `Julia` + + +At a basic level, `Julia` provides an interactive means to read commands or instructions, evaluate those commands, and then print or return those commands. At a user level, there are many different ways to interact with the reading and printing. For example: + + + * The REPL. The `Julia` terminal is the built-in means to interact with `Julia`. A `Julia` Terminal has a command prompt, after which commands are typed and then sent to be evaluated by the `enter` key. The terminal may look something like the following where `2+2` is evaluated: + + +--- + + +```{verbatim} +$ julia + _ + _ _ _(_)_ | Documentation: https://docs.julialang.org + (_) | (_) (_) | + _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. + | | | | | | |/ _` | | + | | |_| | | | (_| | | Version 1.11.1 (2024-10-16) + _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release +|__/ | + +julia> 2 + 2 +4 +``` + +--- + + + * An IDE. For programmers, an integrated development environment is often used to manage bigger projects. `Julia` has `Juno` and `VSCode`. + * A notebook. The [Project Juptyer](https://jupyter.org/) provides a notebook interface for interacting with `Julia` and a more `IDE` style `jupyterlab` interface. A jupyter notebook has cells where commands are typed and immediately following is the printed output returned by `Julia`. The output of a cell depends on the state of the kernel when the cell is computed, not the order of the cells in the notebook. Cells have a number attached, showing the execution order. The `Juypter` notebook is used by `binder` and can be used locally through the `IJulia` package. This notebook has the ability to display many different types of outputs in addition to plain text, such as images, marked up math text, etc. + * The [Pluto](https://github.com/fonsp/Pluto.jl) package provides a *reactive* notebook interface. Reactive means when one "cell" is modified and executed, the new values cascade to all other dependent cells which in turn are updated. This is very useful for exploring a parameter space, say. Pluto notebooks can be exported as HTML files which make them easy to read online and – by clever design – embed the `.jl` file that can run through `Pluto` if it is downloaded. + + +The `Pluto` interface has some idiosyncrasies that need explanation: + + + * Cells can only have one command within them. Multiple-command cells must be contained in a `begin` block or a `let` block. + * By default, the cells are *reactive*. This means when a variable in one cell is changed, then any references to that variable are also updated – like a spreadsheet. This is fantastic for updating several computations at once. However it means variable names can not be repeated within a page. Pedagogically, it is convenient to use variable names and function names (e.g., `x` and `f`) repeatedly, but this is only possible *if* they are within a `let` block or a function body. + * To not repeat names, but to be able to reference a value from cell-to-cell, some Unicode variants may be used within a page. Visually these look familiar, but typing the names requires some understanding of Unicode input. The primary usages is *bold italic* (e.g., `\bix[tab]` or `\bif[tab]`) or *bold face* (e.g. `\bfx[tab]` or `\bff[tab]`). + * The notebooks snapshot the packages they depend on, which is great for reproducibility, but may lead to older versions of the packages being silently used. + + +## Augmenting base `Julia` + + +The base `Julia` installation has many features, but leaves many others to `Julia`'s package ecosystem. These notes use packages to provide plotting, symbolic math, access to special functions, numeric routines, and more. + + +Within `Pluto`, using add-on packages is very simple, as `Pluto` downloads and installs packages when they are requested through a `using` or `import` directive. + + +--- + + +For other interfaces to `Julia` some more detail is needed. + + +The `Julia` package manager makes add-on packages very easy to install. + + +Julia comes with just a few built-in packages, one being `Pkg` which manages subsequent package installation. To add more packages, we first must *load* the `Pkg` package. This is done by issuing the following command: + + +```{julia} +using Pkg +``` + +The `using` command loads the specified package and makes all its *exported* values available for direct use. There is also the `import` command which allows the user to select which values should be imported from the package, if any, and otherwise gives access to the new functionality through the dot syntax. + + +Packages need to be loaded just once per session. + + +To use `Pkg` to "add" another package, we would have a command like: + + +```{julia} +#| eval: false +Pkg.add("CalculusWithJulia") +``` + +This command instructs `Julia` to look at its *general registry* for the `CalculusWithJulia.jl` package, download it, then install it. Once installed, a package only needs to be brought into play with the `using` or `import` commands. + + +:::{.callout-note} +## Note +In a terminal setting, there is a package mode, entered by typing `]` as the leading character and exited by entering `` at a blank line. This mode allows direct access to `Pkg` with a simpler syntax. The command above would be just `add CalculusWithJulia`. As well, when a package is not installed, calling `using SomePackage` will prompt the user if they wish to install the package in the current environment.) + +::: + +Packages can be updated through the command `Pkg.update()`, and removed with `Pkg.rm(pkgname)`. + + +By default packages are installed in a common area. It may be desirable to keep packages for projects isolated. For this the `Pkg.activate` command can be used. This feature allows a means to have reproducible environments even if `Julia` or the packages used are upgraded, possibly introducing incompatibilities. + + +For these notes, the following packages, among others, are used: + + +```{julia} +#| eval: false +Pkg.add("CalculusWithJulia") # for some convenience functions and a few packages (SpecialFunctions, ForwardDiff) +Pkg.add("Plots") # for basic plotting +Pkg.add("SymPy") # for symbolic math +Pkg.add("Roots") # for numerically solving `f(x)=0` and `f(x)=g(x)` +Pkg.add("QuadGk") # for 1-dimensional numeric integration +Pkg.add("HQuadrature") # for higher-dimensional integration +``` + +## `Julia` commands + + +In a `Jupyter` notebook or `Pluto` notebook, commands are typed into a notebook cell: + + +```{julia} +2 + 2 # use shift-enter to evaluate +``` + +Commands are executed by using `shift-enter` or a run button near the cell. + + +In `Jupyter` multiple commands per cell are allowed. In `Pluto`, a `begin` or `let` block is used to collect multiple commands into a single cell. Commands may be separated by new lines or semicolons. + + +On a given line, anything **after** a `#` is a *comment* and is not processed. + + +The results of the last command executed will be displayed in an output area. Separating values by commas allows more than one value to be displayed. Plots are displayed when the plot object is returned by the last executed command. + + +In `Jupyter`, the state of the notebook is determined by the cells executed along with their order. The state of a `Pluto` notebook is a result of all the cells in the notebook being executed. The cell order does not impact this and can be rearranged by the user. + + +## Numbers, variable types + + +`Julia` has many different number types beyond the floating point type employed by most calculators. These include + + + * Floating point numbers: `0.5` + * Integers: `2` + * Rational numbers: `1//2` + * Complex numbers `2 + 0im` + + +`Julia`'s parser finds the appropriate type for the value, when read in. The following all create the number $1$ first as an integer, then a rational, then a floating point number, again as floating point number, and finally as a complex number: + + +```{julia} +1, 1//1, 1.0, 1e0, 1 + 0im +``` + +As much as possible, operations involving certain types of numbers will produce output of a given type. For example, both of these divisions produce a floating point answer, even though mathematically, they need not: + + +```{julia} +2/1, 1/2 +``` + +Some powers with negative bases, like `(-3.0)^(1/3)`, are not defined. However, `Julia` provides the special-case function `cbrt` (and `sqrt`) for handling these. + + +Integer operations may silently overflow, producing odd answers, at first glance: + + +```{julia} +2^64 +``` + +(Though the output is predictable, knowing why requires understanding of how the hardware implements these operations.) + + +When different types of numbers are mixed, `Julia` will usually promote the values to a common type before the operation: + + +```{julia} +(2 + 1//2) + 0.5 +``` + +`Julia` will first add `2` and `1//2` promoting `2` to rational before doing so. Then add the result, `5//2` to `0.5` by promoting `5//2` to the floating point number `2.5` before proceeding. + + +`Julia` uses a special type to store a handful of irrational constants such as `pi`. The special type allows these constants to be treated without round off, until they mix with other floating point numbers. An irrational value for `e` is not exported; the `CalculusWithJulia` exports a floating point value `e=exp(1)`. + + +There are some functions that require these be explicitly promoted to floating point. This can be done by calling `float`. + + +The standard mathematical operations are implemented by `+`, `-`, `*`, `/`, `^`. Parentheses are used for grouping. + + +### Vectors + + +A vector is an indexed collection of similarly typed values. Vectors can be constructed with square brackets (syntax for concatenation): + + +```{julia} +[1, 1, 2, 3, 5, 8] +``` + +Values will be promoted to a common type (or type `Any` if none exists). For example, this vector will have type `Float64` due to the `1/3` computation: + + +```{julia} +[1, 1//2, 1/3] +``` + +(Vectors are used as a return type from some functions, as such, some familiarity is needed.) + + +Other common container types are variables of vectors (higher-dimensional arrarys, offset arrays, etc.) tuples (for heterogeneous, immutable, indexed values); named tuples (which add a name to each value in a tuple); and dictionaries (for associative relationships between a key and a value). + + +Regular arithmetic sequences can be defined by either: + + + * Range operations: `a:h:b` or `a:b` which produces a generator of values starting at `a` separated by `h` (`h` is `1` in the last form) until they reach `b`. + * The `range` function: `range(a, b, length=n)` which produces a generator of `n` values between `a` and `b`; + + +These constructs return range objects. A range object *compactly* stores the values it references. To see all the values, they can be collected with the `collect` function, though this is rarely needed in practice. + + +Random sequences are formed by `rand`, among others: + + +```{julia} +rand(3) +``` + +The call `rand()` returns a single random number (in $[0,1)$.) + + +## Variables + + +Values can be assigned variable names, with `=`. There are some variants + + +```{julia} +u = 2 +a_really_long_name = 3 +a0, b0 = 1, 2 # multiple assignment +a1 = a2 = 0 # chained assignment, sets a2 and a1 to 0 +``` + +The names can be short, as above, or more verbose. Variable names can't start with a number, but can include numbers. Variables can also include [Unicode](../misc/unicode.html) or even be an emoji. + + +```{julia} +α, β = π/3, π/4 +``` + +We can then use the variables to reference the values: + + +```{julia} +u + a_really_long_name + a0 - b0 + α +``` + +Within `Pluto`, names are idiosyncratic: within the global scope, only a single usage is possible per notebook; functions and variables can be freely renamed; structures can be redefined or renamed; ... + + +Outside of `Pluto`, names may be repurposed, even with values of different types (`Julia` is a dynamic language), save for (generic) function names, which have some special rules and can only be redefined as another method for the function. Generic functions are central to `Julia`'s design. Generic functions use a method table to dispatch on, so once a name is assigned to a generic function, it can not be used as a variable name; the reverse is also true. + + +## Functions + + +Functions in `Julia` are first-class objects. In these notes, we often pass them as arguments to other functions. There are many built-in functions and it is easy to define new functions. + + +We "call" a function by passing argument(s) to it, grouped by parentheses: + + +```{julia} +sqrt(10) +sin(pi/3) +log(5, 100) # log base 5 of 100 +``` + +Without parentheses, the name (usually) refers to a generic name and the output lists the number of available implementations (methods). + + +```{julia} +log +``` + +### Built-in functions + + +`Julia` has numerous built-in [mathematical](https://docs.julialang.org/en/v1/manual/mathematical-operations/) functions, we review a few here: + + +#### Powers logs and roots + + +Besides `^`, there are `sqrt` and `cbrt` for powers. In addition basic functions for exponential and logarithmic functions: + + +``` +sqrt, cbrt +exp +log # base e +log10, log2, # also log(b, x) +``` + +#### Trigonometric functions + + +The `6` standard trig functions are implemented; their implementation for degree arguments; their inverse functions; and the hyperbolic analogs. + + +``` +sin, cos, tan, csc, sec, cot +asin, acos, atan, acsc, asec, acot +sinh, cosh, tanh, csch, sech, coth +asinh, acosh, atanh, acsch, asech, acoth +``` + +If degrees are preferred, the following are defined to work with arguments in degrees: + + +``` +sind, cosd, tand, cscd, secd, cotd +``` + +#### Useful functions + + +Other useful and familiar functions are defined: + + + * `abs`: absolute value + * `sign`: is $\lvert x \rvert/x$ except at $x=0$, where it is $0$. + * `floor`, `ceil`: greatest integer less or least integer greater + * `max(a,b)`, `min(a,b)`: larger (or smaller) of `a` or `b` + * `maximum(xs)`, `minimum(xs)`: largest or smallest of the collection referred to by `xs` + + +--- + + +In a Pluto session, the "Live docs" area shows inline documentation for the current object. + + +For other uses of `Julia`, the built-in documentation for an object is accessible through a leading `?`, say, `?sign`. There is also the `@doc` macro, for example: + + +```{julia} +#| eval: false +@doc sign +``` + +--- + + +### User-defined functions + + +Simple mathematical functions can be defined using standard mathematical notation: + + +```{julia} +f(x) = -16x^2 + 100x + 2 +``` + +The argument `x` is passed into the body of function. + + +Other values are found from the environment where defined: + + +```{julia} +#| hold: true +a = 1 +f(x) = 2*a + x +f(3) # 2 * 1 + 3 +a = 4 +f(3) # now 2 * 4 + 3 +``` + +User-defined functions can have $0$, $1$ or more positional arguments: + + +```{julia} +area(w, h) = w*h +``` + +Julia makes different *methods* for *generic* function names, so function definitions whose argument specification is different are for different uses, even if the name is the same. This is *polymorphism*. The practical use is that it means users need only remember a much smaller set of function names, as attempts are made to give common expectations to the same name. (That is, `+` should be used only for "add" ing objects, however defined.) + + +Functions can also be defined with *keyword* arguments that may have defaults specified: + + +```{julia} +#| hold: true +f(x; m=1, b=0) = m*x + b # note ";" +f(1) # uses m=1, b=0 -> 1 * 1 + 0 +f(1, m=10) # uses m=10, b=0 -> 10 * 1 + 0 +f(1, m=10, b=5) # uses m=10, b=5 -> 10 * 1 + 5 +``` + +Keyword arguments are not considered for dispatch. + +Longer functions can be defined using the `function` keyword, the last command executed is returned: + + +```{julia} +function f(x) + y = x^2 + z = y - 3 + z +end +``` + +Functions without names, *anonymous functions*, are made with the `->` syntax as in: + + +```{julia} +x -> cos(x)^2 - cos(2x) +``` + +These are useful when passing a function to another function or when writing a function that *returns* a function. + + +## Conditional statements + + +`Julia` provides the traditional `if-else-end` statements, but more conveniently has a `ternary` operator for the simplest case: + + +```{julia} +our_abs(x) = (x < 0) ? -x : x +``` + +## Looping + + +Iterating over a collection can be done with the traditional `for` loop. However, there are list comprehensions to mimic the definition of a set: + + +```{julia} +[x^2 for x in 1:10] +``` + +Comprehensions can be filtered through the `if` keyword + + +```{julia} +[x^2 for x in 1:10 if iseven(x)] +``` + +This is more efficient than creating the collection then filtering, as is done with: + + +```{julia} +filter(iseven, [x^2 for x in 1:10]) +``` + +## Broadcasting, mapping + + +A function can be applied to each element of a vector through mapping or broadcasting. The latter is implemented in a succinct notation. Calling a function with a "." before its opening "(" will apply the function to each individual value in the argument: + + +```{julia} +xs = [1,2,3,4,5] +sin.(xs) # gives back [sin(1), sin(2), sin(3), sin(4), sin(5)] +``` + +For "infix" operators, the dot precedes the operator, as in this example instructing pointwise multiplication of each element in `xs`: + + +```{julia} +xs .* xs +``` + +Alternatively, the more traditional `map` can be used: + + +```{julia} +map(sin, xs) +``` + +## Plotting + + +Plotting is *not* built-in to `Julia`, rather added through add-on packages. `Julia`'s `Plots` package is an interface to several plotting packages. We mention `plotly` (built-in) for web based graphics, `pyplot`, and `gr` (also built into `Plots`) for other graphics. + + +We must load `Plots` before we can plot (and it must be installed before we can load it): + + +```{julia} +using Plots +plotly() # optionally change the backend from the default +``` + +With `Plots` loaded, we can plot a function by passing the function object by name to `plot`, specifying the range of `x` values to show, as follows: + + +```{julia} +plot(sin, 0, 2pi) # plot a function - by name - over an interval [a,b] +``` + +::: {.callout-note} +This is in the form of **the** basic pattern employed: `verb(function_object, arguments...)`. The verb in this example is `plot`, the object `sin`, the arguments `0, 2pi` to specify `[a,b]` domain to plot over. +::: + +Plotting more than one function over `[a,b]` is achieved through the `plot!` function, which modifies the existing plot (`plot` creates a new one) by adding a new layer: + + +```{julia} +plot(sin, 0, 2pi) +plot!(cos, 0, 2pi) +plot!(zero, 0, 2pi) # add the line y=0 +``` + +(There are alternatives to plot functions or other traces all at once.) + +Individual points are added with `scatter` or `scatter!`: + + +```{julia} +plot(sin, 0, 2pi, legend=false) +plot!(cos, 0, 2pi) +scatter!([pi/4, pi+pi/4], [sin(pi/4), sin(pi + pi/4)]) +``` + +(The extra argument `legend=false` suppresses the automatic legend drawing. There are many other useful keyword arguments to adjust attributes of a trace of a graphic. For example, passing `markersize=10` to the `scatter!` command would draw the points larger than the default.) + + +Plotting an *anonymous* function is a bit more immediate than the two-step approach of defining a named function then calling `plot` with this as an argument: + + +```{julia} +plot( x -> exp(-x/pi) * sin(x), 0, 2pi) +``` + +The `scatter!` function used above takes two vectors of values to describe the points to plot, one for the $x$ values and one for the matching $y$ values. The `plot` function can also produce plots with this interface. For example, here we use a comprehension to produce `y` values from the specified `x` values: + + +```{julia} +#| hold: true +xs = range(0, 2pi, length=251) +ys = [sin(2x) + sin(3x) + sin(4x) for x in xs] +plot(xs, ys) +``` + +There are different plotting interfaces. Though not shown, all of these `plot` commands produce a plot of `f`, though with minor differences: + +```{julia} +#| eval: false +xs = range(a, b, length=251) +ys = f.(xs) +plot(f, a, b) # recipe for a function +plot(xs, f) # alternate recipe +plot(xs, ys) # plot coordinates as two vectors +plot([(x,f(x)) for x in xs]) # plot a vector o points +``` + +The choice should depend on convenience. + +## Equations + + +Notation for `Julia` and math is *similar* for functions - but not for equations. In math, an equation might look like: + + +$$ +x^2 + y^2 = 3 +$$ + +In `Julia` the equals sign is **only** for *assignment* and *mutation*. The *left-hand* side of an equals sign in `Julia` is reserved for a) variable assignment; b) function definition (via `f(x) = ...`); c) indexed mutation of a vector or array; d) mutation of fields in a structure. (Vectors are indexed by a number allowing retrieval and mutation of the stored value in the container. The notation mentioned here would be `xs[2] = 3` to mutate the 2nd element of `xs` to the value `3`. + + +## Symbolic math + + +Symbolic math is available through an add-on package `SymPy` (among others). Once loaded, symbolic variables in `SymPy` are created with the macro `@syms`: + + +```{julia} +using SymPy +``` + +```{julia} +@syms x a b c +``` + +(A macro rewrites values into other commands before they are interpreted. Macros are prefixed with the `@` sign. In this use, the "macro" `@syms` translates `x a b c` into a command involving `SymPy`s `symbols` function.) + + +Symbolic expressions - unlike numeric expressions - are not immediately evaluated, though they may be simplified: + + +```{julia} +p = a*x^2 + b*x + c +``` + +To substitute a value, we can use `Julia`'s `pair` notation (`variable=>value`): + + +```{julia} +p(x=>2), p(x=>2, a=>3, b=>4, c=>1) +``` + +This is convenient notation for calling the `subs` function for `SymPy`. + + +SymPy expressions of a single free variable can be plotted directly: + + +```{julia} +plot(64 - (1/2)*32 * x^2, 0, 2) +``` + + * SymPy has functions for manipulating expressions: `simplify`, `expand`, `together`, `factor`, `cancel`, `apart`, $...$ + * SymPy has functions for basic math: `factor`, `roots`, `solve`, `solveset`, $\dots$ + * SymPy has functions for calculus: `limit`, `diff`, `integrate`, $\dots$ From f7b7df3586bf20a357bbf9b4d29eec48dae23390 Mon Sep 17 00:00:00 2001 From: Fang Liu Date: Fri, 9 May 2025 16:54:52 +0800 Subject: [PATCH 03/11] some typos --- quarto/limits/intermediate_value_theorem.qmd | 2 +- quarto/limits/limits.qmd | 4 ++-- quarto/limits/limits_extensions.qmd | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/quarto/limits/intermediate_value_theorem.qmd b/quarto/limits/intermediate_value_theorem.qmd index 190e1ed..ab07071 100644 --- a/quarto/limits/intermediate_value_theorem.qmd +++ b/quarto/limits/intermediate_value_theorem.qmd @@ -1028,7 +1028,7 @@ nothing ![Trajectories of potential cannonball fires with air-resistance included. (http://ej.iop.org/images/0143-0807/33/1/149/Full/ejp405251f1_online.jpg) ](figures/cannonball.jpg){width=50%} -In 1638, according to Amir D. [Aczel](http://books.google.com/books?id=kvGt2OlUnQ4C&pg=PA28&lpg=PA28&dq=mersenne+cannon+ball+tests&source=bl&ots=wEUd7e0jFk&sig=LpFuPoUvODzJdaoug4CJsIGZZHw&hl=en&sa=X&ei=KUGcU6OAKJCfyASnioCoBA&ved=0CCEQ6AEwAA#v=onepage&q=mersenne%20cannon%20ball%20tests&f=false), an experiment was performed in the French Countryside. A monk, Marin Mersenne, launched a cannonball straight up into the air in an attempt to help Descartes prove facts about the rotation of the earth. Though the experiment was not successful, Mersenne later observed that the time for the cannonball to go up was greater than the time to come down. ["Vertical Projection in a Resisting Medium: Reflections on Observations of Mersenne".](http://www.maa.org/publications/periodicals/american-mathematical-monthly/american-mathematical-monthly-contents-junejuly-2014) +In 1638, according to Amir D. [Aczel](http://books.google.com/books?id=kvGt2OlUnQ4C&pg=PA28&lpg=PA28&dq=mersenne+cannon+ball+tests&source=bl&ots=wEUd7e0jFk&sig=LpFuPoUvODzJdaoug4CJsIGZZHw&hl=en&sa=X&ei=KUGcU6OAKJCfyASnioCoBA&ved=0CCEQ6AEwAA#v=onepage&q=mersenne%20cannon%20ball%20tests&f=false), an experiment was performed in the French Countryside. A monk, Marin Mersenne, launched a cannonball straight up into the air in an attempt to help Descartes prove facts about the rotation of the earth. Though the experiment was not successful, Mersenne later observed that the time for the cannonball to go up was less than the time to come down. ["Vertical Projection in a Resisting Medium: Reflections on Observations of Mersenne".](http://www.maa.org/publications/periodicals/american-mathematical-monthly/american-mathematical-monthly-contents-junejuly-2014) This isn't the case for simple ballistic motion where the time to go up is equal to the time to come down. We can "prove" this numerically. For simple ballistic motion: diff --git a/quarto/limits/limits.qmd b/quarto/limits/limits.qmd index ba2221b..4f21c49 100644 --- a/quarto/limits/limits.qmd +++ b/quarto/limits/limits.qmd @@ -73,7 +73,7 @@ gif(anim, imgfile, fps = 1) caption = L""" -The first triangle has area $1/2$, the second has area $1/8$, then $2$ have area $(1/8)^2$, $4$ have area $(1/8)^3$, ... +The first triangle has area $1/2$, the second has area $1/8$, then $3$ have area $(1/8)^2$, $4$ have area $(1/8)^3$, ... With some algebra, the total area then should be $1/2 \cdot (1 + (1/4) + (1/4)^2 + \cdots) = 2/3$. """ @@ -161,7 +161,7 @@ for (x, y, n, col) ∈ zip(xs, ys, ns, (blue, green, purple, red)) end caption = L""" -The ratio of the circumference of a circle to its diameter, $\pi$, can be approximated from above and below by computing the perimeters of the inscribed $n$-gons. Archimedes computed the perimeters for $n$ being $12$, $24$, $48$, and $96$ to determine that $3~1/7 \leq \pi \leq 3~10/71$. +The ratio of the circumference of a circle to its diameter, $\pi$, can be approximated from above and below by computing the perimeters of the inscribed $n$-gons. Archimedes computed the perimeters for $n$ being $12$, $24$, $48$, and $96$ to determine that $3~10/71 \leq \pi \leq 3~1/7$. """ plotly() ImageFile(p, caption) diff --git a/quarto/limits/limits_extensions.qmd b/quarto/limits/limits_extensions.qmd index 2c46b2b..1ac9858 100644 --- a/quarto/limits/limits_extensions.qmd +++ b/quarto/limits/limits_extensions.qmd @@ -876,7 +876,7 @@ numericq(-1) ###### Question -As mentioned, for limits that depend on specific values of parameters `SymPy` may have issues. As an example, `SymPy` has an issue with the following limit, whose answer depends on the value of $k$" +As mentioned, for limits that depend on specific values of parameters `SymPy` may have issues. As an example, `SymPy` has an issue with the following limit, whose answer depends on the value of "$k$" $$ @@ -1017,7 +1017,7 @@ radioq(choices, answ, keep_order=true) Suppose a sequence of points $x_n$ converges to $a$ in the limiting sense. For a function $f(x)$, the sequence of points $f(x_n)$ may or may not converge. One alternative definition of a [limit](https://en.wikipedia.org/wiki/Limit_of_a_function#In_terms_of_sequences) due to Heine is that $\lim_{x \rightarrow a}f(x) = L$ if *and* only if **all** sequences $x_n \rightarrow a$ have $f(x_n) \rightarrow L$. -Consider the function $f(x) = \sin(1/x)$, $a=0$, and the two sequences implicitly defined by $1/x_n = \pi/2 + n \cdot (2\pi)$ and $y_n = 3\pi/2 + n \cdot(2\pi)$, $n = 0, 1, 2, \dots$. +Consider the function $f(x) = \sin(1/x)$, $a=0$, and the two sequences implicitly defined by $1/x_n = \pi/2 + n \cdot (2\pi)$ and $1/y_n = 3\pi/2 + n \cdot(2\pi)$, $n = 0, 1, 2, \dots$. What is $\lim_{x_n \rightarrow 0} f(x_n)$? From efd69d2fa1d941aa94da0746608fd105435bb596 Mon Sep 17 00:00:00 2001 From: jverzani Date: Sat, 10 May 2025 15:44:25 -0400 Subject: [PATCH 04/11] updates --- quarto/ODEs/Project.toml | 5 +++++ quarto/_common_code.qmd | 2 +- quarto/_quarto.yml | 2 +- quarto/differentiable_vector_calculus/Project.toml | 5 +++++ quarto/limits/Project.toml | 5 +++++ quarto/precalc/Project.toml | 5 +++++ quarto/precalc/numbers_types.qmd | 2 +- 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/quarto/ODEs/Project.toml b/quarto/ODEs/Project.toml index ce11bd1..b8ebcfe 100644 --- a/quarto/ODEs/Project.toml +++ b/quarto/ODEs/Project.toml @@ -1,11 +1,16 @@ [deps] CalculusWithJulia = "a2e0e22d-7d4c-5312-9169-8b992201a882" IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" +LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" MonteCarloMeasurements = "0987c9cc-fe09-11e8-30f0-b96dd679fdca" +Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" +Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d" diff --git a/quarto/_common_code.qmd b/quarto/_common_code.qmd index fcc1575..84bcf2c 100644 --- a/quarto/_common_code.qmd +++ b/quarto/_common_code.qmd @@ -47,7 +47,7 @@ end import Base64: base64encode import Markdown using Mustache -using Tables +usingTables # q and L using LaTeXStrings diff --git a/quarto/_quarto.yml b/quarto/_quarto.yml index b41a532..b1dd890 100644 --- a/quarto/_quarto.yml +++ b/quarto/_quarto.yml @@ -1,5 +1,5 @@ version: "0.23" -engine: julia +engines: ['julia'] project: type: book diff --git a/quarto/differentiable_vector_calculus/Project.toml b/quarto/differentiable_vector_calculus/Project.toml index ebc683f..ba958a3 100644 --- a/quarto/differentiable_vector_calculus/Project.toml +++ b/quarto/differentiable_vector_calculus/Project.toml @@ -7,11 +7,16 @@ DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" ScatteredInterpolation = "3f865c0f-6dca-5f4d-999b-29fe1e7e3c92" SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" +Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d" diff --git a/quarto/limits/Project.toml b/quarto/limits/Project.toml index 02eca3c..86b9abe 100644 --- a/quarto/limits/Project.toml +++ b/quarto/limits/Project.toml @@ -2,7 +2,12 @@ CalculusWithJulia = "a2e0e22d-7d4c-5312-9169-8b992201a882" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" +LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4" Richardson = "708f8203-808e-40c0-ba2d-98a6953ed40d" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" +Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d" diff --git a/quarto/precalc/Project.toml b/quarto/precalc/Project.toml index fb5fac9..4c8c9ae 100644 --- a/quarto/precalc/Project.toml +++ b/quarto/precalc/Project.toml @@ -4,12 +4,17 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45" Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae" +QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4" RealPolynomialRoots = "87be438c-38ae-47c4-9398-763eabe5c3be" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" +Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d" diff --git a/quarto/precalc/numbers_types.qmd b/quarto/precalc/numbers_types.qmd index e0f67d2..929797a 100644 --- a/quarto/precalc/numbers_types.qmd +++ b/quarto/precalc/numbers_types.qmd @@ -26,7 +26,7 @@ On top of these, we have special subsets, such as the natural numbers $\{1, 2, \ Mathematically, these number systems are naturally nested within each other as integers are rational numbers which are real numbers, which can be viewed as part of the complex numbers. -Calculators typically have just one type of number - floating point values. These model the real numbers. `Julia`, on the other hand, has a rich type system, and within that has many different number types. There are types that model each of the four main systems above, and within each type, specializations for how these values are stored. +Calculators typically have just one type of number - floating point values. These model the real numbers. `Julia`, on the other hand, has a rich type system, and within that has serveral different number types. There are types that model each of the four main systems above, and within each type, specializations for how these values are stored. Most of the details will not be of interest to all, and will be described later. From 4d0a9e9a7296399cddde73b17e71924ac653ecc5 Mon Sep 17 00:00:00 2001 From: Fang Liu Date: Fri, 23 May 2025 16:20:13 +0800 Subject: [PATCH 05/11] some typos. --- quarto/derivatives/curve_sketching.qmd | 6 ++-- quarto/derivatives/derivatives.qmd | 6 ++-- .../derivatives/first_second_derivatives.qmd | 30 ++++++++----------- .../derivatives/implicit_differentiation.qmd | 6 ++-- quarto/derivatives/lhospitals_rule.qmd | 4 +-- quarto/derivatives/linearization.qmd | 8 ++--- quarto/derivatives/mean_value_theorem.qmd | 2 +- quarto/derivatives/newtons_method.qmd | 14 ++++----- quarto/derivatives/optimization.qmd | 24 +++++++-------- .../derivatives/taylor_series_polynomials.qmd | 14 ++++----- 10 files changed, 54 insertions(+), 60 deletions(-) diff --git a/quarto/derivatives/curve_sketching.qmd b/quarto/derivatives/curve_sketching.qmd index 48f8b1f..3c99eed 100644 --- a/quarto/derivatives/curve_sketching.qmd +++ b/quarto/derivatives/curve_sketching.qmd @@ -195,7 +195,7 @@ To identify how wide a viewing window should be, for the rational function the a ```{julia} cps = find_zeros(f', -10, 10) -poss_ips = find_zero(f'', (-10, 10)) +poss_ips = find_zeros(f'', (-10, 10)) extrema(union(cps, poss_ips)) ``` @@ -340,7 +340,7 @@ radioq(choices, answ) ###### Question -Consider the function $p(x) = x + 2x^3 + 3x^3 + 4x^4 + 5x^5 +6x^6$. Which interval shows more than a $U$-shaped graph that dominates for large $x$ due to the leading term being $6x^6$? +Consider the function $p(x) = x + 2x^2 + 3x^3 + 4x^4 + 5x^5 +6x^6$. Which interval shows more than a $U$-shaped graph that dominates for large $x$ due to the leading term being $6x^6$? (Find an interval that contains the zeros, critical points, and inflection points.) @@ -494,7 +494,7 @@ Does a plot over $[0,50]$ show qualitatively similar behaviour? ```{julia} #| hold: true #| echo: false -yesnoq(true) +yesnoq("no") ``` Exponential growth has $P''(t) = P_0 a^t \log(a)^2 > 0$, so has no inflection point. By plotting over a sufficiently wide interval, can you answer: does the logistic growth model have an inflection point? diff --git a/quarto/derivatives/derivatives.qmd b/quarto/derivatives/derivatives.qmd index d92e893..95e3798 100644 --- a/quarto/derivatives/derivatives.qmd +++ b/quarto/derivatives/derivatives.qmd @@ -432,7 +432,7 @@ $$ \frac{\log(x+h) - \log(x)}{h} = \frac{1}{h}\log(\frac{x+h}{x}) = \log((1+h/x)^{1/h}). $$ -As noted earlier, Cauchy saw the limit as $u$ goes to $0$ of $f(u) = (1 + u)^{1/u}$ is $e$. Re-expressing the above we can get $1/h \cdot \log(f(h/x))$. The limit as $h$ goes to $0$ of this is found from the composition rules for limits: as $\lim_{h \rightarrow 0} f(h/x) = e^{1/x}$, and since $\log(x)$ is continuous at $e^{1/x}$ we get this expression has a limit of $1/x$. +As noted earlier, Cauchy saw the limit as $u$ goes to $0$ of $f(u) = (1 + u)^{1/u}$ is $e$. Re-expressing the above we can get $1/x \cdot \log(f(h/x))$. The limit as $h$ goes to $0$ of this is found from the composition rules for limits: as $\lim_{h \rightarrow 0} f(h/x) = e$, and since $\log(x)$ is continuous at $e$ we get this expression has a limit of $1/x$. We verify through: @@ -775,7 +775,7 @@ f'(\square) &= 2(\square) & g'(x) &= \frac{1}{2}x^{-1/2} $$ -We use $\square$ for the argument of `f'` to emphasize that $g(x)$ is the needed value, not just $x$: +We use $\square$ for the argument of $f'$ to emphasize that $g(x)$ is the needed value, not just $x$: $$ @@ -1651,7 +1651,7 @@ $$ \frac{d(f\circ g)}{dx}\mid_{x=1} &= \lim_{h\rightarrow 0} \frac{f(g(1) + g'(1)h)-f(g(1))}{h}\\ &= \lim_{h\rightarrow 0} \frac{f(g(1) + g'(1)h)-f(g(1))}{g'(1)h} \cdot g'(1)\\ -&= \lim_{h\rightarrow 0} (f\circ g)'(g(1)) \cdot g'(1). +&= \lim_{h\rightarrow 0} f'(g(1)) \cdot g'(1). \end{align*} $$ diff --git a/quarto/derivatives/first_second_derivatives.qmd b/quarto/derivatives/first_second_derivatives.qmd index 411d021..4e8f857 100644 --- a/quarto/derivatives/first_second_derivatives.qmd +++ b/quarto/derivatives/first_second_derivatives.qmd @@ -243,7 +243,7 @@ g(x) = sqrt(abs(x^2 - 1)) cps = find_zeros(g', -2, 2) ``` -We see the three values $-1$, $0$, $1$ that correspond to the two zeros and the relative minimum of $x^2 - 1$. We could graph things, but instead we characterize these values using a sign chart. A piecewise continuous function can only change sign when it crosses $0$ or jumps over $0$. The derivative will be continuous, except possibly at the three values above, so is piecewise continuous. +We see the three values $-1$, $0$, $1$ that correspond to the two zeros and the relative maximum of $x^2 - 1$. We could graph things, but instead we characterize these values using a sign chart. A piecewise continuous function can only change sign when it crosses $0$ or jumps over $0$. The derivative will be continuous, except possibly at the three values above, so is piecewise continuous. A sign chart picks convenient values between crossing points to test if the function is positive or negative over those intervals. When computing by hand, these would ideally be values for which the function is easily computed. On the computer, this isn't a concern; below the midpoint is chosen: @@ -328,7 +328,7 @@ At $x=0$ we have to the left and right signs found by fp(-pi/2), fp(pi/2) ``` -Both are negative. The derivative does not change sign at $0$, so the critical point is neither a relative minimum or maximum. +Both are negative. The derivative does not change sign at $0$, so the critical point is neither a relative minimum nor maximum. What about at $2\pi$? We do something similar: @@ -338,7 +338,7 @@ What about at $2\pi$? We do something similar: fp(2pi - pi/2), fp(2pi + pi/2) ``` -Again, both negative. The function $f(x)$ is just decreasing near $2\pi$, so again the critical point is neither a relative minimum or maximum. +Again, both negative. The function $f(x)$ is just decreasing near $2\pi$, so again the critical point is neither a relative minimum nor maximum. A graph verifies this: @@ -454,7 +454,7 @@ We won't work with these definitions in this section, rather we will characteriz -A proof of this makes use of the same trick used to establish the mean value theorem from Rolle's theorem. Assume $f'$ is increasing and let $g(x) = f(x) - (f(a) + M \cdot (x-a))$, where $M$ is the slope of the secant line between $a$ and $b$. By construction $g(a) = g(b) = 0$. If $f'(x)$ is increasing, then so is $g'(x) = f'(x) + M$. By its definition above, showing $f$ is concave up is the same as showing $g(x) \leq 0$. Suppose to the contrary that there is a value where $g(x) > 0$ in $[a,b]$. We show this can't be. Assuming $g'(x)$ always exists, after some work, Rolle's theorem will ensure there is a value where $g'(c) = 0$ and $(c,g(c))$ is a relative maximum, and as we know there is at least one positive value, it must be $g(c) > 0$. The first derivative test then ensures that $g'(x)$ will increase to the left of $c$ and decrease to the right of $c$, since $c$ is at a critical point and not an endpoint. But this can't happen as $g'(x)$ is assumed to be increasing on the interval. +A proof of this makes use of the same trick used to establish the mean value theorem from Rolle's theorem. Assume $f'$ is increasing and let $g(x) = f(x) - (f(a) + M \cdot (x-a))$, where $M$ is the slope of the secant line between $a$ and $b$. By construction $g(a) = g(b) = 0$. If $f'(x)$ is increasing, then so is $g'(x) = f'(x) + M$. By its definition above, showing $f$ is concave up is the same as showing $g(x) \leq 0$. Suppose to the contrary that there is a value where $g(x) > 0$ in $[a,b]$. We show this can't be. Assuming $g'(x)$ always exists, after some work, Rolle's theorem will ensure there is a value where $g'(c) = 0$ and $(c,g(c))$ is a relative maximum, and as we know there is at least one positive value, it must be $g(c) > 0$. The first derivative test then ensures that $g'(x)$ will be positive to the left of $c$ and negative to the right of $c$, since $c$ is at a critical point and not an endpoint. But this can't happen as $g'(x)$ is assumed to be increasing on the interval. The relationship between increasing functions and their derivatives – if $f'(x) > 0$ on $I$, then $f$ is increasing on $I$ – gives this second characterization of concavity when the second derivative exists: @@ -503,8 +503,8 @@ Concave up functions are "opening" up, and often clearly $U$-shaped, though that If $c$ is a critical point of $f(x)$ with $f''(c)$ existing in a neighborhood of $c$, then - * $f$ will have a relative maximum at the critical point $c$ if $f''(c) > 0$, - * $f$ will have a relative minimum at the critical point $c$ if $f''(c) < 0$, and + * $f$ will have a relative minimum at the critical point $c$ if $f''(c) > 0$, + * $f$ will have a relative maximum at the critical point $c$ if $f''(c) < 0$, and * *if* $f''(c) = 0$ the test is *inconclusive*. ::: @@ -799,6 +799,8 @@ scatter!(ips, ex.(ips), marker=(5, :brown3, :star5)) The black circle denotes what? ```{julia} +#| hold: true +#| echo: false choices = [raw"A zero of $f$", raw"A critical point of $f$", raw"An inflection point of $f$"] @@ -806,21 +808,11 @@ answ = 1 radioq(choices, answ) ``` - -The black circle denotes what? - -```{julia} -choices = [raw"A zero of $f$", - raw"A critical point of $f$", - raw"An inflection point of $f$"] -answ = 1 -radioq(choices, answ) -``` - - The green diamond denotes what? ```{julia} +#| hold: true +#| echo: false choices = [raw"A zero of $f$", raw"A critical point of $f$", raw"An inflection point of $f$"] @@ -832,6 +824,8 @@ radioq(choices, answ) The red stars denotes what? ```{julia} +#| hold: true +#| echo: false choices = [raw"Zeros of $f$", raw"Critical points of $f$", raw"Inflection points of $f$"] diff --git a/quarto/derivatives/implicit_differentiation.qmd b/quarto/derivatives/implicit_differentiation.qmd index 9406187..b5514fa 100644 --- a/quarto/derivatives/implicit_differentiation.qmd +++ b/quarto/derivatives/implicit_differentiation.qmd @@ -416,7 +416,7 @@ $$ 6x - (6y \frac{dy}{dx} \cdot \frac{dy}{dx} + 3y^2 \frac{d^2y}{dx^2}) = 0. $$ -Again, if must be that $d^2y/dx^2$ appears as a linear factor, so we can solve for it: +Again, it must be that $d^2y/dx^2$ appears as a linear factor, so we can solve for it: $$ @@ -456,7 +456,7 @@ eqn = K(x,y) eqn1 = eqn(y => u(x)) dydx = solve(diff(eqn1,x), diff(u(x), x))[1] # 1 solution d2ydx2 = solve(diff(eqn1, x, 2), diff(u(x),x, 2))[1] # 1 solution -eqn2 = d2ydx2(diff(u(x), x) => dydx, u(x) => y) +eqn2 = subs(d2ydx2, diff(u(x), x) => dydx, u(x) => y) simplify(eqn2) ``` @@ -637,7 +637,7 @@ Okay, now we need to put this value back into our expression for the `x` value a ```{julia} -xstar = N(cps[2](y => ystar, a =>3, b => 3, L => 3)) +xstar = N(cps[2](y => ystar, a =>3, b => 3)) ``` Our minimum is at `(xstar, ystar)`, as this graphic shows: diff --git a/quarto/derivatives/lhospitals_rule.qmd b/quarto/derivatives/lhospitals_rule.qmd index 05d0fb6..611f4da 100644 --- a/quarto/derivatives/lhospitals_rule.qmd +++ b/quarto/derivatives/lhospitals_rule.qmd @@ -115,7 +115,7 @@ $$ \lim_{x \rightarrow 0} \frac{e^x - e^{-x}}{x}. $$ -It too is of the indeterminate form $0/0$. The derivative of the top is $e^x + e^{-x}$, which is $2$ when $x=0$, so the ratio of $f'(0)/g'(0)$ is seen to be $2$ By continuity, the limit of the ratio of the derivatives is $2$. Then by L'Hospital's rule, the limit above is $2$. +It too is of the indeterminate form $0/0$. The derivative of the top is $e^x + e^{-x}$, which is $2$ when $x=0$, so the ratio of $f'(0)/g'(0)$ is seen to be $2$. By continuity, the limit of the ratio of the derivatives is $2$. Then by L'Hospital's rule, the limit above is $2$. * Sometimes, L'Hospital's rule must be applied twice. Consider this limit: @@ -820,7 +820,7 @@ $$ #| hold: true #| echo: false choices = [ -"``e^{-2/\\pi}``", +"``e^{2/\\pi}``", "``{2\\pi}``", "``1``", "``0``", diff --git a/quarto/derivatives/linearization.qmd b/quarto/derivatives/linearization.qmd index 507df2e..9924919 100644 --- a/quarto/derivatives/linearization.qmd +++ b/quarto/derivatives/linearization.qmd @@ -642,7 +642,7 @@ x = Dual(0, 1) @code_lowered sin(x) ``` -This output of `@code_lowered` can be confusing, but this simple case needn't be. Working from the end we see an assignment to a variable named `%7` of `Dual(%3, %6)`. The value of `%3` is `sin(x)` where `x` is the value `0` above. The value of `%6` is `cos(x)` *times* the value `1` above (the `xp`), which reflects the *chain* rule being used. (The derivative of `sin(u)` is `cos(u)*du`.) So this dual number encodes both the function value at `0` and the derivative of the function at `0`.) +This output of `@code_lowered` can be confusing, but this simple case needn't be. Working from the end we see an assignment to a variable named `%3` of `Dual(%6, %12)`. The value of `%6` is `sin(x)` where `x` is the value `0` above. The value of `%12` is `cos(x)` *times* the value `1` above (the `xp`), which reflects the *chain* rule being used. (The derivative of `sin(u)` is `cos(u)*du`.) So this dual number encodes both the function value at `0` and the derivative of the function at `0`. Similarly, we can see what happens to `log(x)` at `1` (encoded by `Dual(1,1)`): @@ -654,14 +654,14 @@ x = Dual(1, 1) @code_lowered log(x) ``` -We can see the derivative again reflects the chain rule, it being given by `1/x * xp` where `xp` acts like `dx` (from assignments `%5` and `%4`). Comparing the two outputs, we see only the assignment to `%5` differs, it reflecting the derivative of the function. +We can see the derivative again reflects the chain rule, it being given by `1/x * xp` where `xp` acts like `dx` (from assignments `%9` and `%8`). Comparing the two outputs, we see only the assignment to `%9` differs, it reflecting the derivative of the function. ## Curvature The curvature of a function will be a topic in a later section on differentiable vector calculus, but the concept of linearization can be used to give an earlier introduction. -The tangent line linearizes the function, it begin the best linear approximation to the graph of the function at the point. The slope of the tangent line is the limi of the slopes of different secant lines. Consider now, the orthogonal concept, the *normal line* at a point. This is a line perpendicular to the tangent line that goes through the point on the curve. +The tangent line linearizes the function, it begin the best linear approximation to the graph of the function at the point. The slope of the tangent line is the limit of the slopes of different secant lines. Consider now, the orthogonal concept, the *normal line* at a point. This is a line perpendicular to the tangent line that goes through the point on the curve. At a point $(c,f(c))$ the slope of the normal line is $-1/f'(c)$. @@ -680,7 +680,7 @@ Rearranging, we have $$ \begin{align*} --f'(c)(y-f(c) &= x-c\\ +-f'(c)(y-f(c)) &= x-c\\ -f'(c+h)(y-f(c+h)) &= x-(c+h) \end{align*} $$ diff --git a/quarto/derivatives/mean_value_theorem.qmd b/quarto/derivatives/mean_value_theorem.qmd index ba5effc..286e52a 100644 --- a/quarto/derivatives/mean_value_theorem.qmd +++ b/quarto/derivatives/mean_value_theorem.qmd @@ -330,7 +330,7 @@ Let $f(x)$ be differentiable on $(a,b)$ and continuous on $[a,b]$. Then there ex This says for any secant line between $a < b$ there will be a parallel tangent line at some $c$ with $a < c < b$ (all provided $f$ is differentiable on $(a,b)$ and continuous on $[a,b]$). -Figure @fig-mean-value-theorem illustrates the theorem. The orange line is the secant line. A parallel line tangent to the graph is guaranteed by the mean value theorem. In this figure, there are two such lines, rendered using red. +Figure @fig-mean-value-theorem illustrates the theorem. The blue line is the secant line. A parallel line tangent to the graph is guaranteed by the mean value theorem. In this figure, there are two such lines, rendered using brown. ```{julia} diff --git a/quarto/derivatives/newtons_method.qmd b/quarto/derivatives/newtons_method.qmd index 3ba3af6..9b978b7 100644 --- a/quarto/derivatives/newtons_method.qmd +++ b/quarto/derivatives/newtons_method.qmd @@ -69,7 +69,7 @@ x₃ = (babylon ∘ babylon ∘ babylon)(2//1) x₃, x₃^2.0 ``` -This is now accurate to the sixth decimal point. That is about as far as we, or the Bablyonians, would want to go by hand. Using rational numbers quickly grows out of hand. The next step shows the explosion. +This is now accurate to the sixth decimal point. That is about as far as we, or the Babylonians, would want to go by hand. Using rational numbers quickly grows out of hand. The next step shows the explosion. ```{julia} @@ -212,7 +212,7 @@ In practice, the algorithm is implemented not by repeating the update step a fix Newton looked at this same example in 1699 (B.T. Polyak, *Newton's method and its use in optimization*, European Journal of Operational Research. 02/2007; 181(3):1086-1096.; and Deuflhard *Newton Methods for Nonlinear Problems: Affine Invariance and Adaptive Algorithms*) though his technique was slightly different as he did not use the derivative, *per se*, but rather an approximation based on the fact that his function was a polynomial. -We can read that he guessed the answer was ``2 + p``, as there is a sign change between $2$ and $3$. Newton put this guess into the polynomial to get after simplification ``p^3 + 6p^2 + 10p - 1``. This has an **approximate** zero found by solving the linear part ``10p-1 = 0``. Taking ``p = 0.1`` he then can say the answer looks like ``2 + p + q`` and repeat to get ``q^3 + 6.3\cdot q^2 + 11.23 \cdot q + 0.061 = 0``. Again taking just the linear part estimates `q = 0.005431...`. After two steps the estimate is `2.105431...`. This can be continued by expressing the answer as ``2 + p + q + r`` and then solving for an estimate for ``r``. +We can read that he guessed the answer was ``2 + p``, as there is a sign change between $2$ and $3$. Newton put this guess into the polynomial to get after simplification ``p^3 + 6p^2 + 10p - 1``. This has an **approximate** zero found by solving the linear part ``10p-1 = 0``. Taking ``p = 0.1`` he then can say the answer looks like ``2 + p + q`` and repeat to get ``q^3 + 6.3q^2 + 11.23q + 0.061 = 0``. Again taking just the linear part estimates `q = -0.005431...`. After two steps the estimate is `2.094568...`. This can be continued by expressing the answer as ``2 + p + q + r`` and then solving for an estimate for ``r``. Raphson (1690) proposed a simplification avoiding the computation of new polynomials, hence the usual name of the Newton-Raphson method. Simpson introduced derivatives into the formulation and systems of equations. @@ -696,7 +696,7 @@ If $M$ were just a constant and we suppose $e_0 = 10^{-1}$ then $e_1$ would be l To identify $M$, let $\alpha$ be the zero of $f$ to be approximated. Assume - * The function $f$ has at continuous second derivative in a neighborhood of $\alpha$. + * The function $f$ has a continuous second derivative in a neighborhood of $\alpha$. * The value $f'(\alpha)$ is *non-zero* in the neighborhood of $\alpha$. @@ -865,7 +865,7 @@ The function $f(x) = x^{20} - 1$ has two bad behaviours for Newton's method: for $x < 1$ the derivative is nearly $0$ and for $x>1$ the second derivative is very big. In this illustration, we have an initial guess of $x_0=8/9$. As the tangent line is fairly flat, the -next approximation is far away, $x_1 = 1.313\dots$. As this guess is +next approximation is far away, $x_1 = 1.313\dots$. As this guess is much bigger than $1$, the ratio $f(x)/f'(x) \approx x^{20}/(20x^{19}) = x/20$, so $x_i - f(x_i)/f'(x_i) \approx (19/20)x_i$ yielding slow, linear convergence until $f''(x_i)$ is moderate. For @@ -1033,7 +1033,7 @@ Let $f(x) = x^2 - 3^x$. This has derivative $2x - 3^x \cdot \log(3)$. Starting w f(x) = x^2 - 3^x; fp(x) = 2x - 3^x*log(3); val = Roots.newton(f, fp, 0); -numericq(val, 1e-14) +numericq(val, 1e-1) ``` ###### Question @@ -1424,7 +1424,7 @@ yesnoq("no") ###### Question -Quadratic convergence of Newton's method only applies to *simple* roots. For example, we can see (using the `verbose=true` argument to the `Roots` package's `newton` method, that it only takes $4$ steps to find a zero to $f(x) = \cos(x) - x$ starting at $x_0 = 1$. But it takes many more steps to find the same zero for $f(x) = (\cos(x) - x)^2$. +Quadratic convergence of Newton's method only applies to *simple* roots. For example, we can see (using the `verbose=true` argument to the `Roots` package's `newton` method), that it only takes $4$ steps to find a zero to $f(x) = \cos(x) - x$ starting at $x_0 = 1$. But it takes many more steps to find the same zero for $f(x) = (\cos(x) - x)^2$. How many? @@ -1454,7 +1454,7 @@ implicit_plot(f, xlims=(-2,2), ylims=(-2,2), legend=false) Can we find which point on its graph has the largest $y$ value? -This would be straightforward *if* we could write $y(x) = \dots$, for then we would simply find the critical points and investiate. But we can't so easily solve for $y$ interms of $x$. However, we can use Newton's method to do so: +This would be straightforward *if* we could write $y(x) = \dots$, for then we would simply find the critical points and investigate. But we can't so easily solve for $y$ interms of $x$. However, we can use Newton's method to do so: ```{julia} diff --git a/quarto/derivatives/optimization.qmd b/quarto/derivatives/optimization.qmd index fef9f8c..b8760d8 100644 --- a/quarto/derivatives/optimization.qmd +++ b/quarto/derivatives/optimization.qmd @@ -639,21 +639,21 @@ It is hard to tell which would minimize time without more work. To check a case ```{julia} -x_straight = t(r1 =>2r0, b=>0, x=>out[1], a=>1, L=>2, r0 => 1) # for x=L +x_straight = subs(t, r1 =>2r0, b=>0, x=>out[1], a=>1, L=>2, r0 => 1) # for x=L ``` Compared to the smaller ($x=\sqrt{3}a/3$): ```{julia} -x_angle = t(r1 =>2r0, b=>0, x=>out[2], a=>1, L=>2, r0 => 1) +x_angle = subs(t, r1 =>2r0, b=>0, x=>out[2], a=>1, L=>2, r0 => 1) ``` What about $x=0$? ```{julia} -x_bent = t(r1 =>2r0, b=>0, x=>0, a=>1, L=>2, r0 => 1) +x_bent = subs(t, r1 =>2r0, b=>0, x=>0, a=>1, L=>2, r0 => 1) ``` The value of $x=\sqrt{3}a/3$ minimizes time: @@ -671,7 +671,7 @@ Will this approach always be true? Consider different parameters, say we switch ```{julia} pts = [0, out...] -m,i = findmin([t(r1 =>2r0, b=>0, x=>u, a=>2, L=>1, r0 => 1) for u in pts]) # min, index +m,i = findmin([subs(t, r1 =>2r0, b=>0, x=>u, a=>2, L=>1, r0 => 1) for u in pts]) # min, index m, pts[i] ``` @@ -997,7 +997,7 @@ A rain gutter is constructed from a 30" wide sheet of tin by bending it into thi 2 * (1/2 * 10*cos(pi/4) * 10 * sin(pi/4)) + 10*sin(pi/4) * 10 ``` -Find a value in degrees that gives the maximum. (The first task is to write the area in terms of $\theta$. +Find a value in degrees that gives the maximum. (The first task is to write the area in terms of $\theta$.) ```{julia} @@ -1049,7 +1049,7 @@ plot!(p, [0, 30,30,0], [0,10,30,0], color=:orange) annotate!(p, [(x,y,l) for (x,y,l) in zip([15, 5, 31, 31], [1.5, 3.5, 5, 20], ["x=30", "θ", "10", "20"])]) ``` -What value of $x$ gives the largest angle $\theta$? (In degrees.) +What value of the largest angle $\theta$ that $x$ gives? (In degrees.) ```{julia} @@ -1094,7 +1094,7 @@ radioq(choices, answ) ##### Question -Let $x_1$, $x_2$, $x_n$ be a set of unspecified numbers in a data set. Form the expression $s(x) = (x-x_1)^2 + \cdots (x-x_n)^2$. What is the smallest this can be (in $x$)? +Let $x_1$, $x_2$, $\dots, x_n$ be a set of unspecified numbers in a data set. Form the expression $s(x) = (x-x_1)^2 + \cdots + (x-x_n)^2$. What is the smallest this can be (in $x$)? We approach this using `SymPy` and $n=10$ @@ -1108,7 +1108,7 @@ s(x) = sum((x-xi)^2 for xi in xs) cps = solve(diff(s(x), x), x) ``` -Run the above code. Baseed on the critical points found, what do you guess will be the minimum value in terms of the values $x_1$, $x_2, \dots$? +Run the above code. Based on the critical points found, what do you guess will be the minimum value in terms of the values $x_1$, $x_2, \dots$? ```{julia} @@ -1117,7 +1117,7 @@ Run the above code. Baseed on the critical points found, what do you guess will choices=[ "The mean, or average, of the values", "The median, or middle number, of the values", -L"The square roots of the values squared, $(x_1^2 + \cdots x_n^2)^2$" +L"The square roots of the values squared, $(x_1^2 + \cdots + x_n^2)^2$" ] answ = 1 radioq(choices, answ) @@ -1126,7 +1126,7 @@ radioq(choices, answ) ###### Question -Minimize the function $f(x) = 2x + 3/x$ over $(0, \infty)$. +Find $x$ to minimize the function $f(x) = 2x + 3/x$ over $(0, \infty)$. ```{julia} @@ -1190,7 +1190,7 @@ The width is: w(h) = 12_000 / h S(w, h) = (w- 2*8) * (h - 2*32) S(h) = S(w(h), h) -hstar =find_zero(D(S), 500) +hstar = find_zero(D(S), 200) wstar = w(hstar) numericq(wstar) ``` @@ -1204,7 +1204,7 @@ The height is? w(h) = 12_000 / h S(w, h) = (w- 2*8) * (h - 2*32) S(h) = S(w(h), h) -hstar =find_zero(D(S), 500) +hstar = find_zero(D(S), 200) numericq(hstar) ``` diff --git a/quarto/derivatives/taylor_series_polynomials.qmd b/quarto/derivatives/taylor_series_polynomials.qmd index d2c5cf9..e44f00c 100644 --- a/quarto/derivatives/taylor_series_polynomials.qmd +++ b/quarto/derivatives/taylor_series_polynomials.qmd @@ -118,7 +118,7 @@ The term "best" is deserved, as any other straight line will differ at least in $$ \begin{align*} \frac{F'(\xi)}{G'(\xi)} &= -\frac{f'(\xi) - f''(\xi)(\xi-x) - f(\xi)\cdot 1}{2(\xi-x)} \\ +\frac{f'(\xi) - f''(\xi)(\xi-x) - f'(\xi)\cdot 1}{2(\xi-x)} \\ &= -f''(\xi)/2\\ &= \frac{F(c) - F(x)}{G(c) - G(x)}\\ &= \frac{f(c) - f'(c)(c-x) - (f(x) - f'(x)(x-x))}{(c-x)^2 - (x-x)^2} \\ @@ -445,7 +445,7 @@ This can be solved to give this relationship: $$ -\frac{d^2\theta}{dt^2} = - \frac{g}{R}\theta. +\frac{d^2\theta}{dt^2} = \frac{g}{R}\theta. $$ The solution to this "equation" can be written (in some parameterization) as $\theta(t)=A\cos \left(\omega t+\phi \right)$. This motion is the well-studied simple [harmonic oscillator](https://en.wikipedia.org/wiki/Harmonic_oscillator), a model for a simple pendulum. @@ -721,7 +721,7 @@ The height of a [GPS satellite](http://www.gps.gov/systems/gps/space/) is about ```{julia} -Hₛ = 12250 * 1609.34 # 1609 meters per mile +Hₛ = 12550 * 1609.34 # 1609 meters per mile HRₛ = Hₛ/R Prealₛ = P0 * (1 + HRₛ)^(3/2) @@ -753,7 +753,7 @@ Finally, we show how to use the `Unitful` package. This package allows us to def m, mi, kg, s, hr = u"m", u"mi", u"kg", u"s", u"hr" G = 6.67408e-11 * m^3 / kg / s^2 -H = uconvert(m, 12250 * mi) # unit convert miles to meter +H = uconvert(m, 12550 * mi) # unit convert miles to meter R = uconvert(m, 3959 * mi) M = 5.972e24 * kg @@ -858,8 +858,8 @@ For notational purposes, let $g(x)$ be the inverse function for $f(x)$. Assume * $$ \begin{align*} -f(x_0 + \Delta_x) &= f(x_0) + a_1 \Delta_x + a_2 (\Delta_x)^2 + \cdots a_n (\Delta_x)^n + \dots\\ -g(y_0 + \Delta_y) &= g(y_0) + b_1 \Delta_y + b_2 (\Delta_y)^2 + \cdots b_n (\Delta_y)^n + \dots +f(x_0 + \Delta_x) &= f(x_0) + a_1 \Delta_x + a_2 (\Delta_x)^2 + \cdots + a_n (\Delta_x)^n + \dots\\ +g(y_0 + \Delta_y) &= g(y_0) + b_1 \Delta_y + b_2 (\Delta_y)^2 + \cdots + b_n (\Delta_y)^n + \dots \end{align*} $$ @@ -897,7 +897,7 @@ $$ (This is following [Liptaj](https://vixra.org/pdf/1703.0295v1.pdf)). -We will use `SymPy` to take this limit for the first `4` derivatives. Here is some code that expands $x + \Delta_x = g(f(x_0 + \Delta_x))$ and then uses `SymPy` to solve: +We will use `SymPy` to take this limit for the first `4` derivatives. Here is some code that expands $x_0 + \Delta_x = g(f(x_0 + \Delta_x))$ and then uses `SymPy` to solve: ```{julia} From 6065782e070d6b330edb27e5c1074befca50bad7 Mon Sep 17 00:00:00 2001 From: jverzani Date: Thu, 29 May 2025 07:49:08 -0400 Subject: [PATCH 06/11] typos --- quarto/derivatives/optimization.qmd | 2 +- quarto/misc/calculus_with_julia.qmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quarto/derivatives/optimization.qmd b/quarto/derivatives/optimization.qmd index b8760d8..406d3b7 100644 --- a/quarto/derivatives/optimization.qmd +++ b/quarto/derivatives/optimization.qmd @@ -1482,7 +1482,7 @@ a = find_zero(y', 1) numericq(a) ``` -Numerically find the value of $a$ that minimizes the length of the line seqment $PQ$. +Numerically find the value of $a$ that minimizes the length of the line segment $PQ$. ```{julia} diff --git a/quarto/misc/calculus_with_julia.qmd b/quarto/misc/calculus_with_julia.qmd index 2726724..587de9e 100644 --- a/quarto/misc/calculus_with_julia.qmd +++ b/quarto/misc/calculus_with_julia.qmd @@ -68,7 +68,7 @@ For more control, the command line and `IJulia` provide access to the function i ] status ``` -External packages are *typically* installed from GitHub and if they are regisered, installation is as easy as calling `add`: +External packages are *typically* installed from GitHub and if they are registered, installation is as easy as calling `add`: ```{julia} From 8ede2b33fb0e95a6c4445c4f537db69eeb59f649 Mon Sep 17 00:00:00 2001 From: Fang Liu Date: Fri, 6 Jun 2025 16:56:56 +0800 Subject: [PATCH 07/11] some typos --- quarto/integrals/arc_length.qmd | 10 +++++----- quarto/integrals/area.qmd | 12 ++++++------ quarto/integrals/area_between_curves.qmd | 11 ++++++----- quarto/integrals/center_of_mass.qmd | 2 +- quarto/integrals/ftc.qmd | 6 +++--- quarto/integrals/improper_integrals.qmd | 2 +- quarto/integrals/integration_by_parts.qmd | 2 +- quarto/integrals/partial_fractions.qmd | 2 +- quarto/integrals/surface_area.qmd | 4 ++-- quarto/integrals/twelve-qs.qmd | 14 +++++++------- quarto/limits/limits.qmd | 2 +- 11 files changed, 34 insertions(+), 33 deletions(-) diff --git a/quarto/integrals/arc_length.qmd b/quarto/integrals/arc_length.qmd index c31ff5e..a3d6e5b 100644 --- a/quarto/integrals/arc_length.qmd +++ b/quarto/integrals/arc_length.qmd @@ -493,14 +493,14 @@ What looks at first glance to be just a slightly more complicated equation is th $$ \begin{align*} -s(u) &= \int_0^u \sqrt{(-\sin(t))^2 + b\cos(t)^2} dt\\ - &= \int_0^u \sqrt{\sin(t)^2 + \cos(t)^2 + c\cos(t)^2} dt \\ - &=\int_0^u \sqrt{1 + c\cos(t)^2} dt. +s(u) &= \int_0^u \sqrt{(-\sin(t))^2 + (b\cos(t))^2} dt\\ + &= \int_0^u \sqrt{\sin(t)^2 + \cos(t)^2 + C\cos(t)^2} dt \\ + &=\int_0^u \sqrt{1 + C\cos(t)^2} dt. \end{align*} $$ -But, despite it not looking too daunting, this integral is not tractable through our techniques and has an answer involving elliptic integrals. We can work numerically though. Letting $a=1$ and $b=2$, we have the arc length is given by: +Where $C = 2c + c^2$ is a constant. But, despite it not looking too daunting, this integral is not tractable through our techniques and has an answer involving elliptic integrals. We can work numerically though. Letting $a=1$ and $b=2$, we have the arc length is given by: ```{julia} @@ -710,7 +710,7 @@ For the latter claim, integrating in the $y$ variable gives $$ \begin{align*} \int_u^c (f(x)-h) dx &= \int_h^m (c - f_1^{-1}(y)) dy\\ -&> \int_h^m (c - f_2^{-1}(y)) dy\\ +&> \int_h^m (f_2^{-1}(y) - c) dy\\ &= \int_c^v (f(x)-h) dx \end{align*} $$ diff --git a/quarto/integrals/area.qmd b/quarto/integrals/area.qmd index 3f18360..8cbe09d 100644 --- a/quarto/integrals/area.qmd +++ b/quarto/integrals/area.qmd @@ -17,7 +17,7 @@ using Roots --- -The question of area has long fascinated human culture. As children, we learn early on the formulas for the areas of some geometric figures: a square is $b^2$, a rectangle $b\cdot h$ a triangle $1/2 \cdot b \cdot h$ and for a circle, $\pi r^2$. The area of a rectangle is often the intuitive basis for illustrating multiplication. The area of a triangle has been known for ages. Even complicated expressions, such as [Heron's](http://tinyurl.com/mqm9z) formula which relates the area of a triangle with measurements from its perimeter have been around for 2000 years. The formula for the area of a circle is also quite old. Wikipedia dates it as far back as the [Rhind](http://en.wikipedia.org/wiki/Rhind_Mathematical_Papyrus) papyrus for 1700 BC, with the approximation of $256/81$ for $\pi$. +The question of area has long fascinated human culture. As children, we learn early on the formulas for the areas of some geometric figures: a square is $b^2$, a rectangle $b\cdot h$, a triangle $1/2 \cdot b \cdot h$ and for a circle, $\pi r^2$. The area of a rectangle is often the intuitive basis for illustrating multiplication. The area of a triangle has been known for ages. Even complicated expressions, such as [Heron's](http://tinyurl.com/mqm9z) formula which relates the area of a triangle with measurements from its perimeter have been around for 2000 years. The formula for the area of a circle is also quite old. Wikipedia dates it as far back as the [Rhind](http://en.wikipedia.org/wiki/Rhind_Mathematical_Papyrus) papyrus for 1700 BC, with the approximation of $256/81$ for $\pi$. The modern approach to area begins with a non-negative function $f(x)$ over an interval $[a,b]$. The goal is to compute the area under the graph. That is, the area between $f(x)$ and the $x$-axis between $a \leq x \leq b$. @@ -480,9 +480,9 @@ This is just the area of a trapezoid with heights $a$ and $b$ and side length $$ \begin{align*} -S &= x_1 \cdot (x_1 - x_0) + x_2 \cdot (x_2 - x_1) + \cdots x_n \cdot (x_n - x_{n-1}) \\ -&= (a + 1\frac{b-a}{n}) \cdot \frac{b-a}{n} + (a + 2\frac{b-a}{n}) \cdot \frac{b-a}{n} + \cdots (a + n\frac{b-a}{n}) \cdot \frac{b-a}{n}\\ -&= n \cdot a \cdot (\frac{b-a}{n}) + (1 + 2 + \cdots n) \cdot (\frac{b-a}{n})^2 \\ +S &= x_1 \cdot (x_1 - x_0) + x_2 \cdot (x_2 - x_1) + \cdots + x_n \cdot (x_n - x_{n-1}) \\ +&= (a + 1\frac{b-a}{n}) \cdot \frac{b-a}{n} + (a + 2\frac{b-a}{n}) \cdot \frac{b-a}{n} + \cdots + (a + n\frac{b-a}{n}) \cdot \frac{b-a}{n}\\ +&= n \cdot a \cdot (\frac{b-a}{n}) + (1 + 2 + \cdots + n) \cdot (\frac{b-a}{n})^2 \\ &= n \cdot a \cdot (\frac{b-a}{n}) + \frac{n(n+1)}{2} \cdot (\frac{b-a}{n})^2 \\ & \rightarrow a \cdot(b-a) + \frac{(b-a)^2}{2} \\ &= \frac{b^2}{2} - \frac{a^2}{2}. @@ -729,7 +729,7 @@ An immediate consequence would be $\int_{-\pi}^\pi \sin(x) = 0$, as would $\int_ ##### Example -Numerically estimate the definite integral $\int_0^e x\log(x) dx$. (We redefine the function to be $0$ at $0$, so it is continuous.) +Numerically estimate the definite integral $\int_0^2 x\log(x) dx$. (We redefine the function to be $0$ at $0$, so it is continuous.) We have to be a bit careful with the Riemann sum, as the left Riemann sum will have an issue at $0=x_0$ (`0*log(0)`) returns `NaN` which will poison any subsequent arithmetic operations, so the value returned will be `NaN` and not an approximate answer. We could define our function with a check: @@ -860,7 +860,7 @@ $$ \frac{b-a}{6}(f(x_1) + 4f(x_2) + f(x_3)). $$ -This formula will actually be exact for any 3rd degree polynomial. In fact an entire family of similar approximations using $n$ points can be made exact for any polynomial of degree $n-1$ or lower. But with non-evenly spaced points, even better results can be found. +This formula will actually be exact for any 2nd degree polynomial. In fact an entire family of similar approximations using $n$ points can be made exact for any polynomial of degree $n-1$ or lower. But with non-evenly spaced points, even better results can be found. The formulas for an approximation to the integral $\int_{-1}^1 f(x) dx$ discussed so far can be written as: diff --git a/quarto/integrals/area_between_curves.qmd b/quarto/integrals/area_between_curves.qmd index ae95ab1..cce4ab5 100644 --- a/quarto/integrals/area_between_curves.qmd +++ b/quarto/integrals/area_between_curves.qmd @@ -494,7 +494,7 @@ box(f⁻¹(x₀-1Δ), x₀-2Δ, 1 - f⁻¹(x₀-1Δ), Δ, colᵣ) box(f⁻¹(x₀-2Δ), x₀-3Δ, 1 - f⁻¹(x₀-2Δ), Δ, colᵣ) ``` -The figure above suggests that the area under $f(x)$ over $[a,b]$ could be represented as the area between the curves $f^{-1}(y)$ and $y=b$ from $[f(a), f(b)]$. +The figure above suggests that the area under $f(x)$ over $[a,b]$ could be represented as the area between the curves $f^{-1}(y)$ and $x=b$ from $[f(a), f(b)]$. --- @@ -552,7 +552,7 @@ p = plot(xs, ys; line=(3, :black), ylims=(0,4), legend=false) scatter!(p, xs, ys; marker=(7, :circle)) ``` -Going further, we draw the four trapezoids using different colors depending on the sign of the `xs[i+1] - xs[[i]` terms: +Going further, we draw the four trapezoids using different colors depending on the sign of the `xs[i+1] - xs[i]` terms: ```{julia} for i in 1:4 @@ -563,7 +563,7 @@ end p ``` -The yellow trapezoids appear to be colored green, as they completely overlap with parts of the blue trapezoids and blue and yellow make green. As the signs of the differences of the $x$ values is different, these areas add to $0$ in the sum, leaving just the area of the interior when the sum is computed. +The yellow trapezoids appear to be colored grey, as they completely overlap with parts of the blue trapezoids and blue and yellow make grey with lights. As the signs of the differences of the $x$ values is different, these areas add to $0$ in the sum, leaving just the area of the interior when the sum is computed. For this particular figure, the enclosed area is @@ -964,9 +964,10 @@ end What does this imply: ```{julia} +#| hold: true #| echo: false choices = ["The two enclosed areas should be equal", - "The two enclosed areas are clearly different, as they do not overap"], + "The two enclosed areas are clearly different, as they do not overap"] radioq(choices, 1) ``` - " + diff --git a/quarto/integrals/center_of_mass.qmd b/quarto/integrals/center_of_mass.qmd index a3f486b..e148a5b 100644 --- a/quarto/integrals/center_of_mass.qmd +++ b/quarto/integrals/center_of_mass.qmd @@ -503,7 +503,7 @@ numericq(val) ###### Question -Find the center of mass of the region in the first quadrant bounded by the function $f(x) = x^3(1-x)^4$. +Find the center of mass in the $x$ variable of the region in the first quadrant bounded by the function $f(x) = x^3(1-x)^4$. ```{julia} diff --git a/quarto/integrals/ftc.qmd b/quarto/integrals/ftc.qmd index 14abf85..742e13c 100644 --- a/quarto/integrals/ftc.qmd +++ b/quarto/integrals/ftc.qmd @@ -589,7 +589,7 @@ The answer will either be at a critical point, at $0$ or as $x$ goes to $\infty$ $$ -[\text{erf}(x)]' = \frac{2}{\pi}e^{-x^2}. +[\text{erf}(x)]' = \frac{2}{\sqrt{\pi}}e^{-x^2}. $$ Oh, this is never $0$, so there are no critical points. The maximum occurs at $0$ or as $x$ goes to $\infty$. Clearly at $0$, we have $\text{erf}(0)=0$, so the answer will be as $x$ goes to $\infty$. @@ -755,7 +755,7 @@ A junior engineer at `Treadmillz.com` is tasked with updating the display of cal ********** ``` -In this example display there was 1 calorie burned in the first minute, then 2, then 5, 5, 4, 3, 2, 2, 1. The total is $24$. +In this example display there was 1 calorie burned in the first minute, then 2, then 5, 5, 4, 4, 3, 2, 2, 1. The total is $29$. In her work the junior engineer found this old function for updating the display @@ -814,7 +814,7 @@ end Then the "area" represented by the dots stays fixed over this time frame. -The engineer then thought a bit more, as the form of her answer seemed familiar. She decides to parameterize it in terms of $t$ and found with $h=1/n$: `c(t) = (C(t) - C(t-h))/h`. Ahh - the derivative approximation. But then what is the "area"? It is no longer just the sum of the dots, but in terms of the functions she finds that each column represents $c(t)\cdot h$, and the sum is just $c(t_1)h + c(t_2)h + \cdots c(t_n)h$ which looks like an approximate integral. +The engineer then thought a bit more, as the form of her answer seemed familiar. She decides to parameterize it in terms of $t$ and found with $h=1/n$: `c(t) = (C(t) - C(t-h))/h`. Ahh - the derivative approximation. But then what is the "area"? It is no longer just the sum of the dots, but in terms of the functions she finds that each column represents $c(t)\cdot h$, and the sum is just $c(t_1)h + c(t_2)h + \cdots + c(t_n)h$ which looks like an approximate integral. If the display were to reach the modern age and replace LED "dots" with a higher-pixel display, then the function to display would be $c(t) = C'(t)$ and the area displayed would be $\int_{t-10}^t c(u) du$. diff --git a/quarto/integrals/improper_integrals.qmd b/quarto/integrals/improper_integrals.qmd index b092702..057ad5b 100644 --- a/quarto/integrals/improper_integrals.qmd +++ b/quarto/integrals/improper_integrals.qmd @@ -161,7 +161,7 @@ $$ = \int_{\log(e)}^{\log(M)} \frac{1}{u^{2}} du = \frac{-1}{u} \big|_{1}^{\log(M)} = \frac{-1}{\log(M)} - \frac{-1}{1} -= 1 - \frac{1}{M}. += 1 - \frac{1}{\log(M)}. $$ As $M$ goes to $\infty$, this will converge to $1$. diff --git a/quarto/integrals/integration_by_parts.qmd b/quarto/integrals/integration_by_parts.qmd index 3dff29a..dcbff56 100644 --- a/quarto/integrals/integration_by_parts.qmd +++ b/quarto/integrals/integration_by_parts.qmd @@ -95,7 +95,7 @@ end @fig-integration-by-parts shows a parametric plot of $(u(t),v(t))$ for $a \leq t \leq b$.. -The total shaded area, a rectangle, is $u(b)v(b)$, the area of $A$ and $B$ combined is just $u(b)v(b) - u(a)v(a)$ or $[u(x)v(x)]\big|_a^b$. We will show that that $A$ is $\int_a^b v(x)u'(x)dx$ and $B$ is $\int_a^b u(x)v'(x)dx$ giving the formula +The total shaded area, a rectangle, is $u(b)v(b)$, the area of $A$ and $B$ combined is just $u(b)v(b) - u(a)v(a)$ or $[u(x)v(x)]\big|_a^b$. We will show that $A$ is $\int_a^b v(x)u'(x)dx$ and $B$ is $\int_a^b u(x)v'(x)dx$ giving the formula. We can compute $A$ by a change of variables with $x=u^{-1}(t)$ (so $u'(x)dx = dt$): diff --git a/quarto/integrals/partial_fractions.qmd b/quarto/integrals/partial_fractions.qmd index 2fc0983..3fcfdae 100644 --- a/quarto/integrals/partial_fractions.qmd +++ b/quarto/integrals/partial_fractions.qmd @@ -456,7 +456,7 @@ answ = 2 radioq(choices, answ, keep_order=true) ``` -If $m < n$, then why can we cancel out the $(x-c)^n$ and not have a concern? +If $m < n$, then why can we cancel out the $(x-c)^m$ and not have a concern? ```{julia} diff --git a/quarto/integrals/surface_area.qmd b/quarto/integrals/surface_area.qmd index 2cb2efd..eed1d73 100644 --- a/quarto/integrals/surface_area.qmd +++ b/quarto/integrals/surface_area.qmd @@ -263,7 +263,7 @@ ws = unzip(S.(us,vs')) surface(ws..., alpha=0.75) ``` -We compare this answer to that of the frustum of a cone with radii $1$ and $(3/2)^2$, formed by rotating the line segment connecting $(0,f(0))$ with $(3/2,f(3/2))$. From looking at the graph of the surface, these values should be comparable. The surface area of the cone part is $\pi (r_1^2 + r_0^2) / \sin(\theta) = \pi (r_1 + r_0) \cdot \sqrt{(\Delta h)^2 + (r_1-r_0)^2}$. +We compare this answer to that of the frustum of a cone with radii $1$ and $(3/2)^2$, formed by rotating the line segment connecting $(0,f(0))$ with $(3/2,f(3/2))$. From looking at the graph of the surface, these values should be comparable. The surface area of the cone part is $\pi (r_1^2 - r_0^2) / \sin(\theta) = \pi (r_1 + r_0) \cdot \sqrt{(\Delta h)^2 + (r_1-r_0)^2}$. ```{julia} @@ -354,7 +354,7 @@ That is, the surface area is simply the circumference of the circle traced out b ##### Example -The surface area of of an open cone can be computed, as the arc length is $\sqrt{h^2 + r^2}$ and the centroid of the line is a distance $r/2$ from the axis. This gives SA$=2\pi (r/2) \sqrt{h^2 + r^2} = \pi r \sqrt{h^2 + r^2}$. +The surface area of an open cone can be computed, as the arc length is $\sqrt{h^2 + r^2}$ and the centroid of the line is a distance $r/2$ from the axis. This gives SA$=2\pi (r/2) \sqrt{h^2 + r^2} = \pi r \sqrt{h^2 + r^2}$. ##### Example diff --git a/quarto/integrals/twelve-qs.qmd b/quarto/integrals/twelve-qs.qmd index 6c6a424..cdb6144 100644 --- a/quarto/integrals/twelve-qs.qmd +++ b/quarto/integrals/twelve-qs.qmd @@ -165,7 +165,7 @@ A = simplify(integrate(nl - f(x), (x, q, a))); #| code-fold: true #| code-summary: "Show the code" @syms k::nonnegative -V = simplify(integrate(PI * (nl - f(x) - k)^2, (x, q, a))); +V = simplify(integrate(2PI*(nl-f(x))*(a - x + k),(x, q, a))); ``` ---- @@ -218,7 +218,7 @@ L = integrate(sqrt(1 + fp(x)^2), (x, q, a)); ---- -> 5. The $y$ coordinate of the midpoint ofthe line segment $PQ$ +> 5. The $y$ coordinate of the midpoint of the line segment $PQ$ ```{julia} @@ -300,7 +300,7 @@ end #| code-summary: "Show the code" # use parametric and 2π ∫ u(t) √(u'(t)^2 + v'(t)^2) dt uu(x) = a - x -vv(x) = f(uu(x)) +vv(x) = f(a - uu(x)) SA = 2PI * integrate(uu(x) * sqrt(diff(uu(x),x)^2 + diff(vv(x),x)^2), (x, q, a)); ``` @@ -394,11 +394,11 @@ plot!([a₀,q₀,q₀,a₀-f(a₀)/fp(a₀),a₀], # v1, v2, v3 = [[x[i]-x[1],y[i]-y[1], 0] for i in 2:4] # area = 1//2 * last(cross(v3,v2) + cross(v2, v1)) # 1/2 area of parallelogram # print(simplify(area)) -# -(x₁ - x₂)*(y₁ - y₃)/2 + (x₁ - x₃)*(y₁ - y₂)/2 - (x₁ - x₃)*(y₁ - y₄)/2 + (x₁ - x₄)*(y₁ - y₃)/2 +# (x₁ - x₂)*(y₁ - y₃)/2 - (x₁ - x₃)*(y₁ - y₂)/2 + (x₁ - x₃)*(y₁ - y₄)/2 - (x₁ - x₄)*(y₁ - y₃)/2 tl₀ = a - f(a) / fp(a) x₁,x₂,x₃,x₄ = (a,q,q,tl₀) y₁, y₂, y₃, y₄ = (f(a), f(q), 0, 0) -quadrilateral = -(x₁ - x₂)*(y₁ - y₃)/2 + (x₁ - x₃)*(y₁ - y₂)/2 - (x₁ - x₃)*(y₁ - y₄)/2 + (x₁ - x₄)*(y₁ - y₃)/2; +quadrilateral = (x₁ - x₂)*(y₁ - y₃)/2 - (x₁ - x₃)*(y₁ - y₂)/2 + (x₁ - x₃)*(y₁ - y₄)/2 - (x₁ - x₄)*(y₁ - y₃)/2; ``` ---- @@ -415,7 +415,7 @@ article_answers = (1/(2sqrt(2)), 1/2, sqrt(3/10), 0.558480, 0.564641, #| echo: false # check problems = ("1a"=>yvalue, "1b"=>lseg, "1c"=>hd, - "2a" => A, "2b" => V, + "2a" => A, "2b" => V(k=>1), "3" => yₘ, "4" => L, "5" => mp, @@ -429,7 +429,7 @@ problems = ("1a"=>yvalue, "1b"=>lseg, "1c"=>hd, ) ≈ₒ(a,b) = isapprox(a, b; atol=1e-5, rtol=sqrt(eps())) ∂ = Differential(a) -solutions = [k => only(solve(∂(p) ~ 0, a)) for (k,p) in problems] +solutions = [k => (find_zero(∂(p), 0.5)) for (k,p) in problems] [(sol=k, correct=(any(isapprox.(s, article_answers; atol=1e-5)))) for (k,s) ∈ solutions] nothing ``` diff --git a/quarto/limits/limits.qmd b/quarto/limits/limits.qmd index 4f21c49..59c24b4 100644 --- a/quarto/limits/limits.qmd +++ b/quarto/limits/limits.qmd @@ -73,7 +73,7 @@ gif(anim, imgfile, fps = 1) caption = L""" -The first triangle has area $1/2$, the second has area $1/8$, then $3$ have area $(1/8)^2$, $4$ have area $(1/8)^3$, ... +The first triangle has area $1/2$, the second has area $1/8$, then $2$ have area $(1/8)^2$, $4$ have area $(1/8)^3$, ... With some algebra, the total area then should be $1/2 \cdot (1 + (1/4) + (1/4)^2 + \cdots) = 2/3$. """ From 748797fee50ebb2c7b94d078d58d03cbd756600f Mon Sep 17 00:00:00 2001 From: jverzani Date: Fri, 6 Jun 2025 06:49:50 -0400 Subject: [PATCH 08/11] WIP --- quarto/_common_code.qmd | 2 +- quarto/derivatives/Project.toml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/quarto/_common_code.qmd b/quarto/_common_code.qmd index 84bcf2c..fcc1575 100644 --- a/quarto/_common_code.qmd +++ b/quarto/_common_code.qmd @@ -47,7 +47,7 @@ end import Base64: base64encode import Markdown using Mustache -usingTables +using Tables # q and L using LaTeXStrings diff --git a/quarto/derivatives/Project.toml b/quarto/derivatives/Project.toml index 90e7d59..aadd710 100644 --- a/quarto/derivatives/Project.toml +++ b/quarto/derivatives/Project.toml @@ -5,12 +5,19 @@ DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" ImplicitEquations = "95701278-4526-5785-aba3-513cca398f19" +LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4" +Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" +Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" TaylorSeries = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea" TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" +TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" From e7684ac2f72a6a6f794bb322fd35bb43240ca4ba Mon Sep 17 00:00:00 2001 From: jverzani Date: Fri, 6 Jun 2025 12:06:10 -0400 Subject: [PATCH 09/11] incorporate PR --- quarto/integrals/Project.toml | 6 ++++++ quarto/integrals/twelve-qs.qmd | 1 + 2 files changed, 7 insertions(+) diff --git a/quarto/integrals/Project.toml b/quarto/integrals/Project.toml index f1f0940..b420575 100644 --- a/quarto/integrals/Project.toml +++ b/quarto/integrals/Project.toml @@ -1,13 +1,19 @@ [deps] CalculusWithJulia = "a2e0e22d-7d4c-5312-9169-8b992201a882" +ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" +LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66" SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" +Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" UnitfulUS = "7dc9378f-8956-57ef-a780-aa31cc70ff3d" diff --git a/quarto/integrals/twelve-qs.qmd b/quarto/integrals/twelve-qs.qmd index cdb6144..4622360 100644 --- a/quarto/integrals/twelve-qs.qmd +++ b/quarto/integrals/twelve-qs.qmd @@ -5,6 +5,7 @@ This section uses these packages: ```{julia} using SymPy using Plots +using Roots plotly() ``` From 95429d26f971363a72f8caf574bafcbbefe320d3 Mon Sep 17 00:00:00 2001 From: Fang Liu Date: Sat, 14 Jun 2025 09:27:53 +0800 Subject: [PATCH 10/11] some typos. --- quarto/ODEs/differential_equations.qmd | 2 +- quarto/ODEs/odes.qmd | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/quarto/ODEs/differential_equations.qmd b/quarto/ODEs/differential_equations.qmd index 082e324..ef85e1b 100644 --- a/quarto/ODEs/differential_equations.qmd +++ b/quarto/ODEs/differential_equations.qmd @@ -409,7 +409,7 @@ p = [γ => 0.0, prob = ODEProblem(sys, u0, TSPAN, p, jac=true) sol = solve(prob,Tsit5()) -plot(t -> sol(t)[3], t -> sol(t)[4], TSPAN..., legend=false) +plot(t -> sol(t)[1], t -> sol(t)[3], TSPAN..., legend=false) ``` The toolkit will automatically generate fast functions and can perform transformations (such as is done by `ode_order_lowering`) before passing along to the numeric solves. diff --git a/quarto/ODEs/odes.qmd b/quarto/ODEs/odes.qmd index 55e8722..46b2050 100644 --- a/quarto/ODEs/odes.qmd +++ b/quarto/ODEs/odes.qmd @@ -340,7 +340,7 @@ The first-order initial value equations we have seen can be described generally $$ \begin{align*} y'(x) &= F(y,x),\\ -y(x_0) &= x_0. +y(x_0) &= y_0. \end{align*} $$ @@ -375,7 +375,7 @@ $$ u'(x) = a u(1-u), \quad a > 0 $$ -Before beginning, we look at the form of the equation. When $u=0$ or $u=1$ the rate of change is $0$, so we expect the function might be bounded within that range. If not, when $u$ gets bigger than $1$, then the slope is negative and when $u$ gets less than $0$, the slope is positive, so there will at least be a drift back to the range $[0,1]$. Let's see exactly what happens. We define a parameter, restricting `a` to be positive: +Before beginning, we look at the form of the equation. When $u=0$ or $u=1$ the rate of change is $0$, so we expect the function might be bounded within that range. If not, when $u$ gets bigger than $1$, then the slope is negative and though the slope is negative too when $u<0$, but for a realistic problem, it always be $u\ge0$. so we focus $u$ on the range $[0,1]$. Let's see exactly what happens. We define a parameter, restricting `a` to be positive: ```{julia} @@ -403,7 +403,7 @@ To finish, we call `dsolve` to find a solution (if possible): out = dsolve(eqn) ``` -This answer - to a first-order equation - has one free constant, `C_1`, which can be solved for from an initial condition. We can see that when $a > 0$, as $x$ goes to positive infinity the solution goes to $1$, and when $x$ goes to negative infinity, the solution goes to $0$ and otherwise is trapped in between, as expected. +This answer - to a first-order equation - has one free constant, `C₁`, which can be solved for from an initial condition. We can see that when $a > 0$, as $x$ goes to positive infinity the solution goes to $1$, and when $x$ goes to negative infinity, the solution goes to $0$ and otherwise is trapped in between, as expected. The limits are confirmed by investigating the limits of the right-hand: @@ -420,7 +420,7 @@ We can confirm that the solution is always increasing, hence trapped within $[0, diff(rhs(out),x) ``` -Suppose that $u(0) = 1/2$. Can we solve for $C_1$ symbolically? We can use `solve`, but first we will need to get the symbol for `C_1`: +Suppose that $u(0) = 1/2$. Can we solve for $C_1$ symbolically? We can use `solve`, but first we will need to get the symbol for `C₁`: ```{julia} From 4f60e9a41461d43775fb1dbc46bffc1cd0dbb0de Mon Sep 17 00:00:00 2001 From: jverzani Date: Sat, 14 Jun 2025 07:23:19 -0400 Subject: [PATCH 11/11] typos --- quarto/precalc/julia_overview.qmd | 4 ++-- quarto/precalc/numbers_types.qmd | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/quarto/precalc/julia_overview.qmd b/quarto/precalc/julia_overview.qmd index bac1c2d..86adc26 100644 --- a/quarto/precalc/julia_overview.qmd +++ b/quarto/precalc/julia_overview.qmd @@ -97,7 +97,7 @@ julia> 2 + 2 * An IDE. For programmers, an integrated development environment is often used to manage bigger projects. `Julia` has `Juno` and `VSCode`. - * A notebook. The [Project Juptyer](https://jupyter.org/) provides a notebook interface for interacting with `Julia` and a more `IDE` style `jupyterlab` interface. A jupyter notebook has cells where commands are typed and immediately following is the printed output returned by `Julia`. The output of a cell depends on the state of the kernel when the cell is computed, not the order of the cells in the notebook. Cells have a number attached, showing the execution order. The `Juypter` notebook is used by `binder` and can be used locally through the `IJulia` package. This notebook has the ability to display many different types of outputs in addition to plain text, such as images, marked up math text, etc. + * A notebook. The [Project Jupyter](https://jupyter.org/) provides a notebook interface for interacting with `Julia` and a more `IDE` style `jupyterlab` interface. A jupyter notebook has cells where commands are typed and immediately following is the printed output returned by `Julia`. The output of a cell depends on the state of the kernel when the cell is computed, not the order of the cells in the notebook. Cells have a number attached, showing the execution order. The `Juypter` notebook is used by `binder` and can be used locally through the `IJulia` package. This notebook has the ability to display many different types of outputs in addition to plain text, such as images, marked up math text, etc. * The [Pluto](https://github.com/fonsp/Pluto.jl) package provides a *reactive* notebook interface. Reactive means when one "cell" is modified and executed, the new values cascade to all other dependent cells which in turn are updated. This is very useful for exploring a parameter space, say. Pluto notebooks can be exported as HTML files which make them easy to read online and – by clever design – embed the `.jl` file that can run through `Pluto` if it is downloaded. @@ -280,7 +280,7 @@ Values will be promoted to a common type (or type `Any` if none exists). For exa (Vectors are used as a return type from some functions, as such, some familiarity is needed.) -Other common container types are variables of vectors (higher-dimensional arrarys, offset arrays, etc.) tuples (for heterogeneous, immutable, indexed values); named tuples (which add a name to each value in a tuple); and dictionaries (for associative relationships between a key and a value). +Other common container types are variables of vectors (higher-dimensional arrays, offset arrays, etc.) tuples (for heterogeneous, immutable, indexed values); named tuples (which add a name to each value in a tuple); and dictionaries (for associative relationships between a key and a value). Regular arithmetic sequences can be defined by either: diff --git a/quarto/precalc/numbers_types.qmd b/quarto/precalc/numbers_types.qmd index 929797a..454abfc 100644 --- a/quarto/precalc/numbers_types.qmd +++ b/quarto/precalc/numbers_types.qmd @@ -26,7 +26,7 @@ On top of these, we have special subsets, such as the natural numbers $\{1, 2, \ Mathematically, these number systems are naturally nested within each other as integers are rational numbers which are real numbers, which can be viewed as part of the complex numbers. -Calculators typically have just one type of number - floating point values. These model the real numbers. `Julia`, on the other hand, has a rich type system, and within that has serveral different number types. There are types that model each of the four main systems above, and within each type, specializations for how these values are stored. +Calculators typically have just one type of number - floating point values. These model the real numbers. `Julia`, on the other hand, has a rich type system, and within that has several different number types. There are types that model each of the four main systems above, and within each type, specializations for how these values are stored. Most of the details will not be of interest to all, and will be described later.