# Issue with Differential Equation Solver

**URL:** <https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008>\
**Category:** General Usage\
**Tags:** question, package, diffeq\
**Created:** [October 16, 2023, 11:05am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008 "2023-10-16T11:05:37Z")\
**Posts on this page:** 16\
**Page:** 2

<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:** [October 19, 2023, 10:29am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/21 "2023-10-19T10:29:16Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [October 19, 2023, 10:40am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/22 "2023-10-19T10:40:21Z")

</div>

these are the packages installed:  
Status `~/.julia/environments/v1.8/Project.toml`  
[093aae92] BSplineKit v0.16.5  
[336ed68f] CSV v0.10.11  
[35d6a980] ColorSchemes v3.24.0  
[a93c6f00] DataFrames v1.6.1  
⌃ [0c46a032] DifferentialEquations v7.10.0  
[f6369f11] ForwardDiff v0.10.36  
[4345ca2d] Loess v0.6.3  
[2fda8390] LsqFit v0.15.0  
⌃ [961ee093] ModelingToolkit v8.70.0  
[76087f3c] NLopt v1.0.0  
⌅ [8913a72c] NonlinearSolve v1.10.1  
[429524aa] Optim v1.7.8  
[1dea7af3] OrdinaryDiffEq v6.58.0  
[58dd65bb] Plotly v0.4.1  
[91a5bcdd] Plots v1.39.0  
⌃ [c3e4b0f8] Pluto v0.19.9  
[7f904dfe] PlutoUI v0.7.52  
[f3b207a7] StatsPlots v0.15.6  
[24249f21] SymPy v1.1.14  
[fdbf4ff8] XLSX v0.10.0  
[10745b16] Statistics  
Info Packages marked with ⌃ and ⌅ have new versions available, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated`

I use most of them.

---

<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:** [October 19, 2023, 10:42am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/23 "2023-10-19T10:42:20Z")

</div>

What’s holding back ModelingToolkit / DifferentialEquations? Which is the one that hasn’t been updated?

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [October 19, 2023, 10:52am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/24 "2023-10-19T10:52:28Z")

</div>

Not exactly sure, when I try updating it, this is what I get:

**(@v1.8) pkg\>** update ModelingToolkit

**Updating** registry at `~/.julia/registries/General.toml`

**Installed** TranscodingStreams ─ v0.10.1

**Installed** LinearSolve ──────── v2.11.0

**Installed** FillArrays ───────── v1.7.0

**No Changes** to `~/.julia/environments/v1.8/Project.toml`

**Updating** `~/.julia/environments/v1.8/Manifest.toml`

[1a297f60] ↑ FillArrays v1.6.1 ⇒ v1.7.0

[7ed4a6bd] ↑ LinearSolve v2.10.0 ⇒ v2.11.0

[731186ca] ↓ RecursiveArrayTools v2.39.0 ⇒ v2.38.10

[3bb67fe8] ↑ TranscodingStreams v0.10.0 ⇒ v0.10.1

**Precompiling** project…

33 dependencies successfully precompiled in 103 seconds. 336 already precompiled.

---

<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:** [October 19, 2023, 10:58am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/25 "2023-10-19T10:58:31Z")

</div>

Clean up your global environment and it will be easier to debug.

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [October 19, 2023, 11:32am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/26 "2023-10-19T11:32:23Z")

</div>

> [@ChrisRackauckas](#):
>
> `odelingToolkit@8.72`

I tried updating using workspace() but it did not work, and I tried restart repl, it doesn’t seem to work, is there another way to clear the global environment?

---

<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:** [October 19, 2023, 11:37am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/27 "2023-10-19T11:37:56Z")

</div>

I meant your global package environment.

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [October 19, 2023, 11:59am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/28 "2023-10-19T11:59:08Z")

</div>

I tried this, is this good enough?

**julia\>** using Pkg

**julia\>** using Dates

**julia\>** Pkg.gc(;collect\_delay=Dates.Day(0))

**Active** manifest files: 14 found

**Active** artifact files: 124 found

**Active** scratchspaces: 5 found

**Deleted** 240 package installations (228.822 MiB)

**Deleted** 45 artifact installations (555.484 MiB)

**Deleted** 5 scratchspaces (1.385 KiB)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [October 19, 2023, 12:01pm UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/29 "2023-10-19T12:01:53Z")

</div>

By cleaning up Chris meant removing unneeded packages which might introduce incompatibilities preventing packages from updating.

The easiest thing to do is probably to just work in a clean environment (i.e. `] activate .` in the folder in which you’re saving your code as well) and then add only the packages you need for this analysis to that environment. See here:

[https://pkgdocs.julialang.org/v1/environments/](https://pkgdocs.julialang.org/v1/environments/)

---

<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:** [October 19, 2023, 12:01pm UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/30 "2023-10-19T12:01:58Z")

</div>

I highly recommend making a clean environment and adding packages. If you just add the differential equation solver, it will be fine. What random thing is causing problems? I don’t know, I’ve never used XLSX. But do it incrementally. Add only the packages you need.

When you add something that pulls other packages back, take a look at it. That package is doing bad things. Avoid that package if you can.

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [October 19, 2023, 1:07pm UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/31 "2023-10-19T13:07:16Z")

</div>

This is how I created a new environment:  
begin  
import Pkg  
Pkg.activate(“.”)  
Pkg.add(“MethodOfLines”)  
Pkg.add(“Symbolics”)  
Pkg.add(“DomainSets”)  
using MethodOfLines  
using ModelingToolkit  
using OrdinaryDiffEq  
using NonlinearSolve  
using PlutoUI  
using DifferentialEquations  
using Plots  
using XLSX  
using Symbolics  
using DomainSets  
end

I am still facing the same error

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [October 19, 2023, 1:13pm UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/32 "2023-10-19T13:13:52Z")

</div>

Are you still in the same folder? You shouldn’t have been able to do e.g. `using Plots` since you only added three new packages. Go into a new folder and make sure your directory is set to there, then perform those steps. You can check to see if your environment is empty by seeing if there’s anything in `] st`. e.g. an empty project shows no packages

```julia
(jl_tDbHjK) pkg> st
Status `C:\Users\User\AppData\Local\Temp\jl_tDbHjK\Project.toml` (empty project)

