Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate Steven's comments #2

Merged
merged 5 commits into from
Dec 24, 2016
Merged

Incorporate Steven's comments #2

merged 5 commits into from
Dec 24, 2016

Conversation

ararslan
Copy link
Member

I'll put all of the requested changes into this PR so that it can be tagged once this is merged.

Fixes #1

gauss([T,] N)

Return a pair `(x, w)` of `N` quadrature points `x[i]` and weights `w[i]` to
integrate functions on the interval `(-1, 1)`, i.e. `dot(f(x), w)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dot(w, f.(x)), so that you don't conjugate f. Or sum(w .* f.(x)) is probably more natural here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`T` is an optional parameter specifying the floating-point type, defaulting to `Float64`.
Arbitrary precision (`BigFloat`) is also supported.

Return a pair `(x, w)` of `N` quadrature points `x[i]` and weights `w[i]` to
integrate functions on the interval `(-1, 1)`, i.e. `dot(f(x), w)`
approximates the integral. Uses the method described in Trefethen &
Bau, Numerical Linear Algebra, to find the `N`-point Gaussian quadrature.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... in O(N²) operations

Since the rule is symmetric, this only returns the `n+1` points with `x <= 0`.
The function Also computes the embedded `n`-point Gauss quadrature weights `gw`
(again for `x <= 0`), corresponding to the points `x[2:2:end]`. Returns `(x,w,wg)`.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given these points and weights, the estimated integral `I` and error `E` can be computed for an
integrand `f(x)` as follows:

    x,w,wg = kronrod(n)
    fx⁰ = f(x[end])      # f(0)
    x⁻ = x[1:end-1]     # the x < 0 Kronrod points
    fx = f.(x⁻) .+ f.((-).(x⁻))    # f(x < 0) + f(x > 0)
    I = sum(fx .* w[1:end-1]) + fx⁰ * w[end]
    if isodd(n)
        E = abs(sum(fx[2:2:end] .* wg[1:end-1]) + fx⁰*wg[end] - I)
    else
        E = abs(sum(fx[2:2:end] .* wg[1:end])- I)
    end

Also, should have a similar comment to above explaining T and noting that it is O(N^2).

@stevengj
Copy link
Member

See also my suggestion on the kronrod docstring.

@ararslan
Copy link
Member Author

How are things looking now?

@stevengj
Copy link
Member

Shouldn't docs/src/index.md be updated to pull in the new docstrings?

@ararslan
Copy link
Member Author

Good call, thanks!

@stevengj
Copy link
Member

LGTM

@ararslan
Copy link
Member Author

Fantastic. Thanks for all your help!

@ararslan ararslan merged commit 1094910 into master Dec 24, 2016
@ararslan ararslan deleted the aa/updates branch December 24, 2016 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants