Tech:double array

- double_array Technical Notes


 * Declaration :

class myclass : public gld_object { private: GL_STRUCT(double_array,name); }
 * 1) include 


 * Implementation

myclass::myclass(MODULE *module) {   // ...    if ( gl_publish(oclass, PT_double_array,"name",get_name_offset, // other options... NULL)<1 ) exception("unable to publish module myclass properties"); // ... } int myclass::create(void) {   // ...    name.set_name("name"); // ... } int myclass::init(OBJECT *parent) {   // ...    set_name("'a'11 'a'12 ... 'a'1M ; 'a'21 'a'22 ... 'a'2M ; 'a'N1 'a'N2 ... 'a'NM"); }
 * 1) include "myclass.h"

The double_array is a built-in type type and implemented as a class in the C++ Module API. This class allows basic math operations on arrays. The following operators are supported

Example
A good example of using double_array is the canonical control model:

int example::sync(timestamp t1) {    TIMESTAMP ts = 10; // discrete-time model time step Y = C*X + D*U; X += A*X + B*U; return (t1/ts+1)*ts; }

The declarations for the arrays are

GL_STRUCT(double_array,A); ///< A matrix (state transition) GL_STRUCT(double_array,B); ///< B matrix (control) GL_STRUCT(double_array,C); ///< C matrix (output) GL_STRUCT(double_array,D); ///< D matrix (feedfwd) GL_STRUCT(double_array,X); ///< state vector X (state) GL_STRUCT(double_array,U); ///< control vector U (input) GL_STRUCT(double_array,Y); ///< output vector Y (output)

The user would then provide the input and output properties and the model definition in the GLM file. The following example is a SISO model (the extension to MIMO is intuitive).

module class example { double input; double output; } object example { input 0; output 0; A "0 1 ; -0.16 -1"; // dimensions must match state vector B "1 ; 1"; // dimensions must match state vector and input C "1 0"; // dimensions must match state vector and output D "0"; // dimensions must match input input and output U "input"; X "0 ; 0"; Y "output"; object player { property input; file input.csv; };   object recorder { property output; file output.csv; interval -1; }; };

History
Support for double_array math operations was added in.