# Kronrod error when using QuadGK w/ symbolic inputs

**URL:** <https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit, quadgk, symbolics\
**Created:** [March 5, 2025, 4:20pm UTC](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587 "2025-03-05T16:20:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JarodMcCormick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jarodmccormick/32/212396_2.png) [@JarodMcCormick](https://discourse.julialang.org/u/JarodMcCormick)\
**Post date:** [March 5, 2025, 4:20pm UTC](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587/1 "2025-03-05T16:20:43Z")

</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 regular use and test. But when I run the following line to create an equation for ModelingToolkit, I get this error:

julia\> eqs = [stream\_enthalpy(stream1; T=Tval) - stream\_enthalpy(stream1) ~ stream\_delta\_heat\_capacity(stream1, Tval)]  
ERROR: MethodError: no method matching kronrod(::Type{Num}, ::Int64)  
The function `kronrod` exists, but no method is defined for this combination of argument types.

Closest candidates are:  
kronrod(::Any, ::Integer, ::Real, ::Real; rtol, quad)  
@ QuadGK ~/.julia/packages/QuadGK/7rND3/src/weightedgauss.jl:90  
kronrod(::Type{T}, ::Integer) where T\<:AbstractFloat  
@ QuadGK ~/.julia/packages/QuadGK/7rND3/src/gausskronrod.jl:337  
kronrod(::AbstractMatrix{\<:Real}, ::Integer, ::Real, ::Pair{\<:Tuple{Real, Real}, \<:Tuple{Real, Real}})  
@ QuadGK ~/.julia/packages/QuadGK/7rND3/src/gausskronrod.jl:411  
…

Stacktrace:  
[1] macro expansion  
@ ~/.julia/packages/QuadGK/7rND3/src/gausskronrod.jl:618 [inlined]  
[2] \_cachedrule(::Type{Num}, n::Int64)  
@ QuadGK ~/.julia/packages/QuadGK/7rND3/src/gausskronrod.jl:618  
[3] cachedrule(::Type{Num}, n::Int64)  
@ QuadGK ~/.julia/packages/QuadGK/7rND3/src/gausskronrod.jl:626  
[4] do\_quadgk(f::ProcessCalc.var"#39#43"{…}, s::Tuple{…}, n::Int64, atol::Nothing, rtol::Nothing, maxevals::Int64, nrm::typeof(LinearAlgebra.norm), \_segbuf::Nothing, eval\_segbuf::Nothing)  
@ QuadGK ~/.julia/packages/QuadGK/7rND3/src/adapt.jl:19  
[5] #50  
@ ~/.julia/packages/QuadGK/7rND3/src/api.jl:83 [inlined]  
[6] handle\_infinities  
@ ~/.julia/packages/QuadGK/7rND3/src/adapt.jl:189 [inlined]  
[7] #quadgk#49  
@ ~/.julia/packages/QuadGK/7rND3/src/api.jl:82 [inlined]  
[8] quadgk  
@ ~/.julia/packages/QuadGK/7rND3/src/api.jl:80 [inlined]  
[9] quadgk  
@ ~/.julia/packages/QuadGK/7rND3/src/api.jl:77 [inlined]  
[10] stream\_delta\_heat\_capacity(stream::FlowStream{RK{…}, Nothing}, outlet\_temperature::Num)  
@ ProcessCalc ~/.julia/dev/ProcessCalc/src/base/streams.jl:359  
[11] top-level scope  
@ REPL[23]:1  
Some type information was truncated. Use `show(err)` to see complete types.

Does anyone have any ideas? It doesn’t seem like the error is coming from my code.

---

<div class="post-metadata">

**Author:** ![JarodMcCormick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jarodmccormick/32/212396_2.png) [@JarodMcCormick](https://discourse.julialang.org/u/JarodMcCormick)\
**Post date:** [March 5, 2025, 4:25pm UTC](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587/2 "2025-03-05T16:25:50Z")

</div>

To give some extra context, this is what Claude 3.7 is giving me on this:

This is occurring because:

- You’re trying to use stream\_delta\_heat\_capacity with a symbolic variable (Tval of type Num from Symbolics.jl) as the outlet temperature

- Inside stream\_delta\_heat\_capacity, the quadgk function is trying to perform numerical integration with this symbolic variable

- The kronrod function (used internally by quadgk) doesn’t have a method defined for symbolic types

This is not an issue with your code specifically, but rather a limitation in how these packages interact. The QuadGK package is designed for numerical integration with concrete floating-point numbers, not symbolic variables.

I’d like to use QuadGK in my functions, but for some reason it doesn’t seem like variables are registering properly.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 5, 2025, 5:10pm UTC](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587/3 "2025-03-05T17:10:52Z")

</div>

> [@JarodMcCormick](#):
>
> To give some extra context, this is what Claude 3.7 is giving me on this

Please don’t post AI-generated answers, in general. People are on this forum to talk to humans.

> [@JarodMcCormick](#):
>
> [9] quadgk  
> @ ~/.julia/packages/QuadGK/7rND3/src/api.jl:77 [inlined]  
> [10] stream\_delta\_heat\_capacity(stream::FlowStream{RK{…}, Nothing}, outlet\_temperature::Num)

Your `stream_delta_heat_capacity` is calling `quadgk` to do an integral. But `quadgk` is for numerical integration, it won’t work on symbolic variables.

It’s not clear what you want it to do here. Do you want a symbolic integral? Or are you hoping that ModelingToolkit will generate some code that calls `quadgk`?

---

<div class="post-metadata">

**Author:** ![JarodMcCormick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jarodmccormick/32/212396_2.png) [@JarodMcCormick](https://discourse.julialang.org/u/JarodMcCormick)\
**Post date:** [March 5, 2025, 6:34pm UTC](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587/4 "2025-03-05T18:34:46Z")

</div>

I have a numerical function “stream\_delta\_heat\_capacity” that is calling QuadGK as part of it. It’s just integrating from the inlet to the outlet temperature.

I put together another function that overloads this function:

```julia
function symbolic_delta_heat_capacity(stream::FlowStream, T_out::Num)
  # Create a function that can be called with numerical values
  function delta_heat_capacity_numeric(T_val)
    return stream_delta_heat_capacity(stream, Float64(T_val))
  end

  return delta_heat_capacity_numeric(value(T_out))
end

```

This resolves the QuadGK issue, and allows the code to run by casting the variable to a Float64 type.

I’m not sure why posting AI-generated content is not helpful. You’re still conversing with a human – I’m just trying to provide additional context. This error was strange because it was happening two libraries down in the stack, not in code that I had written or understand.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 7, 2025, 6:30pm UTC](https://discourse.julialang.org/t/kronrod-error-when-using-quadgk-w-symbolic-inputs/126587/5 "2025-03-07T18:30:14Z")

</div>

> [@stevengj](#):
>
> Or are you hoping that ModelingToolkit will generate some code that calls `quadgk`?

For reference, you would use function registration on the call to QuadGK.jl to make this happen. The documentation for this is:

> **[Function Registration and Tracing · Symbolics.jl](https://docs.sciml.ai/Symbolics/stable/manual/functions/)**
>
> Documentation for Symbolics.jl.
