Skip to content

Commit

Permalink
added tufte style margin notes
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMSCode committed Nov 5, 2024
1 parent c857f44 commit 9e099ec
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 6 deletions.
8 changes: 6 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
push!(LOAD_PATH, "../src") #make the package available to the script
using Documenter, ClenshawCurtisQuadrature #load the package and Documenter

doctest(ClenshawCurtisQuadrature, fix=true)

#generate the documentation
makedocs(
sitename="ClenshawCurtisQuadrature.jl",
doctest = false, #FIXME: enable once examples are added to the documenation,

doctest = true,
format = Documenter.HTML(assets = ["assets/custom.css"])
)



deploydocs(
repo = "github.com/DavidMSCode/ClenshawCurtisQuadrature.jl.git",
)
42 changes: 42 additions & 0 deletions docs/src/assets/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Custom CSS for Tufte-style margin note */
.admonition.is-info {
position: relative;
float: right;
width: var(--margin-width);
margin-left: 1em;
margin-right: calc(-1*var(--margin-width));
font-size: 0.85em;
color: #ffffff;
background: #ffffff;
padding: 0.5em;
border-style: none !important;
border-width: 0px;
border-left: 2px solid #3852C7 !important;
}

.docstring {
clear: right;
}

.content {
margin-right: var(--margin-width);
margin-left: 0px;
}

:root {
--margin-width: 300px; /* Set the desired width of the margin note */
}

@media screen and (min-width: 1150px) {
html.theme--documenter-dark #documenter .docs-main {
max-width: 1150px;
margin-left: 20rem;
padding-right: 1rem;
}
}

@media screen and (max-width: 1150px) {
html.theme--documenter-dark #documenter .docs-main {
width: 100%;
}
}
85 changes: 81 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,94 @@ and run
The purpose of this module is to numerically solve integrals of the form

```math
F(\tau) = F(-1) + \int_{-1}^{1}f(\tau)d\tau
F(\tau) = F(-1) + \int_{-1}^{\tau}f(\xi)d\xi
```
where ``f(\tau)`` is an integrand that is valid on the domain [-1,1] and
``F(\tau)`` is an antiderivative of the integrand.

!!! note
If ``F(\tau)`` is an antiderivative of ``f(\tau)``, then ``F(\tau)+c`` is
also an antiderivative of ``f(\tau)`` for any constant value ``c``. But, if
``F(-1)`` is known, then there is only one antiderivative that satisfies the
integral.

where ``f(\tau)`` is an integrand that is valid on the domain ``[-1,1]`` and
``F(\tau)`` is an antiderivative of the integrand. This is performed by
representing ``F(\tau)`` and ``f(\tau)`` as a summation of Chebyshev
polynomials on the domain ``[-1,1]``

```math
F(\tau) \approx \sum_{n=0}^N \alpha_n T_n(\tau)
```

```math
f(\tau) \approx \sum_{n=0}^{N-1} a_n T_n(\tau)
```
where ``T_n(\tau)`` is the ``n``-th Chebyshev polynomial of the first kind.
``N`` is the degree of the interpolating polynomial and ``a_n`` and ``\alpha_n``
are the interpolating coefficients of the integrand and the particular
antiderivative respectively. Because the integrals of the Chebyshev polynomials
are related the values of Chebyshev polynomials of higher and lower degrees, we
can perform linear operations on the integrand's coefficients to calculate
the corresponding antiderivative's coefficients. The functions in this module
are designed to generate the matrices required for this quadrature.

## Examples
If we want to know the integral on the domain ``[-1,1]`` of the function
``f(\tau)=\tau^2``, we can do so by first sampling the function at set of M+1
points. Because we know the antiderivative of ``f(\tau)`` is a 3rd order
polynomial, I'll choose ``N=3`` as our desired interpolating polynomial of the
solution. We can sample as many points as we want, but because the integrand
will be represented as a 2nd order polynomial we need at least 3 points to
calculate the coefficients.

To do so first generate the values of ``\tau`` at cosine spaced nodes.
!!! note
Because we just wanted the value of the integral on the range ``[-1,1]``
we assume that ``F(-1)=0``. The next examples will demonstrating solving
an initial value problem when ``F(-1)\neq 0``.

The Ta and T1 matrices returned by clenshaw\_curtis\_ivpi() are also
interpolating matrices. They specifically contain the values of the
chebyshev polynomials needed to interpolate the integrand and
antiderivative at each of the ``M+1`` cosine spaced nodes we calculated
before. Pre-calculating these matrices can be useful for iterative problems
where the integrand is unkown as a function of ``\tau``.

```jldoctest
using ClenshawCurtisQuadrature
#set the degree variables
M = 2
N = 3
#Generate the cosine spaced nodes
Ms = 0:M
taus = cos.(pi*Ms/M)
#Sample the integrand
f = (x) -> x^2
ys = f.(taus)
#Get the Least Squares Operation and Quadrature matrix
A,Ta,P1,T1 = clenshaw_curtis_ivpi(N,M)
#Calculate the least squares fit interpolating polynomial coefficients
a = A*ys
#Apply the quadrature matrix
alpha = P1*a
#Get the interpolating polynomials at τ=1
T = interpolate(1,N)
F1 = T*alpha
# output
1-element Vector{Float64}:
0.6666666666666666
```
The result is that ``\int_{-1}^1 \tau^2d\tau=\frac{2}{3}`` which is exactly the
correct answer.


## Methods

Expand Down

0 comments on commit 9e099ec

Please sign in to comment.