Skip to content

Conversation

@YingboMa
Copy link
Member

Unfortunately, we cannot assume the order of params in an ODE system. For instance, the Lotka-Volterra is

function lotka(du,u,p,t)
  x = u[1]
  y = u[2]
  du[1] = p[1]*x - p[2]*x*y
  du[2] = -p[3]*y + p[4]*x*y
end

and generated Jacobian function is

    function ##405(##406, u, p, t)
        #= /Users/yingboma/.julia/dev/ModelingToolkit/src/utils.jl:55 =#
        let (x₁, x₂, α₁, α₃, α₄, α₂) = (u[1], u[2], p[1], p[2], p[3], p[4])
            ##406[1] = (+)(α₁, (*)(x₂, α₂, -1))
            ##406[2] = (*)(x₂, α₄)
            ##406[3] = (*)(α₂, x₁, -1)
            ##406[4] = (+)((*)(α₃, -1), (*)(α₄, x₁))
        end
        #= /Users/yingboma/.julia/dev/ModelingToolkit/src/utils.jl:56 =#
        nothing
    end

.

Note that it generates

(x₁, x₂, α₁, α₃, α₄, α₂) = (u[1], u[2], p[1], p[2], p[3], p[4])

which is incorrect. The order which params appear is not necessarily the same with the order which the user supplies it. Hence, we have to have an optional argument for params that retains the order.

@YingboMa YingboMa requested a review from ChrisRackauckas July 30, 2019 18:21
@YingboMa
Copy link
Member Author

Ah, we could do it just by

de = modelingtoolkitize(prob)
jac = eval(ModelingToolkit.generate_jacobian(de...))

@YingboMa YingboMa closed this Jul 30, 2019
@codecov-io
Copy link

codecov-io commented Jul 30, 2019

Codecov Report

Merging #160 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #160      +/-   ##
==========================================
+ Coverage   92.84%   92.85%   +0.01%     
==========================================
  Files          12       12              
  Lines         461      462       +1     
==========================================
+ Hits          428      429       +1     
  Misses         33       33
Impacted Files Coverage Δ
src/systems/diffeqs/diffeqsystem.jl 90.16% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dab9126...41c6487. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants