LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

formula node two dimensional arrays

simple question but i seem to get an error

i've few 2D arrays which i know the elements so i would like to define them directly into the formula node so i did like this:


// arrays initialization
float A[6][6];
float B[6][2];
float C[6][6];
float D[6][2];
float Aug[12][8];
float Track[12];

// arrays values

A={{0,k1,0,0,0,0},
{0,0,1,0,0,0},
{0,k3,0,0,0,0},
{0,0,0,0,1,0},
{0,0,0,k5,0,k6},
{0,0,0,0,0,0}};

B={{k2,0},
{0,0},
{k4,0},
{0,0},
{0,0},
{0,k7}};


etc...

the error i'm getting is

Error on line 35 is marked by a '#' character: ".../ arrays values  A={#{0,k1,0,0,0,0}, {0,"

the line number refers to matrix A={{......
if i cut this matrix i get the same error in B and so on.. so it seems that i did something wrong however, isn't formula node the same as C?

thanks in advance...
0 Kudos
Message 1 of 9
(4,197 Views)
anyone, please?
0 Kudos
Message 2 of 9
(4,176 Views)

Hi Jzee,

(Under LV7.1)  To see the C-syntax implemented by the formula-node, Search LabVIEW help on "Formula Node" and take the "syntax" link.  There's a syntax summary in "BNF" form.  I may be wrong, but it doesn't look like the aggregate-array-constant "expression" is allowed in an "assignment". Smiley Sad 

BTW, there's also a "Array Manipulation in Formula Nodes" help-page.

Cheers!

Message Edited by tbd on 04-01-2007 12:30 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 3 of 9
(4,171 Views)
well,

i saw the formula node help but can't see any mistake in my code in regards to what they have in the help. could you please write my code in the way "you think" it should be?

thanks
0 Kudos
Message 4 of 9
(4,163 Views)

Hi Jzee,

      I copied this from the page on syntax:

"expression:

expression binary-operator expression
unary-operator expression
expression unary-operator
expression ? expression : expression
( expression )
identifier
constant
function-name ( argument-list )

"

... the right-side of an "assignment" needs to be an "expression" but there doesn't appear to be any form of "expression" that handles the array-aggregate.  If this is in fact the case, then the assignments would need to be done individually: 

B[0][0]=2; // note, was "k2", but what does "k2" mean?
B[0][1]=0;
B[1][0]=0;
B[1][1]=0;
B[2][0]=4;
B[2][1]=0; // etc

Would it work for you to pass the 2D array into the Formula Node - already defined?

?

Message Edited by tbd on 04-01-2007 02:56 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 5 of 9
(4,158 Views)
K2 is actually defined before and all other variables, all what i needed actually is to avoid writing the matrices with the variables in any graphical way because i had constants that depend on other constants. so here is the whole code but right hand side is replaced by "xx". if there is no aggregate assignment then this is just a pain in the bum and there is no point of having a formula node. do you have any other suggestions for entering my matrices other than using CD state space VI because at that point i need to calculate the second set of constants to enter them in the state space VI in the "symbolic" form. or do you think i can write something like the form of K1=-m*g*l**2/I_theta in the symbolic SS parameters. and write K1 in the element position in the A-matrix...etc

float m= xx;            // mass  - Kg
float l= xx ;            // (exactly .77) height centre of gravity - m
float r= xx ;       //  radius of the tyre - m
float I_theta=xx ;       // moment of inertia in pitch direction kg.m^2
float I_phi=xx ;     // moment of inertia in roll direction  kg.m^2
float I_psi= xx ;      // moment of inertia in the yaw direction  kg.m^2
float g=xx;             // gravitational acceleration m^2/s
float v= xx;               // speed of the unicycle in X direction m^2/s
float w= xx;               // w_MAX=16 rad/s - speed of yawing rad/************************** NOTING that rpm = rad/s * 9.549
float phi_c=xx;            // command roll  angle



// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// % state space system constants - depend on above single constants as in K1
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
float k1=-m*g*l**2/I_theta;
float k2=xx;
float k3=xx;
float k4=-xx;
float k5=xxi;
float k6=xx;
float k8=xx;

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// % state space matrices
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// arrays initialization
float A[6][6];
float B[6][2];
float C[6][6];
float D[6][2];
float Aug[12][8];
float Track[12];

// arrays values

A={{0,k1,0,0,0,0},
{0,0,1,0,0,0},
{0,k3,0,0,0,0},
{0,0,0,0,1,0},
{0,0,0,k5,0,k6},
{0,0,0,0,0,0}};

B={{k2,0},
{0,0},
{k4,0},
{0,0},
{0,0},
{0,k7}};

and definitions for C, and D... some other matrices...etc
0 Kudos
Message 6 of 9
(4,151 Views)

> pain in the bum

yes, it's sorta depressing in those (albiet rare) cases when LabVIEW forces us into something so... inelegant. Smiley Wink

... but the work-around that (i think) you suggested doesn't seem too bad.  Did you mean to suggest that the (somewhat sparse) 2D arrays could be initialized on the block-diagram, and the 8 "k-values" could be "plugged-into" the pre-existing array?  So:

float k1=-m*g*l**2/I_theta;
float k2=xx;
float k3=xx;
float k4=-xx;
float k5=xxi;
float k6=xx;
float k8=xx;

could become:

A[0][1]=-m*g*l**2/I_theta;
B[0][0]= xx; // from k2
A[2][1]= xx; // from k3
B[2][0]=-xx; // from k4
A[4][3]= xx; // from k5
A[4][5]= xx; // from k6
B[5][1]= xx; // from k7

... and the array-assignment dissappears completely! Smiley Happy

?

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 7 of 9
(4,148 Views)
well your idea about sparce matrices doesn't look bad actually. I meant something as horrible and painfull as this picture and at the end you get an error from the CD SS VI.


0 Kudos
Message 8 of 9
(4,146 Views)
... thanks for the pic!  ... have to admit "state-space" references were completely lost on me Smiley Tongue - is this a Matlab-specific abstraction? (just did a bit of searching...)
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 9 of 9
(4,142 Views)