# Algebraic equations and conditional definitions in models

2 views

### Yochanan Di Veroli

Feb 17, 2021, 10:40:53 AM2/17/21
to iq-desktop-...@intiquan.com
So a couple of quick questions:

1/ Do states only defined via algebraic equations need to be written as variables in the model (i.e. in states only odes can be defined)?

2/ Can you only define on a conditional basis via events?

For instance if we have something like:

if (STATE1<parameter1) then
variable1 = function1 (states,parameters)
elseif(STATE1>=parameter1 ) then
variable1 = function2 (states,parameters)

Would you define it as follows??

********** MODEL VARIABLES
variable =  function1 (states,parameters)
********** MODEL EVENTS
Event1 = gt( STATE1,parameter1 ), variable1, function2 (states,parameters)

Would that work in the correect way?

Thanks! Giovanni

### Henning Schmidt

Feb 17, 2021, 11:37:04 AM2/17/21
to Yochanan Di Veroli, IQ Desktop Users Group
Hi Giovanni,

see below:

On Wed, Feb 17, 2021 at 4:40 PM Yochanan Di Veroli <ydiv...@gmail.com> wrote:
So a couple of quick questions:

1/ Do states only defined via algebraic equations need to be written as variables in the model (i.e. in states only odes can be defined)?

In IQM Tools it was possible to define DAEs. E.g. by specifying in the STATE section:     0 = Total_Drug + Free_Drug + Bound_Drug
In IQR Tools such a syntax is not supported as also the solver does not allow for it.

Free_Drug = Total_Drug - Bound_Drug

Also makes the solving easier.

2/ Can you only define on a conditional basis via events?

Conditional statement (similar to if then else then else then ...) can be implemented with the "piecewise" function in models. See here: https://iqrtools.intiquan.com/doc/book/modelImplementation.html#conditions

For instance if we have something like:

if (STATE1<parameter1) then
variable1 = function1 (states,parameters)
elseif(STATE1>=parameter1 ) then
variable1 = function2 (states,parameters)

Would you define it as follows??

********** MODEL VARIABLES
variable1 =  piecewise( function1 (states,parameters),   le(STATE1,parameter1),    function2 (states,parameters))

With events that would not work. Events can only change state variables and parameters but not variables.

Best,
Henning