# \#quadgk

**URL:** https://discourse.julialang.org/tag/quadgk/575.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Type instability in nested quadgk calls](https://discourse.julialang.org/t/type-instability-in-nested-quadgk-calls/126667)

<div class="topic-metadata">

**Author:** [@mbasquens](https://discourse.julialang.org/u/mbasquens)\
**Replies:** 26\
**Last updated:** [March 10, 2025, 6:44pm UTC](https://discourse.julialang.org/t/type-instability-in-nested-quadgk-calls/126667 "2025-03-10T18:44:52Z")

</div>

Hi! I am having trouble with the type stability of quadgk when the integrand function is using quadgk itself. Here is the MWE: using QuadGK f(x) = quadgk(y -\> x\*y, 0., 1.)\[1\] quadgk(f, 0., 1.) Using code\_warntype on t…

---

## [Kronrod error when using QuadGK w/ symbolic inputs](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587)

<div class="topic-metadata">

**Author:** [@JarodMcCormick](https://discourse.julialang.org/u/JarodMcCormick)\
**Replies:** 4\
**Last updated:** [March 7, 2025, 6:30pm UTC](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587 "2025-03-07T18:30:14Z")

</div>

I am running a script where I’m calculating some values using ModelingToolkit with some code that I’ve developed. I register my functions using the @register\_symbolic macro, and these functions work on their own through …

---

## [Arc length for a spline](https://discourse.julialang.org/t/arc-length-for-a-spline/36161)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 27\
**Last updated:** [February 7, 2025, 8:04am UTC](https://discourse.julialang.org/t/arc-length-for-a-spline/36161 "2025-02-07T08:04:11Z")

</div>

Given some spline (e.g. Dierckx.jl, Interpolations.jl), is there a good way to get its arc length? Right now I’m using this: using LinearAlgebra, Dierckx t = range(0, stop = π, length = 100) x = cos.(t) y = sin.(t) spl…

---

## [Optimization with integrals in both objective and the constraint](https://discourse.julialang.org/t/optimization-with-integrals-in-both-objective-and-the-constraint/113838)

<div class="topic-metadata">

**Author:** [@Ayesha](https://discourse.julialang.org/u/Ayesha)\
**Replies:** 9\
**Last updated:** [May 9, 2024, 11:54pm UTC](https://discourse.julialang.org/t/optimization-with-integrals-in-both-objective-and-the-constraint/113838 "2024-05-09T23:54:36Z")

</div>

I’m trying to optimize a function that has an integral in the objective. While I can perform unconstrained optimization, I’m unsure how to use the Julia optimizer. I am trying to do this to add a constraint later, which …

---

## [QuadGK unexpected behavior on first degree polynomial](https://discourse.julialang.org/t/quadgk-unexpected-behavior-on-first-degree-polynomial/113134)

<div class="topic-metadata">

**Author:** [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Replies:** 2\
**Last updated:** [April 18, 2024, 2:25pm UTC](https://discourse.julialang.org/t/quadgk-unexpected-behavior-on-first-degree-polynomial/113134 "2024-04-18T14:25:34Z")

</div>

I constructed a tiny example on which my (naive?) use of the quadgk() fails. The example is a first order polynomial in x and y on the triangular domain with vertices (0,0), (1,0) and (0,1). Below a working and failing M…

---

## [Why does "QuadGK.jl" not behave the same as "Integrals.jl with QuadGKJL()"](https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795)

<div class="topic-metadata">

**Author:** [@Laura](https://discourse.julialang.org/u/Laura)\
**Replies:** 3\
**Last updated:** [February 29, 2024, 7:08am UTC](https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795 "2024-02-29T07:08:36Z")

</div>

I am writing a program to perform a spherical Bessel transformation which requires some one dimensional integrals but I am having some trouble with the Integrals.jl package. Naturally my first attempt to do this was to …

---

## [Error in dblquad integration with Unitful and MonteCarloMeasurements](https://discourse.julialang.org/t/error-in-dblquad-integration-with-unitful-and-montecarlomeasurements/110420)

<div class="topic-metadata">

**Author:** [@GSavvidis](https://discourse.julialang.org/u/GSavvidis)\
**Replies:** 5\
**Last updated:** [February 22, 2024, 7:00pm UTC](https://discourse.julialang.org/t/error-in-dblquad-integration-with-unitful-and-montecarlomeasurements/110420 "2024-02-22T19:00:05Z")

</div>

Hello everyone, This is my first post so apologies in advance for any mistakes in the question format. I have been trying to calculate an integral of two variables using dblquad. The function to be integrated contains …

---

## [How to improve the implementation of a function involving a numerical integration?](https://discourse.julialang.org/t/how-to-improve-the-implementation-of-a-function-involving-a-numerical-integration/105444)

<div class="topic-metadata">

**Author:** [@lsablon](https://discourse.julialang.org/u/lsablon)\
**Replies:** 7\
**Last updated:** [October 27, 2023, 4:10am UTC](https://discourse.julialang.org/t/how-to-improve-the-implementation-of-a-function-involving-a-numerical-integration/105444 "2023-10-27T04:10:03Z")

</div>

Hello, I am trying to optimize my code, but I don’t really know in which direction I should go (but I know I don’t want to use multithreading). Here is my goal: I want to implement the following function k\_\\perp(x,y;…

---

## [QuadGK returns NaNs](https://discourse.julialang.org/t/quadgk-returns-nans/105308)

<div class="topic-metadata">

**Author:** [@aner-sanchez](https://discourse.julialang.org/u/aner-sanchez)\
**Replies:** 4\
**Last updated:** [October 24, 2023, 1:24pm UTC](https://discourse.julialang.org/t/quadgk-returns-nans/105308 "2023-10-24T13:24:46Z")

</div>

Hello everyone :slight\_smile: Would someone know why using QuadGK n = 538 \_, w, \_ = kronrod(n,1e-11,40); @show w returns a vector of NaN weights at n=538 and not before?

---

## [How to evaluate a complex function between complex bounds](https://discourse.julialang.org/t/how-to-evaluate-a-complex-function-between-complex-bounds/102460)

<div class="topic-metadata">

**Author:** [@AkchurinDA](https://discourse.julialang.org/u/AkchurinDA)\
**Replies:** 2\
**Last updated:** [August 3, 2023, 10:43pm UTC](https://discourse.julialang.org/t/how-to-evaluate-a-complex-function-between-complex-bounds/102460 "2023-08-03T22:43:21Z")

</div>

I’m having trouble evaluating the following expression that contains an integral with a complex function with complex bounds. In this expression, \\phi() is the PDF of a standard normal distribution, \\beta is a number…

---

## [Using Numerical Integration and ApproxFun in Turing.jl](https://discourse.julialang.org/t/using-numerical-integration-and-approxfun-in-turing-jl/101850)

<div class="topic-metadata">

**Author:** [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Replies:** 12\
**Last updated:** [July 21, 2023, 5:13pm UTC](https://discourse.julialang.org/t/using-numerical-integration-and-approxfun-in-turing-jl/101850 "2023-07-21T17:13:09Z")

</div>

I’m trying to write some code to “show how it works” when it comes to imposing high quality prior information on a Bayesian regression problem. I’m running into implementation issues and could use some thoughts @stevengj …

---

## [Domain error with QuadGK to derive Caputo derivative](https://discourse.julialang.org/t/domain-error-with-quadgk-to-derive-caputo-derivative/96550)

<div class="topic-metadata">

**Author:** [@khaledharizb](https://discourse.julialang.org/u/khaledharizb)\
**Replies:** 2\
**Last updated:** [March 24, 2023, 3:57pm UTC](https://discourse.julialang.org/t/domain-error-with-quadgk-to-derive-caputo-derivative/96550 "2023-03-24T15:57:06Z")

</div>

Hi everyone! I’m trying to evaluate caputo derivative using Quadgk. It works unless when t=3 it gives me Domain error. With Mathematica I got the value -3.11522 using QuadGK, ForwardDiff, SpecialFunctions f(t)=t^2\*sin(t…

---

## [QuadGK Computation Question](https://discourse.julialang.org/t/quadgk-computation-question/92983)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 8\
**Last updated:** [January 16, 2023, 12:01pm UTC](https://discourse.julialang.org/t/quadgk-computation-question/92983 "2023-01-16T12:01:27Z")

</div>

Hi all, I have tried QuadGK, but the result is not the same as the solution manual. Is there a problem in between? this is my code: using SymPy, QuadGK x = symbols("x") f(x) = (x^6 + 2)/(8x^2) # simplify(diff(f(x),…

---

## [Unreasonable slow speed in numerical integration](https://discourse.julialang.org/t/unreasonable-slow-speed-in-numerical-integration/89910)

<div class="topic-metadata">

**Author:** [@swish47](https://discourse.julialang.org/u/swish47)\
**Replies:** 16\
**Last updated:** [November 12, 2022, 7:15pm UTC](https://discourse.julialang.org/t/unreasonable-slow-speed-in-numerical-integration/89910 "2022-11-12T19:15:45Z")

</div>

I hope to compute an intergration of a function with intergration inside, however the efficiency is extremely slow. using HCubature,QuadGK,NumericalIntegration spinonenergy(kx::Float64,ky::Float64)::Float64=2\*(cos(kx)+c…

---

## [When Zygote.jl meets Quadgk.jl: Mutating arrays is not supported -- called setindex!(::Vector{QuadGK.Segment})](https://discourse.julialang.org/t/when-zygote-jl-meets-quadgk-jl-mutating-arrays-is-not-supported-called-setindex-vector-quadgk-segment/84042)

<div class="topic-metadata">

**Author:** [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Replies:** 6\
**Last updated:** [July 12, 2022, 5:14am UTC](https://discourse.julialang.org/t/when-zygote-jl-meets-quadgk-jl-mutating-arrays-is-not-supported-called-setindex-vector-quadgk-segment/84042 "2022-07-12T05:14:15Z")

</div>

I have a problem calculating the derivative of a function that involves an integral operation. Examples are as follows: using QuadGK using Zygote function test() f(t)=quadgk(x-\>sin(x)\*exp(t\*cos(x)) , 0, pi, atol=1…

---

## [Is Julia integral calculation not as fast as MATLAB?](https://discourse.julialang.org/t/is-julia-integral-calculation-not-as-fast-as-matlab/79824)

<div class="topic-metadata">

**Author:** [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Replies:** 20\
**Last updated:** [April 22, 2022, 2:08pm UTC](https://discourse.julialang.org/t/is-julia-integral-calculation-not-as-fast-as-matlab/79824 "2022-04-22T14:08:34Z")

</div>

I found it was slow when I used QuadGK.jl to do integral calculation. Then I used MATLAB to make a comparison and found that Julia integral was slower than MATLAB. Here are my comparisons: julia\> using QuadGK julia\> f(…

---

## [NaN returned by gauss()](https://discourse.julialang.org/t/nan-returned-by-gauss/68260)

<div class="topic-metadata">

**Author:** [@trg818](https://discourse.julialang.org/u/trg818)\
**Replies:** 6\
**Last updated:** [September 16, 2021, 7:33pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260 "2021-09-16T19:33:37Z")

</div>

I’m using the function gauss() from QuadGK in order to calculate a non-adaptive quadrature and am irritated about the appearance of NaN beyond a certain N. Specifically, gauss(1093,38.68598671891722,150000.0) returns an …

---

## [Integrand produced a NaN. Domain error using QuadGK](https://discourse.julialang.org/t/integrand-produced-a-nan-domain-error-using-quadgk/60287)

<div class="topic-metadata">

**Author:** [@leopdsf](https://discourse.julialang.org/u/leopdsf)\
**Replies:** 3\
**Last updated:** [April 30, 2021, 3:37am UTC](https://discourse.julialang.org/t/integrand-produced-a-nan-domain-error-using-quadgk/60287 "2021-04-30T03:37:10Z")

</div>

Hello, everyone. I’m trying to solve numerically the following integral: \\int \_{-\\infty} ^{\\infty} \\exp(-z^2/2)\\ln(2\\cosh(z)) dz = 2.67636. For that, I write the following using QuadGK f3(z) = exp(-z^2/2)\*log(2\*cosh…

---

## [Plot integrals](https://discourse.julialang.org/t/plot-integrals/54087)

<div class="topic-metadata">

**Author:** [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Replies:** 6\
**Last updated:** [January 27, 2021, 11:27pm UTC](https://discourse.julialang.org/t/plot-integrals/54087 "2021-01-27T23:27:53Z")

</div>

I can plot derivatives using ForwardDiff and Plots using ForwardDiff using Plots f(x)=x^2 df(x)=ForwardDiff.derivative(f(x), x) plot(df) but QuadGK.jl gives two answers so this method won’t work. Is there a way to pl…
