Modia.jl icon indicating copy to clipboard operation
Modia.jl copied to clipboard

numerical constant and spaces in equation

Open johhell opened this issue 4 years ago • 1 comments

issue with spaces in equations

correct results

two spaces

ConstantTest = Model(
    AA=1.3,
    equations = :[ der(X) = -1.0*X + 2.0*AA    ]  
)
ct = @instantiateModel(ConstantTest, log=true)
simulate!(ct, stopTime=10)
plot(ct, ("X"))

Equations after alias reduction:
   1: der(X) = -1.0X + 2.0AA

no spaces

    equations = :[ der(X) = -1.0*X+2.0*AA    ]

Equations after alias reduction:
   1: der(X) = -1.0X + 2.0AA

error message

one space

    equations = :[ der(X) = -1.0*X +2.0*AA    ]

Equations after alias reduction:
   1: der(X) = -1.0X
   2: 2.0AA

johhell avatar Aug 31 '21 17:08 johhell

Thank you for highlighting this. It is a general property of the Julia parser.

`julia> e = [1 + 2] 1-element Vector{Int64}: 3

julia> e = [1 +2] 1×2 Matrix{Int64}: 1 2`

So your Modia model gives either one or two equations:

`julia> :[ der(X) = -1.0X + 2.0AA ] :([der(X) = begin #= REPL[28]:1 =# -1.0X + 2.0AA end])

julia> :[ der(X) = -1.0X +2.0AA ] :([der(X) = begin #= REPL[29]:1 =# -1.0X end 2.0AA])`

I will leave the ticket open in order to remember to improve the diagnostics.

HildingElmqvist avatar Aug 31 '21 19:08 HildingElmqvist