home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-21 | 4.6 KB | 158 lines | [TEXT/RLAB] |
- list:
-
- RLaB LIST objects, or entities, are arrays of other entities.
- You can think of lists as N-dimensional arrays. In their
- simplest form a list is a single dimension array with funny
- indexing syntax. The neat thing about lists is that the index
- does not have to be an integer value. The index can be a
- string, or a scalar. It is OK to use an expression as a list
- index value since RLaB will evaluate it (it had better
- evaluate to a string or scalar).
-
- One advantage of lists is the ability to give array elements
- descriptive names, such as: `a.mass', `m.modes', etc... The
- syntax `a.name' where name is a descriptive string, is
- shorthand for the more complex LIST indexing syntax. The
- formal indexing syntax is:
-
- expr . [ scalar_or_string_expr ]
-
- Where expr is any valid expression that evaluates to a LIST,
- scalar_or_string_expr is any valid expression that evaluates
- to a scalar or string.
-
- To use a list, or assign to members of the list you can create
- it first...
-
- list = <<>>
-
- This will create an empty list. Or, you can create and load
- the list at the same time...
-
- list = <<a; b>>
-
- The above will create the list, and COPY the objects a and b
- into the list. The list members will have index values 1 and
- 2.
-
- list = <<A=a; B=b>>
-
- The above will create a list, copying the variable a into the
- variable A, and so on. When an assignment occurs inside the
- list creation operators the LHS variable does not appear on
- the global symbol table. The new list has members named `A'
- and `B'.
-
- Like other objects you can just start using the list...
-
- list.a_inv = inv(a);
-
- This will create the list and it's first member. The name of
- the member is `a_inv'. To reference a list member, two methods
- are available.
-
- list.NAME
- list.[ scalar_or_string_expr ]
-
- The first method interprets NAME as a character string, and
- uses the string to index the member. The second method
- converts the result of the scalar or string expression into a
- string and uses that to index the list. Therefore
-
- list.[2.5]
- x = 2.5; list.[x]
- list.[1.5 + sqrt(1)]
-
- are equivalent.
-
- list.matrix
- list.["matrix"]
-
- are also equivalent.
-
- A nice thing about lists is that they only contain objects
- that are explicitly installed, regardless of the index values.
- For instance, a list with index values of "1" and "100" will
- only contains two items, the elements for the "1" and "100"
- indices, no more. Furthermore, lists can be more efficient
- than appending rows or columns onto matrices, since the memory
- management overhead is less.
-
- Lists can also be a convenient way to have an array that
- indexes from zero. This may not be as efficient as using a
- matrix, but if the problem is expressed more clearly then a
- list may be appropriate.
-
- The built-in function members() returns a matrix of the
- argument's indices. This can be useful when a function
- encounters a LIST, but doesn't know the member names.
-
- Example:
-
- > xlist = << Mass = sqrt(200); Inertia = eye(3,3); xdot = [1,2,3] >>
- Inertia Mass xdot
- > for( i in members(xlist) )
- {
- xlist.[i]
- }
- Inertia =
- matrix columns 1 thru 3
- 1 0 0
- 0 1 0
- 0 0 1
- Mass =
- 14.14
- xdot =
- matrix columns 1 thru 3
- 1 2 3
-
- ----------------------------------------------------------------
-
- The Rlab symbol-table is a list. It can be referenced with the
- special symbol `$$'. The symbol-table can be used like other
- lists, with certain exceptions.
-
- 1.) The symbol-table cannot be copied.
-
- 2.) The symbol table cannot be destroyed.
-
- Why would you want to use `$$' ? Well, you might use it to
- reference a variable with a string. For example:
-
- > printf ("Enter variable name to print: "); a = getline ("stdin");
- Enter variable name to print: eps
- > $$.[a.[1]]
- eps =
- 1.11e-16
-
- Another example of `$$' usage can be found in the rfile
- rlib/save.r, or type `help save'.
-
- ----------------------------------------------------------------
-
- When using the list syntax:
-
- list.[ scalar_or_string_expr ]
-
- If scalar_or_string_expr does not evaluate to a string, then
- it is converted to a string with a "%.6g" format ("%.6gi" if
- it is a complex constant"). The same is true whether you are
- assigning to members of a list, or referencing existing list
- members. This may lead to some unexpected results if you use
- floating-point numbers for list indices.
-
- > a.[1.23456] = 13
- 1.23456
- > a.[1.2345]
- UNDEFINED
- > a.[1.23456]
- 1.23456 =
- 13
- > a.[1.234567]
- UNDEFINED
- > a.[1.234563]
- 1.23456 =
- 13
-
- ----------------------------------------------------------------
-