Skip to content

Large error when integrating around point of discontinuity #269

@flin2

Description

@flin2

Describe the bug 🐞

The numerical solution has a large discrepancy from the analytical solution when the bound is close to the point of discontinuity.

Expected behavior

I expect the difference should be really small (much smaller than 0.00059).

Minimal Reproducible Example 👇

using Integrals

function f(x)
    if x < 1
        return exp(x)
    elseif x >=1
        return exp(2x)
    end
end

function F(x0, x1)
    if x0 < 1 && x1 < 1
        return exp(x1) - exp(x0)
    elseif x0 < 1 && x1 >= 1
        return exp(2x1) / 2 - exp(2) / 2 + exp(1) - exp(x0)
    elseif x0 >= 1 && x1 >= 1
        return exp(2x1) / 2 - exp(2x0) / 2
    end
end


x0 = 0.997
x1 = 2.0

prob = IntegralProblem((x,p) -> f(x), (x0,x1))
sol1 = solve(prob, QuadGKJL(), reltol=1e-12, abstol=1e-12).u
sol0 = F(x0, x1)

sol1 - sol0
(sol1 - sol0) ./ sol0

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
[de52edbc] Integrals v4.6.0
  • Output of versioninfo()
Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 14 × Apple M4 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 10 virtual cores)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions