LENGTH INDEX

LENGTH _ _ _ _ _ _ _ _ _ _ _ _ operator

The length operator returns the number of items in a list, the number of terms in an expression, or the dimensions of an array or matrix.

syntax:

length(<expr>) or length <expr>

<expr> can be a list structure, an array, a matrix, or a scalar expression .

examples:


alist := {a,b,{ww,xx,yy,zz}}; 

  ALIST := {A,B,{WW,XX,YY,ZZ}} 


length alist; 

  3  


length third alist; 

  4  


dlist := {d}; 

  DLIST := {D} 


length rest dlist; 

  0  


matrix mmm(4,5); 

length mmm; 

  {4,5} 


array aaa(5,3,2); 

length aaa; 

  {6,4,3} 


eex := (x+3)**2/(x-y); 

          2
         X  + 6*X + 9
  EEX := ------------ 
            X - Y


length eex; 

  5

An item in a list that is itself a list only counts as one item. A n error message will be printed if length is called on a matrix which has not had its dimensions set. The length of an array includes the zeroth element of each dimension, showing the full number of elements allocated. (Declaring an array A with n elements allocates A(0),A(1),...,A(n).) The length of an expression is the total number of additive terms appearing in the numerator and denominator of the expression. Note that subtraction of a term is represented internally as addition of a negative term.