Differential Equations in C
In C, an internal derivation variable is created for each continuous state variable. The name of this variable is composed of the name of the state variable and the prefix ddt.
Examples are the continuous state variables x and xp; the automatically created derivation variables are ddtx and ddtxp. They are visible in all methods.
A complete example is a PT2 system with the continuous state variables x and xp, the input in, and the parameters d, T, K.
x’ = xp;
xp’ = (K*in – (2.0*d*T*xp) – x) / (T*T);
The PT2 system above can be expressed as C code in the CT block as follows:
ddtx = xp;
ddtxp = (K*in – (2.0*d*T*ddtx) – x) / (T*T);
See also