```

You can also test in a temporary environment if you prefer. After restarting your session to ensure no packages are being reused, you can do

```julia
julia> import Pkg

julia> Pkg.activate(; temp = true)
  Activating new project at `C:\Users\User\AppData\Local\Temp\jl_eZE42P`

julia> Base.active_project() # make sure
"C:\\Users\\User\\AppData\\Local\\Temp\\jl_eZE42P\\Project.toml"

julia> Pkg.add("MethodOfLines")

```

(and so on). Then run your test code again, including packages one at a time and running your test code after each new `add` and `using`.

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [December 30, 2023, 10:43am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/34 "2023-12-30T10:43:05Z")

</div>

I am currently trying to solve 2 differential equations with 2 common variables, this is the code:

```julia
begin
# Parameters, variables, and derivatives for system 1
@parameters ts xs xf
@variables Ts(..) Tf(..)
Dts = Differential(ts)
Dxs = Differential(xs)
Dxxs = Differential(xs)^2
Dxf= Differential(xf)
Dxxf= Differential(xf)^2

# MOL Discretization parameters for system 1
x_max1 = L
x_min1 = 0
t_min1 = 0
t_max1 = 6737
nc1 = 20
x_num1 = range(x_min1, x_max1, length=nc1)
dxs = (x_max1 - x_min1) / (nc1 - 1)

# MOL Discretization parameters for system 2
x_max2 = L
x_min2 = 0
t_min2 = 0
t_max2 = 6737
nc2 = 20
x_num2 = range(x_min2, x_max2, length=nc2)
dxf = (x_max2 - x_min2) / (nc2 - 1)
	

# PDE equation for system 1
eq1 = ((52000 * exp(-1.24e-5 * Ts(ts, xs)) / (Ts(ts, xs) + 437)) / 1000) * Dxxs(Ts(ts, xs)) + ((h * A * ((Ts(ts, xs)) - Tf(ts, xf))) / (vol)) ~ ρs * Cps * Dts(Ts(ts, xs))
	
# Boundary conditions for system 1
bcs1 = [Ts(t_min1, xs) ~ Tamb,
            ((52000 * exp(-1.24e-5 * Ts(ts, xs)) / (Ts(ts, xs) + 437)) / 1000) * Dxs(Ts(ts, x_max1)) ~ 0,
            A * ((52000 * exp(-1.24e-5 * Ts(ts, xs)) / (Ts(ts, xs) + 437)) / 1000) * Dxs(Ts(ts, x_min1)) ~
                -(ϵ * σ * (Ts(ts, x_min1)^4) - (Tamb)^4) - h * A * ((Ts(ts, x_min1)) - Tamb)]

# Space and time domain for system 1
domains1 = [ts ∈ Interval(t_min1, t_max1),
            xs ∈ Interval(x_min1, x_max1)]

# ODE system for system 1
@named pdesys1 = PDESystem([eq1], bcs1, domains1, [ts, xs], [Ts])

# MOL parameters for system 1
order1 = 2
discretization1 = MOLFiniteDifference([xs => dxs, xf=> dxf], ts, approx_order=order1)

# Convert the ODE problem for system 1
prob1 = discretize(pdesys1, discretization1)
sol1 = solve(prob1, saveat=3)
T_exp1 = sol1.u[Ts]

