# Error when calculating RHS of reaction ode "no method matching Float64(::Num)"

**URL:** <https://discourse.julialang.org/t/error-when-calculating-rhs-of-reaction-ode-no-method-matching-float64-num/64420>\
**Category:** Chemistry\
**Tags:** question, diffeq, debug, numerics\
**Created:** [July 10, 2021, 2:00pm UTC](https://discourse.julialang.org/t/error-when-calculating-rhs-of-reaction-ode-no-method-matching-float64-num/64420 "2021-07-10T14:00:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SA8416](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sa8416/32/25225_2.png) [@SA8416](https://discourse.julialang.org/u/SA8416)\
**Post date:** [July 10, 2021, 2:00pm UTC](https://discourse.julialang.org/t/error-when-calculating-rhs-of-reaction-ode-no-method-matching-float64-num/64420/1 "2021-07-10T14:00:52Z")

</div>

I have some code that uses a function to calculate some changes in concentration, but I get an error of:

```julia
ERROR: LoadError: MethodError: no method matching Float64(::Num)
Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:200
  (::Type{T})(::T) where T<:Number at boot.jl:760
  (::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50

```

I have attached the code below:

```julia
using DifferentialEquations
@parameters t c0[1:4] Ke[1:2] kb[1:2] aw aw² aw³ ρ ζ ρζ ρζ² γ γ² T

# Calculate parameters
ρ = 0.592
ζ = 1.0
ρζ = ρ*ζ
ρζ² = ρζ*ρζ
ρζ³ = ρζ*ρζ²

aw = 0.995
aw² = aw*aw
aw³ = aw*aw²

γ = 1.08
γ² = γ*γ

T = 590.0
# calculate equilibrium constants
Ke[01] = (1.0E-06)*10.0^(-4.098 + (-3245.2/T) + (2.2362E+05/(T^2)) + (-3.9984E+07/(T^3)) + (log10(ρ) * (13.957 + (-1262.3/T) + (8.5641E+05/(T^2)))) )
Ke[02] = 10^(28.6059+0.012078*T+(1573.21/T)-13.2258*log10(T))

# calculate backward rate constants
kb[01] = Ke[01]*ρζ²/γ²
kb[02] = Ke[02]*γ/ρζ

# set initial concentrations
c0 = [0.09897, 0.01186, 2.94e-5, 4.17e-8]

function oderhs(c,Ke,kb,aw,aw²,aw³,ρζ,ρζ²,ρζ³,γ,γ²)
      # rename c to their corresponding species
      H₃BO₃ = c[1]; H₄BO₄⁻ = c[2]; OH⁻ = c[3]; H⁺ = c[4];
      # rename Ke to their corresponding reactions
      Ke_iw1 = Ke[1]; Ke_ba1 = Ke[2];
      # rename kb to their corresponding reactions
      kb_iw1 = kb[1]; kb_ba1 = kb[2];
      # determine the rate of reaction for each reaction
      r_iw1 = kb_iw1*(H⁺*OH⁻ - Ke_iw1*ρζ²*aw/γ²)
      r_ba1 = kb_ba1*(H₄BO₄⁻ - H₃BO₃*OH⁻*Ke_ba1*γ/ρζ)
      dc = zeros(eltype(c),4)
      # calculate the change in species concentration
      dc[1] = r_ba1
      dc[2] = r_ba1
      dc[3] = r_iw1 + r_ba1
      dc[4] = r_iw1
      
      return dc
end

dc = oderhs(c0,Ke,kb,aw,aw²,aw³,ρζ,ρζ²,ρζ³,γ,γ²)

```

---

<div class="post-metadata">

**Author:** ![lamorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lamorton/32/21115_2.png) [@lamorton](https://discourse.julialang.org/u/lamorton)\
**Post date:** [July 10, 2021, 4:02pm UTC](https://discourse.julialang.org/t/error-when-calculating-rhs-of-reaction-ode-no-method-matching-float64-num/64420/2 "2021-07-10T16:02:09Z")

</div>

Welcome to Julia discourse! For future reference, please post the full stack trace along with the error message – it makes it easier for others to help you. 🙂

Parameters are not for assigning to. The way they work is that you provide values for them during the construction of an `ODEProblem` from and `ODESystem` by providing a mapping from parameters to values. The error messages you are getting are b/c you have overwritten the parameters with literal numbers, and the final one that you listed is b/c you are trying to put a symbolic parameter into the array `dc` that expects literal numbers. [Here’s an example](https://mtk.sciml.ai/stable/tutorials/ode_modeling/) for how the process works. (I assume you are getting `@parameters` from `ModelingToolkit`.)

If you haven’t already, check out [Catalyst.jl](https://catalyst.sciml.ai/dev/tutorials/using_catalyst/) for simulating chemical reactions.

---

<div class="post-metadata">

**Author:** ![SA8416](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sa8416/32/25225_2.png) [@SA8416](https://discourse.julialang.org/u/SA8416)\
**Post date:** [July 10, 2021, 8:10pm UTC](https://discourse.julialang.org/t/error-when-calculating-rhs-of-reaction-ode-no-method-matching-float64-num/64420/3 "2021-07-10T20:10:24Z")

</div>

Thanks!  
What fixes the problem is changing  
`dc = zeros(eltype(c),4)`  
to  
`dc = zeros(Num,4)`

given from:

[https://stackoverflow.com/questions/68328599/error-when-calculating-rhs-of-ode-no-method-matching-float64num/68330792#68330792](https://stackoverflow.com/questions/68328599/error-when-calculating-rhs-of-ode-no-method-matching-float64num/68330792#68330792)

Thank you for suggesting Catalyst.jl, but I haven’t had success coupling the results from it to my transport solver (thus the need to hard-code the reaction rates instead) 🙂

---

<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:** [July 10, 2021, 8:12pm UTC](https://discourse.julialang.org/t/error-when-calculating-rhs-of-reaction-ode-no-method-matching-float64-num/64420/4 "2021-07-10T20:12:44Z")

</div>

> [@SA8416](#):
>
> Thank you for suggesting Catalyst.jl, but I haven’t had success coupling the results from it to my transport solver (thus the need to hard-code the reaction rates instead) 🙂

Open an issue?

---

<div class="post-metadata">

**Author:** ![SA8416](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sa8416/32/25225_2.png) [@SA8416](https://discourse.julialang.org/u/SA8416)\
**Post date:** [July 10, 2021, 8:59pm UTC](https://discourse.julialang.org/t/error-when-calculating-rhs-of-reaction-ode-no-method-matching-float64-num/64420/5 "2021-07-10T20:59:44Z")

</div>

Done  
[https://github.com/SciML/Catalyst.jl/issues/346](https://github.com/SciML/Catalyst.jl/issues/346)
