A rule object represents a rule, which is a mathematical expression that modifies one of the following:
A rule is scoped to a model. A rule has a RuleType property that specifies one of the following four types of rules:
|For information about...||See...|
|Creating and adding a rule to a model||addrule|
|Methods and properties of a rule||rule object|
Use any valid MATLAB® code to create the mathematical expression for a rule. The rule can specify compartments, species, or model-scoped parameters.
Following are rules for writing rule expressions:
The expression must be a single MATLAB statement.
Do not end the rule expression with any of the following:
Comment text preceded by %
Line continuations indicated by ...
An algebraic rule lets you specify mathematical constraints on one or more compartments, species, or parameters that must hold during a simulation. It is evaluated continuously during a simulation.
An algebraic rule takes the form 0 = Expression and the rule is specified as the Expression.
For example, you could write a mass conservation expression such as species_total = species1 + species2 where species_total is the independent variable. In SimBiology®, write the rule as species1 + species2 - species_total.
An algebraic rule is a convenient way to define mathematical relationships between states. A model can consist of a combination of differential and algebraic relationships.
An algebraic rule is a constraint that is enforced by the solver during simulation. You can use algebraic rules to specify the dynamics for parameters, species, and compartments that are not driven by one or more reactions. The accuracy of the solution depends on the tolerance specified in the Configset object, which defines the simulation settings.
An algebraic rule is defined by the equation:
Where t is simulation time. The variable x is species amount, parameter value, or compartment capacity.
An example of an algebraic rule is:
x*log(x) - 3
Consider the mathematical constraint y = m*x - c. In the software this rule is written as m*x - c - y. If you want to use this rule to determine the value of y, then m, x, and c must be variables or constants whose values are known or determined by other equations. In general, the degree of freedom available must match the number of constraints. Therefore, you must ensure that the equation is not overconstrained or underconstrained. In this example, if the equation is underconstrained, it is unclear which variable is being determined by the expression.
An initial assignment rule lets you specify the initial value of a compartment capacity, species amount, or parameter value as a function of other component values in the model. It is evaluated once at the beginning of a simulation.
An initial assignment rule is expressed as Variable = Expression.
For example, you could write an initial assignment rule to set the initial amount of species1 to be proportional to species2:
species1 = k*species2
A repeated assignment rule lets you specify a value that holds at all times during simulation, and is a function of other component values in the model. It is evaluated at every time-step during a simulation. These time steps are determined by the solver during the simulation process.
A repeated assignment rule is expressed as Variable = Expression.
For example, if you want the capacity of a compartment (cytoplasm) to change in response to a change in the concentration of a species (x), write a repeated assignment rule to set the capacity of cytoplasm to be proportional to x.
cytoplasm = k*x
Where k is a specified constant parameter.
Repeated assignment rules are mathematically equivalent to algebraic rules, but result in exact solutions, compared to algebraic rules whose accuracy depends on the tolerance specified in the Configset object, which defines the simulation settings.
A rate rule lets you specify the time derivative of a compartment capacity, species amount, or parameter value. It is evaluated continuously during a simulation.
A rate rule is determined by dVariable/dt = Expression, which is expressed in the software as Variable = Expression. For example, to define the rate of change in the quantity of species3 (dspecies3/dt), write the rule in the software as:
species3 = k * (species1 + species2)
One example of a rate rule is when species1 is at the boundary of the system, but the rate of input of species1 to the system can be determined by a rate rule.
A rate rule is defined by the equation:
dx/dt = f(t,W)
The variable x can be a species amount, parameter value, or compartment capacity. The function f(W) is an expression that can include other species and parameters. Enter a rate rule using the form
x = f(t,W)
You can increase or decrease the amount or concentration of a species by a constant value using a zero-order rate rule. For example, suppose species c increases by a constant rate k.
reaction: none rate equation: none rate rule: dc/dt = k species : c = 10 mole(initial amount) parameters: k = 1 mole/second
The analytical solution is c = kt + co, where co is the initial amount or concentration of the species c.
Enter the rule described above as c = k. Set the RuleType property to rate, enter the values for c and k, and then simulate.
Alternatively, you could model a constant increase in a species using Mass Action reaction null -> C.
For examples of creating other rate rules, see the following sections in Creating Rate Rules:
For an example of creating a model that includes a rule expression that calls the custom function, see Create and Simulate a Model with a User-Defined Function.