lots of cleanup

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

View File

@@ -567,54 +567,67 @@ 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:
::: {#fig-plot-sin-0-to-2pi-illustration}
```{julia}
plot(sin, 0, 2pi)
```
Plot of $f(x) = \sin(x)$ over $[0, 2\pi]$
:::
::: {.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.
This plot command is in the form of **the** basic pattern employed throughout: `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:
::: {#fig-plot-example-sin-cos-zero}
```{julia}
plot(sin, 0, 2pi)
plot!(cos, 0, 2pi)
plot!(zero, 0, 2pi) # add the line y=0
plot!(cos)
plot!(zero) # add the line y=0
```
Plot of $f(x) = \sin(x)$, $g(x) = \cos(x)$ and $h(x) = 0 over $[0, 2\pi]$
:::
(There are alternatives to plot functions or other traces all at once.)
Individual points are added with `scatter` or `scatter!`:
Individual points are added with `scatter` or `scatter!`. Either two vectors `xs` and `ys` with the coordinates in each *or* a vector of tuples, each tuple representing a point can be used.
::: {#fig-plot-of-sin-cos-scattered-points}
```{julia}
plot(sin, 0, 2pi, legend=false)
plot!(cos, 0, 2pi)
scatter!([pi/4, pi+pi/4], [sin(pi/4), sin(pi + pi/4)])
scatter!([(pi/4, sin(pi/4)), ( pi+pi/4, sin(pi + pi/4))])
```
Plot of $f(x) = \sin(x)$ and $g(x) = \cos(x)$ over the $[0, 2\pi]$ with intersection points marked with markers through `scatter`
:::
(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:
::: {#fig-plot-of-anonymous-function-exp-minusx-over-pi-times-sinx}
```{julia}
plot( x -> exp(-x/pi) * sin(x), 0, 2pi)
```
Plot of $f(x) = e^{-x/\pi}\sin(x)$ over $[0, 2\pi]$ using an anonymous function
:::
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:
::: {#fig-plot-sine-functions-using-xs-ys-approach}
```{julia}
#| hold: true
xs = range(0, 2pi, length=251)
ys = [sin(2x) + sin(3x) + sin(4x) for x in xs]
plot(xs, ys)
```
Plot of $f(x) = \sin(2x) + \sin(3x) + \sin(4x)$ over $[0, 2\pi]$ made by constructing vectors `xs` , `ys` holding $x$ and $y$ coordiinates of points to include
:::
There are different plotting interfaces. Though not shown, all of these `plot` commands produce a plot of `f`, though with minor differences:
@@ -679,12 +692,14 @@ 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:
SymPy expressions of a single free variable can be plotted directly.
::: {#fig-plot-64-16-xsquared-using-sympy-recipe}
```{julia}
plot(64 - (1/2)*32 * x^2, 0, 2)
```
Plot of $f(x) = 64 - 16x^2$ over $[0, 2]$ using a plot recipe
:::
* SymPy has functions for manipulating expressions: `simplify`, `expand`, `together`, `factor`, `cancel`, `apart`, $...$
* SymPy has functions for basic math: `factor`, `roots`, `solve`, `solveset`, $\dots$