Skip to contents

equation_dependencies(sys) lists, for each equation, the variables its right-hand side depends on. variable_dependencies(sys) is the bipartite graph from variables to the equations that modify them (the variables on the left-hand sides). asgraph() turns the equation dependencies into a BipartiteGraph() from equations to variables, asdigraph() turns a bipartite graph into a directed graph on the joint vertex set, and eqeq_dependencies() and varvar_dependencies() give the directed graphs of equations (or variables) that depend on each other. These are the functions of the same names in ModelingToolkit.

Usage

equation_dependencies(sys, variables = unknowns(sys), eqs = equations(sys))

asgraph(sys, variables = unknowns(sys), eqs = equations(sys))

variable_dependencies(sys, variables = unknowns(sys), eqs = equations(sys))

asdigraph(
  g,
  sys,
  variables = unknowns(sys),
  equationsfirst = TRUE,
  eqs = equations(sys)
)

eqeq_dependencies(eqdeps, vardeps)

varvar_dependencies(eqdeps, vardeps)

Arguments

sys

A System.

variables

The variables to track; defaults to the unknowns.

eqs

The equations (or jumps); defaults to the system's equations.

g

A BipartiteGraph.

equationsfirst

Number the equations before the variables.

eqdeps, vardeps

Bipartite graphs from asgraph() and variable_dependencies(). asgraph() also accepts the list returned by equation_dependencies() as sys, with variables the variable list.

Value

A list of variable lists, a BipartiteGraph, or a directed graph: a list with fadjlist (successors) and badjlist (predecessors).

Examples

t <- t_nounits; D <- D_nounits
variables("x(t)", "y(t)"); parameters("k")
sys <- System(list(D(x) ~ -k * y, D(y) ~ x), t, name = "sys")
equation_dependencies(sys)
#> [[1]]
#> [[1]][[1]]
#> y(t)
#> 
#> 
#> [[2]]
#> [[2]][[1]]
#> x(t)
#> 
#> 
eg <- asgraph(sys)
vg <- variable_dependencies(sys)
eqeq_dependencies(eg, vg)$fadjlist
#> [[1]]
#> [1] 2
#> 
#> [[2]]
#> [1] 1
#> 
varvar_dependencies(eg, vg)$fadjlist
#> [[1]]
#> [1] 2
#> 
#> [[2]]
#> [1] 1
#> 
asdigraph(eg, sys)$fadjlist
#> [[1]]
#> [1] 4
#> 
#> [[2]]
#> [1] 3
#> 
#> [[3]]
#> integer(0)
#> 
#> [[4]]
#> integer(0)
#>