# PDE equation for system 2
eq2 = Cpf * ρf * V * Dxf(Tf(ts, xf)) ~ -Cpf * ρf * Dtf(Tf(ts, xf)) +
        ((h * A * ((Ts(ts, xs)) - Tf(ts, xf))) / (vol))

# Boundary conditions for system 2
bcs2 = [Tf(t_min2, xf) ~ Tamb,
        kf * Dxf(Tf(ts, x_max2)) ~ 0,
        A * kf * Dxf(Tf(ts, x_min2)) ~ -h * A * ((Tf(ts, x_min2)) - Tamb)]
	
# Space and time domain for system 2
domains2 = [ts ∈ Interval(t_min2, t_max2),
            xf ∈ Interval(x_min2, x_max2)]

# ODE system for system 2
@named pdesys2 = PDESystem([eq2], bcs2, domains2, [ts, xf], [Tf(ts, xf)])

# MOL parameters for system 2
order2 = 2
discretization2 = MOLFiniteDifference([xf => dxf, xs => dxs], approx_order=order2)

# Convert the ODE problem for system 2
prob2 = discretize(pdesys2, discretization2)
sol2 = solve(prob2, saveat=3)
T_exp2 = sol2.u[Tf]

end

```

This is the error I am getting:  
Sym doesn’t have a operation or arguments!

1. **error** (::String)@_error.jl:35_
2. **error\_sym** ()@_types.jl:78_
3. **operation** @_types.jl:108_ [inlined]
4. **operation** (::Symbolics.CallWithMetadata{SymbolicUtils.FnType{Tuple, Real}, Base.ImmutableDict{DataType, Any}})@_variable.jl:240_
5. **chain\_flatten\_array\_variables** (::Vector{Symbolics.CallWithMetadata{SymbolicUtils.FnType{Tuple, Real}, Base.ImmutableDict{DataType, Any}}})@_make\_pdesys\_compatible.jl:6_
6. **make\_pdesys\_compatible** (::ModelingToolkit.PDESystem)@_make\_pdesys\_compatible.jl:32_
7. **symbolic\_discretize** (::ModelingToolkit.PDESystem, ::MethodOfLines.MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})@_symbolic\_discretize.jl:11_
8. **var"#discretize#73"** (::Nothing, ::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(SciMLBase.discretize), ::ModelingToolkit.PDESystem, ::MethodOfLines.MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})@_discretization\_state.jl:58_
9. **discretize** (::ModelingToolkit.PDESystem, ::MethodOfLines.MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})@_discretization\_state.jl:55_
10. **top-level scope** @_[Local: 52](http://localhost:1234/edit?id=899a6c64-a561-11ee-3f63-85c357e80732#)_

Would appreciate your help!

---

<div class="post-metadata">

**Author:** ![Wen-Wei\_Tseng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wen-wei_tseng/32/28839_2.png) [@Wen-Wei\_Tseng](https://discourse.julialang.org/u/Wen-Wei_Tseng)\
**Post date:** [December 30, 2023, 12:32pm UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/35 "2023-12-30T12:32:26Z")

</div>

I got the error: `L` is not defined.

Perhaps try installing specific versions of packages?

`] add DifferentialEquations@7.11.0 ModelingToolkit@8.73.1 MethodOfLines@0.10.4 `

You can see the working combination in `MethodOfLines.jl`’s [docs](https://docs.sciml.ai/MethodOfLines/stable/#Reproducibility).

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [December 31, 2023, 10:58am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/36 "2023-12-31T10:58:01Z")

</div>

L is defined above in a different cell. I also installed the versions of packages you suggested, but I am still getting the same error. If you see an issue with how I wrote my equations and defined my variables, and parameters, please let me know!

---

<div class="post-metadata">

**Author:** ![A\_09](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@A\_09](https://discourse.julialang.org/u/A_09)\
**Post date:** [January 13, 2024, 10:51am UTC](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008/37 "2024-01-13T10:51:43Z")

</div>

now that I am trying to solve the equations:

```julia
begin

# MOL parameters for system 1
order1 = 2
discretization1 = MOLFiniteDifference([xs => dxs, xf=> dxf], t, approx_order=order1)

# Convert the ODE problem for system 2
prob1 = discretize(pdesys1, discretization1)
sol1 = solve(prob1, saveat=3)
# T_exp1 = sol1.u[Ts, Tf]
Ts_values = sol1(Ts).u
Tf_values = sol1(Tf).u

end

```

I get this error and I believe that 2 dimensions of t are needed, I am unsure of how to formate it for this package: “Solution has length 1 in dimension t. Interpolation will not be possible for variable Tf(t, xf). Solution return code is InitialFailure.”

[Previous page](https://discourse.julialang.org/t/issue-with-differential-equation-solver/105008.md?page=1)
