Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Dec 21, 2023
2 parents 55faf70 + 05cb1cc commit 6761f4d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "CalculusWithJulia"
uuid = "a2e0e22d-7d4c-5312-9169-8b992201a882"
version = "0.1.1"
version = "0.1.4"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -21,16 +21,16 @@ SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Contour = "0.5"
Contour = "0.5, 0.6"
ForwardDiff = "0.10"
HCubature = "1"
IntervalSets = "0.5"
IntervalSets = "0.5, 0.6, 0.7"
JSON = "0.10, 0.20, 0.21, 1"
PlotUtils = "1"
RecipesBase = "0.7, 0.8, 1.0"
Reexport = "1"
Requires = "1"
Roots = "1, 2"
SpecialFunctions = "1"
SpecialFunctions = "1, 2"
SplitApplyCombine = "1"
julia = "1"
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
`Julia` package to provide notes and features for using `Julia` to address typical problems from the undergraduate calculus sequence.


The notes may be read at [Calculus with Julia](http://juliahub.com/docs/CalculusWithJulia).
The notes may be read at [calculuswithjulia.github.io](calculuswithjulia.github.io). Any suggested edits for the notes should be in a pull request to the repository [https://github.com/jverzani/CalculusWithJuliaNotes.jl/](https://github.com/jverzani/CalculusWithJuliaNotes.jl/).

The notes expect that this package is installed, as it also provides a handful of conveniences for the task.

In addition to the html pages, there are other versions of the same material that can be generated, such as `ipynb` notebooks or `pdf` files. See the `runtests.jl` file for details.

The notes may be read at [calculuswithjulia.github.io](https://calculuswithjulia.github.io).


## Contributing

This is a work in progress. To report an issue, make a comment, or suggest something new, please file an [issue](https://github.com/jverzani/CalculusWithJulia.jl/issues/). In your message add the tag `@jverzani` to ensure it is not overlooked. Otherwise, an email to `verzani` at `math.csi.cuny.edu` will also work.

To make edits to the documents directly, a pull request with the modified `*.jmd` files in the `CwJ` directory should be made. Minor edits to the `*.jmd` files should be possible through the GitHub web interface. The `*.html` files are generated using `Julia's` `Weave` package. This need not be done.
The accompanying notes have their own edit feature.
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
Documenter = "1"
16 changes: 11 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using Documenter, CalculusWithJulia
using Documenter
using CalculusWithJulia

makedocs(
sitename="Calculus with Julia",
format = Documenter.HTML(),
modules = [CalculusWithJulia],
warnonly = Documenter.except(:autodocs_block)
)

makedocs(sitename="Calculus with Julia")

# Documenter can also automatically deploy documentation to gh-pages.
# See "Hosting Documentation" and deploydocs() in the Documenter manual
# for more information.

import Documenter
Documenter.deploydocs(
repo = "github.com/jverzani/CalculusWithJulia.jl"
deploydocs(
repo = "github.com/jverzani/CalculusWithJulia.jl.git"
)
4 changes: 3 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CalculusWithJulia.jl

Documentation for [CalculusWithJulia.jl](https://github.com/jverzani/CalculusWithJulia.jl), a package to accompany the notes [calculuswithjulia.github.io](https://calculuswithjulia.github.io) for using `Julia` for Calculus.
Documentation for [CalculusWithJulia.jl](https://github.com/jverzani/CalculusWithJulia.jl), a package to accompany the notes "Calculus with Julia" for using `Julia` for Calculus.

To suggest corrections to the notes, please submit a pull request to [https://github.com/jverzani/CalculusWithJuliaNotes.jl/](https://github.com/jverzani/CalculusWithJuliaNotes.jl/). The [Quarto](https://quarto.org/) pages makes this easy, as they have an "Edit this page" link.

----

Expand Down
4 changes: 2 additions & 2 deletions src/CalculusWithJulia.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
CalculusWithJulia
A package to accompany [notes](calculuswithjulia.github.io) on using Julia with calculus.
A package to accompany notes at [https://calculuswithjulia.github.io](https://calculuswithjulia.github.io) on using Julia for topics from the calculus sequence.
This package does two things:
Expand Down Expand Up @@ -79,7 +79,7 @@ function __init__()
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("plots.jl") # could deprecate...
end

e = exp(1)
const e = exp(1)
export e

export unzip, rangeclamp
Expand Down
68 changes: 56 additions & 12 deletions src/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,63 @@ riemann(f, 0, 1, 1000, method="simpsons") # use Simpson's rule
"""
function riemann(f::Function, a::Real, b::Real, n::Int; method="right")
if method == "right"
meth = f -> (lr -> begin l,r = lr; f(r) * (r-l) end)
elseif method == "left"
meth = f -> (lr -> begin l,r = lr; f(l) * (r-l) end)
elseif method == "trapezoid"
meth = f -> (lr -> begin l,r = lr; (1/2) * (f(l) + f(r)) * (r-l) end)
elseif method == "simpsons"
meth = f -> (lr -> begin l,r=lr; (1/6) * (f(l) + 4*(f((l+r)/2)) + f(r)) * (r-l) end)
Ms = (left = (f,a,b) -> f(a),
right= (f,a,b) -> f(b),
mid = (f,a,b) -> f(a/2 + b/2),
= (f,a,b) -> first(findmin(f, range(a,b,10))),
= (f,a,b) -> first(findmax(f, range(a,b,10))),
trapezoid = (f,a,b) -> (f(a) + f(b))/2,
simpsons = (f,a,b) -> (c = a/2 + b/2;(1/6) * (f(a) + 4*f(c) + f(b))),
ct = (f,a,b)-> (c = a/2+b/2; (f(a)+f(b))/2 + 1/12 * (f'(b)-f'(a))*(b-a))
)

F = Ms[Symbol(method)]
xs = range(a, b, n+1)
xs′ = zip(Iterators.take(xs, n), Iterators.drop(xs, 1))
sum(F(f, xᵢ₋₁, xᵢ) * (xᵢ-xᵢ₋₁) for (xᵢ₋₁, xᵢ) xs′)
end


xs = range(a, b, n+1)
pairs = zip(xs[begin:end-1], xs[begin+1:end]) # (x₀,x₁), …, (xₙ₋₁,xₙ)
sum(meth(f), pairs)
"""
fubini(f, [zs], [ys], xs; rtol=missing, kws...)
Integrate `f` of 1, 2, or 3 input variables.
The zs may depend (x,y), the ys may depend on x
## Examples
```
# integrate over the unit square
fubini((x,y) -> sin(x-y), (0,1), (0,1))
# integrate over a triangle
fubini((x,y) -> 1, (0,identity), (0,1 ))
#
f(x,y,z) = x*y^2*z^3
fubini(f, (0,(x,y) -> x+ y), (0, x -> x), (0,1))
```
Note: This code relies on `quadgk` which isn't loaded in this package. It won't run unless defined elsewhere, say by copy-and-paste.
Note: This uses nested calls to `quadgk`. The use of `hcubature` is recommended, typically after a change of variables to make a rectangular domain. The relative tolerance increases at each nested level.
"""
fubini(@nospecialize(f), dx; rtol=missing, kws...) =
quadgk(f, dx...; rtol=first(skipmissing((rtol, nothing))), kws...)[1]

fubini(@nospecialize(f), ys, xs; rtol=missing, kws...) =
fubini(x -> fubini(y -> f(x,y), endpoints(ys, x); rtol=rtol), xs;
rtol = 10*rtol, kws...)

fubini(@nospecialize(f), zs, ys, xs; rtol=missing, kws...) =
fubini(x ->
fubini(y ->
fubini(z -> f(x,y,z), endpoints(zs, (x,y));
rtol=10*10*rtol, kws...),
endpoints(ys,x);
rtol = 10*rtol),

xs;
rtol=rtol)

end
endpoints(ys,x) = ((f,x) -> isa(f, Function) ? f(x...) : f).(ys, Ref(x))
6 changes: 3 additions & 3 deletions src/multidimensional.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# helpful bits for working with n ≥ 2

"""
`unzip(vs)`
`unzip(v1, v2, ...)`
`unzip(r::Function, a, b)`
unzip(vs)
unzip(v1, v2, ...)
unzip(r::Function, a, b)
Take a vector of points described by vectors (as returned by, say
`r(t)=[sin(t),cos(t)], r.([1,2,3])`, and return a tuple of collected x
Expand Down
9 changes: 6 additions & 3 deletions src/sympy.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
gradient(ex::SymPy.Sym, vars::AbstractArray=SymPy.free_symbols(ex)) = diff.(ex, [vars...])
divergence(F::Vector{SymPy.Sym}, vars=SymPy.free_symbols(F)) = sum(diff.(F, vars))
curl(F::Vector{SymPy.Sym}, vars=SymPy.free_symbols(F)) = curl(F.jacobian(vars))
gradient(ex::SymPy.Sym, vars::AbstractArray=SymPy.free_symbols(ex)) =
diff.(ex, [vars...])
divergence(F::Vector{<:SymPy.Sym}, vars=SymPy.free_symbols(F)) =
sum(diff.(F, vars))
curl(F::Vector{<:SymPy.Sym}, vars=SymPy.free_symbols(F)) =
curl(F.jacobian(vars))

0 comments on commit 6761f4d

Please sign in to comment.