Derivative

derivative - Built-in derivative data type

Synopsis
class class_name { derivative name [ unit ] ; } object class_name { name d(variable1)/d(variable2); name d(variable1)/dt; }

Description
The derivative property automatically calculates the average derivative of variable1 with respect to another variable2. If dt is used, the derivative is with respect to the global clock. The value of the derivative is updated whenever variable1 or variable2 changes. If dt is used, the value of the derivative is updated after the object's clock is updated.

Both variables must have either double or complex underlying type. The division is performed according to the usual mathematical rules for a quotient of doubles and complex values, as appropriate.

The units of the derivative must be consistent the units obtained when dividing variable1 by variable2. The conversion is performed automatically each time the derivative value is updated. If either of the variables has no unit, then the derivative cannot have a unit, and the values are simply divided.

Variables can be local to the object, in which case they are simply named. If a variable in another object is used, the name of the object must be prepended, as in object_name.variable.

Global variables may used provided the are of double or complex type. The syntax for a global variable is ::variable for core globals and module::variable for module globals.

Example
The following example maintains the derivative of the random variable x with respect to time and names it dx.

class example { random x[m]; derivative dx[m/s]; } object example { x "type:normal(0,1); refresh:1h"; dx d(x)/dt; object recorder { property "x,dx"; interval -1; file example.csv; }; }