| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (4 out of 15)

Tabular Functions of One Argument

Tabular functions of one argument are items of the TABULAR-FUNCTION-OF-1-ARG class, referred to henceforth as tabular functions.

Tabular functions begin with a single-argument, user-defined function of the form:

From such a function, you enter one or more arguments and values to derive, or cause G2 to compute, multiple comparative or associative values. G2 presents such comparisons and associations in a tabular format. Tabular functions and their arguments can consist of any type (integer, float, symbolic, logical, or text).

If you create a tabular function of arithmetic values, you can direct G2 to interpolate a return value for an argument that is not given in the table. G2 performs a straight-line interpolation whenever it interpolates one or more missing values. If you do not direct G2 to interpolate values, and a value of x is not given in the table, function evaluation fails.

Two examples illustrating different uses of tabular functions are:


Example Shows how to...
1
Translate values from one type into another. After specifying the series of numbers with an associated color, you could then use this tabular function in an expression such as:
2
Define the percentage of maximum flow through a valve as a function of the percent of the valve opening. Thus, given a valve opening, x, you can use the function percent-of-max-flow to calculate the percent of maximum flow through a valve. You can use this function in an expressions such as: Percent-of-max-flow is defined as a tabular function, rather than as a user-defined function, because the relationship between the two variables is non-linear and cannot be expressed readily in an algebraically.

To create a new tabular function of one argument:

The tabular function's icon and part of its menu are:


Notice that a tabular function has two table menu choices:

These are the attributes of a tabular function:

Attribute Description
Names
The name of the function as you will use it in expressions.
Allowable values:
symbol
Default value:
none


Keep-sorted
Specifies whether G2 sorts the values in the table.
Allowable values:
{no | by args | by values}
Default value:
by args


Interpolate?
Defines whether G2 will interpolate values that are not provided in the table.
Allowable values:
{no | yes}
Default value:
yes

Naming the Tabular Function

The Names attribute provides the name to use when referring to the function within expressions. After completing this attribute, the name replaces the f(x) label in the table of values for the function.

Sorting the Items in the Table

The Keep-sorted attribute specifies whether G2 sorts the function arguments, referred to as the values of x, or the values that correspond to the arguments, referred to as f (x).

If G2 is interpolating values, you must specify by values for this attribute.

Interpolating Function Values

The Interpolate? attribute specifies whether G2 interpolates a value for f (x) when the value of x is not explicitly given in the table.

When G2 is interpolating values, it performs a straight-line interpolation. For example, assume that the percent-of-max-flow function has these values:


G2 interpolates for all values of x in the range of 10 to 50. For example, if x is 15, G2 interpolates the percent-of-max-flow as 45. For interpolation to occur, the value of x must be greater than or equal to the smallest argument in the table and less than or equal to the largest argument in the table. If the argument is not in this range, G2 fails to evaluate the function.

Adding and Deleting Values and Arguments

For each tabular function, you enter one or more arguments, and a corresponding number of return values. G2 can complete a list of multiple arguments and return values, after you supply the first two entries.

During function execution, each argument is a possible value to pass to the function; every value is the complement of an argument that G2 can return. When using the optional interpolation capabilities, a tabular function can accept arguments and return complementary values that are not listed in the table.

To show the tabular function values table:

  1. Choose table of values from the menu for the function's icon.

    A new table of values contains the values of x and f(x):


To record values in the tabular function table:

  1. Choose add or delete rows from the table of values.

  2. Enter the syntax to add or delete rows in the edit workspace.

Adding Rows of Values

Use this syntax to add values to a tabular function:

As an example, entering this statement results in the tabular function that follows:

Note that if you have indicated that G2 should sort by either argument or value, where you add the rows does not matter; G2 immediately sorts them. For example, the table shown above is sorted by argument. If you add a row to it with x = 55, G2 automatically places that row after the row that has 50 as an argument value.

Deleting Rows of Values

Use this syntax for deleting rows:

Some examples are:

Example Result
delete unfinished rows
Deletes rows that do not have a value for either x or f (x).
delete row
Deletes the first row in the table.
delete row after x = 60
Deletes the row after the one that has 60 as the value for the x argument.
delete rows with x = 30 and f (x) = 40
Deletes all rows that have the value 30 for the x argument and 40 for the f(x) argument.
delete 5 rows at the end
Deletes the last five rows in the value table.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (4 out of 15)

Copyright © 1997 Gensym Corporation, Inc.