Merge pull request #116 from fangliu-tju/main

update
This commit is contained in:
john verzani 2023-07-21 07:20:17 -04:00 committed by GitHub
commit 7da4532685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 22 deletions

View File

@ -129,7 +129,7 @@ This problem can also be solved using a bracketing method. The package has both
```{julia} ```{julia}
u0 = (1.0, 2.0) u0 = (1.0, 2.0)
prob = NonlinearProblem(f, u0) prob = IntervalNonlinearProblem(f, u0)
``` ```
And And
@ -149,7 +149,7 @@ Incorporating parameters is readily done. For example to solve $f(x) = \cos(x) -
f(x, p) = @. cos(x) - x/p f(x, p) = @. cos(x) - x/p
u0 = (0, pi/2) u0 = (0, pi/2)
p = 2 p = 2
prob = NonlinearProblem(f, u0, p) prob = IntervalNonlinearProblem(f, u0, p)
solve(prob, Bisection()) solve(prob, Bisection())
``` ```
@ -159,7 +159,7 @@ The *insignificant* difference in stopping criteria used by `NonlinearSolve` and
```{julia} ```{julia}
an = solve(NonlinearProblem{false}(f, u0, p), Bisection()) an = solve(IntervalNonlinearProblem{false}(f, u0, p), Bisection())
ar = solve(Roots.ZeroProblem(f, u0), Roots.Bisection(); p=p) ar = solve(Roots.ZeroProblem(f, u0), Roots.Bisection(); p=p)
nextfloat(an[]) == ar, f(an[], p), f(ar, p) nextfloat(an[]) == ar, f(an[], p), f(ar, p)
``` ```
@ -418,7 +418,7 @@ prob = OptimizationProblem(sys, u0, p; grad=true, hess=true)
soln = solve(prob, LBFGS()) soln = solve(prob, LBFGS())
``` ```
We used an initial guess of $x=4$ above. The `LBFGS` method is a computationally efficient modification of the Broyden-Fletcher-Goldfarb-Shanno algorithm ... It is a quasi-Newton method that updates an approximation to the Hessian using past approximations as well as the gradient." On this problem it performs similarly to `Newton`, though in general may be preferable for higher-dimensional problems. We used an initial guess of $x=4$ above. The `LBFGS` method is a computationally efficient modification of the Broyden-Fletcher-Goldfarb-Shanno algorithm. It is a quasi-Newton method that updates an approximation to the Hessian using past approximations as well as the gradient. On this problem it performs similarly to `Newton`, though in general may be preferable for higher-dimensional problems.
### Two dimensional ### Two dimensional
@ -515,7 +515,7 @@ For a simple definite integral, such as $\int_0^\pi \sin(x)dx$, we have:
```{julia} ```{julia}
f(x, p) = sin(x) f(x, p) = sin(x)
prob = IntegralProblem(f, 0.0, pi) prob = IntegralProblem(f, 0.0, 1pi)
soln = solve(prob, QuadGKJL()) soln = solve(prob, QuadGKJL())
``` ```
@ -546,7 +546,7 @@ The `Integrals` solution is a bit more verbose, but it is more flexible. For exa
```{julia} ```{julia}
f(x, p) = sin.(x) f(x, p) = sin.(x)
prob = IntegralProblem(f, [0.0], [pi]) prob = IntegralProblem(f, [0.0], [1pi])
soln = solve(prob, HCubatureJL()) soln = solve(prob, HCubatureJL())
``` ```
@ -574,7 +574,7 @@ Consider $d/dp \int_0^\pi \sin(px) dx$. We can do this integral directly to get
\frac{d}{dp} \int_0^\pi \sin(px)dx \frac{d}{dp} \int_0^\pi \sin(px)dx
&= \frac{d}{dp}\left( \frac{-1}{p} \cos(px)\Big\rvert_0^\pi\right)\\ &= \frac{d}{dp}\left( \frac{-1}{p} \cos(px)\Big\rvert_0^\pi\right)\\
&= \frac{d}{dp}\left( -\frac{\cos(p\cdot\pi)-1}{p}\right)\\ &= \frac{d}{dp}\left( -\frac{\cos(p\cdot\pi)-1}{p}\right)\\
&= \frac{\cos(p\cdot \pi) - 1)}{p^2} + \frac{\pi\cdot\sin(p\cdot\pi)}{p} &= \frac{\cos(p\cdot \pi) - 1}{p^2} + \frac{\pi\cdot\sin(p\cdot\pi)}{p}
\end{align*} \end{align*}
Using `Integrals` with `QuadGK` we have: Using `Integrals` with `QuadGK` we have:
@ -583,7 +583,7 @@ Using `Integrals` with `QuadGK` we have:
```{julia} ```{julia}
f(x, p) = sin(p*x) f(x, p) = sin(p*x)
function ∫sinpx(p) function ∫sinpx(p)
prob = IntegralProblem(f, 0.0, pi, p) prob = IntegralProblem(f, 0.0, 1pi, p)
solve(prob, QuadGKJL()) solve(prob, QuadGKJL())
end end
``` ```
@ -614,7 +614,7 @@ The power of a common interface is the ability to swap backends and the uniformi
#### $f: R^n \rightarrow R$ #### $f: R^n \rightarrow R$
The area under a surface generated by $z=f(x,y)$ over a rectangular region $[a,b]\times[c,d]$ can be readily computed. The two coding implementations require $f$ to be expressed as a function of a vector*and* a parameterand the interval to be expressed using two vectors, one for the left endpoints (`[a,c]`) and on for the right endpoints (`[b,d]`). The area under a surface generated by $z=f(x,y)$ over a rectangular region $[a,b]\times[c,d]$ can be readily computed. The two coding implementations require $f$ to be expressed as a function of a vector*and* a parameterand the interval to be expressed using two vectors, one for the left endpoints (`[a,c]`) and one for the right endpoints (`[b,d]`).
For example, the area under the function $f(x,y) = 1 + x^2 + 2y^2$ over $[-1/2, 1/2] \times [-1,1]$ is computed by: For example, the area under the function $f(x,y) = 1 + x^2 + 2y^2$ over $[-1/2, 1/2] \times [-1,1]$ is computed by:
@ -664,7 +664,7 @@ To compute this transformed integral, we might have:
```{julia} ```{julia}
function vol_sphere(ρ) function vol_sphere(ρ)
f(rθ, p) = sqrt(ρ^2 - rθ[1]^2) * rθ[1] f(rθ, p) = sqrt(ρ^2 - rθ[1]^2) * rθ[1]
ls = [0,0] ls = [0.0,0.0]
rs = [ρ, 2pi] rs = [ρ, 2pi]
prob = IntegralProblem(f, ls, rs) prob = IntegralProblem(f, ls, rs)
solve(prob, HCubatureJL()) solve(prob, HCubatureJL())
@ -677,7 +677,7 @@ If it is possible to express the region to integrate as $G(R)$ where $R$ is a re
$$ $$
\iint_{G(R)} f(x) dA = \iint_R (f\circ G)(u) |det(J_G(u)| dU \iint_{G(R)} f(x) dA = \iint_R (f\circ G)(u) |det(J_G(u))| dU
$$ $$
turns the integral into the non-rectangular domain $G(R)$ into one over the rectangular domain $R$. The key is to *identify* $G$ and to compute the Jacobian. The latter is simply accomplished with `ForwardDiff.jacobian`. turns the integral into the non-rectangular domain $G(R)$ into one over the rectangular domain $R$. The key is to *identify* $G$ and to compute the Jacobian. The latter is simply accomplished with `ForwardDiff.jacobian`.

View File

@ -15,7 +15,7 @@ The [Makie.jl webpage](https://github.com/JuliaPlots/Makie.jl) says
:::{.callout-note} :::{.callout-note}
## Examples and tutorials ## Examples and tutorials
`Makie` is a sophisticated plotting package, and capable of an enormous range of plots (cf. [examples](https://makie.juliaplots.org/stable/examples/plotting_functions/).) `Makie` also has numerous [tutorials](https://makie.juliaplots.org/stable/tutorials/) to learn from. These are far more extensive that what is described herein, as this section focuses just on the graphics from calculus. `Makie` is a sophisticated plotting package, and capable of an enormous range of plots (cf. [examples](https://makie.juliaplots.org/stable/examples/plotting_functions/).) `Makie` also has numerous [tutorials](https://makie.juliaplots.org/stable/tutorials/) to learn from. These are far more extensive than what is described herein, as this section focuses just on the graphics from calculus.
::: :::
@ -186,7 +186,7 @@ The curves of calculus are lines. The `lines` command of `Makie` will render a c
The basic plot of univariate calculus is the graph of a function $f$ over an interval $[a,b]$. This is implemented using a familiar strategy: produce a series of representative values between $a$ and $b$; produce the corresponding $f(x)$ values; plot these as points and connect the points with straight lines. The basic plot of univariate calculus is the graph of a function $f$ over an interval $[a,b]$. This is implemented using a familiar strategy: produce a series of representative values between $a$ and $b$; produce the corresponding $f(x)$ values; plot these as points and connect the points with straight lines.
To create regular values between `a` and `b` typically the `range` function or the range operator (`a:h:b`) are employed. The the related `LinRange` function is also an option. To create regular values between `a` and `b` typically the `range` function or the range operator (`a:h:b`) are employed. The related `LinRange` function is also an option.
For example: For example:

View File

@ -149,7 +149,7 @@ The difference is solely the specification of the `mode` value, for a line plot
### Nothing ### Nothing
The line graph plays connect-the-dots with the points specified by paired `x` and `y` values. *Typically*, when and `x` value is `NaN` that "dot" (or point) is skipped. However, `NaN` doesn't pass through the JSON conversion `nothing` can be used. The line graph plays connect-the-dots with the points specified by paired `x` and `y` values. *Typically*, when `x` value is `NaN` that "dot" (or point) is skipped. However, `NaN` doesn't pass through the JSON conversion `nothing` can be used.
```{julia} ```{julia}
@ -381,17 +381,17 @@ In the following, to highlight the difference between $f(x) = \cos(x)$ and $p(x)
xs = range(-1, 1, 100) xs = range(-1, 1, 100)
data = [ data = [
Config( Config(
x=xs, y=cos.(xs),
fill = "tonexty",
fillcolor = "rgba(0,0,255,0.25)", # to get transparency
line = Config(color=:blue)
),
Config(
x=xs, y=[1 - x^2/2 for x ∈ xs ], x=xs, y=[1 - x^2/2 for x ∈ xs ],
fill = "tozeroy", fill = "tozeroy",
fillcolor = "rgba(255,0,0,0.25)", # to get transparency fillcolor = "rgba(255,0,0,0.25)", # to get transparency
line = Config(color=:red) line = Config(color=:red)
) ),
Config(
x=xs, y=cos.(xs),
fill = "tonexty",
fillcolor = "rgba(0,0,255,0.25)", # to get transparency
line = Config(color=:blue)
)
] ]
Plot(data) Plot(data)
``` ```
@ -428,7 +428,7 @@ lyt = Config(title = "Main chart title",
Plot(data, lyt) Plot(data, lyt)
``` ```
The `xaxis` and `yaxis` keys have many customizations. For example: `nticks` specifies the maximum number of ticks; `range` to set the range of the axis; `type` to specify the axis type from "linear", "log", "date", "category", or "multicategory;" and `visible` The `xaxis` and `yaxis` keys have many customizations. For example: `nticks` specifies the maximum number of ticks; `range` to set the range of the axis; `type` to specify the axis type from "linear", "log", "date", "category", or "multicategory"; and `visible`.
The aspect ratio of the chart can be set to be equal through the `scaleanchor` key, which specifies another axis to take a value from. For example, here is a parametric plot of a circle: The aspect ratio of the chart can be set to be equal through the `scaleanchor` key, which specifies another axis to take a value from. For example, here is a parametric plot of a circle: