 Dataplot Elementary Operations

Contents We discuss the following elementary Dataplot operations:

Arithmetic Operations

Supported Symbols for Arithmetic Operations As with Fortran, the Dataplot language uses the following symbols for arithmetic operations:
 + addition - subtraction * multiplication / division ** exponentiation (the ^ symbol does not work for exponentiation and it fact has a distinct function as a substitution character in Dataplot)
Priority of Operations Also, operations are performed left to right with priorities defined in a fashion identical to Fortran:
1. exponentiation
2. multiplication and division
Use of Parentheses As with Fortran, the order of operations can be altered by the use of parentheses. Operations in parentheses are performed first.
Use of Arithmetic Operations with the Three Most Important Dataplot Commands The three most important Dataplot commands are
1. PLOT
2. FIT
3. LET
These three commands also have the most common occurrence of arithmetic operations, as in
PLOT 10+X**2 FOR X = 1 1 10
which would generate a plot of 10+X**2 for the values of X = 1, at increments of 1, up to 10 (that is X = 1, 2, ..., 10). The command
FIT Y = A + B*LOG(C+X**2)
would carry out a non-linear fit of Y on X with the model A + B*LOG(C+X**2). The command
LET A = X*Y + Z**2
would compute the parameter or variable A from the parameters or variables X, Y, and Z. If X, Y, and Z were all parameters, then A would become a parameter. If any of the X, Y, or Z were variables, then A would become a variable.
Arithmetic Operations Used in Function Defitions Arithmetic operations are also used in the definition of functions. For example
LET FUNCTION F = X**2
LET FUNCTION G = 10*Y
LET FUNCTION H = A+F/G
which would result in the creation of the functions F, G, and H where F = X**2, G = 10*Y, and H = A+(X**2)/(10*Y). Note that Dataplot would automatically provide the needed parantheses in the definition of H.
Dataplot  / Dataplot Elementary Operations ]

Relational Operators

Six Relational Operators Dataplot has six relational operators:
 = equality <> inequality < less than > greater than <= or =< less than or equal to >= or => greater than or equal to
Do Not Include Spaces Within a Relational Operator The spacing within such operators is important. For example, using > = instead of >= will lead to a syntax error or possible erroneous results. Thus to generate a plot of Y versus X but with the plot restricted to those X and Y values for which the LAB variable is 7 or greater, the proper entry is
PLOT Y X SUBSET LAB >= 7
while
PLOT Y X SUBSET LAB > = 7
is incorrect.
Spacing Around Relational Operators is Optional Spacing around such relational operators is optional and at the analyst's discretion. Using spaces around relational operators generally provides better human readability. The following are equivalent:
PLOT Y X SUBSET LAB >= 7
PLOT Y X SUBSET LAB>=7

FIT Y = A+B/X
FIT Y=A+B/X

LET Y = (X**LAMBDA)/(LAMBDA+1)
LET Y=(X**LAMBDA)/(LAMBDA+1)

Dataplot  / Dataplot Elementary Operations ]

Functions

Functions Are Named Character Strings A function is a named character string, and may be defined via the LET FUNCTION command, as in
LET FUNCTION F = EXP(-0.5*X**2)
LET FUNCTION G = SIN(2*PI*W*T)
LET FUNCTION H = F+LOG(G)
LET FUNCTION F2 = DERIVATIVE F WRT X
Functions Can Be Concatenated Functions can be concatenated and built-up piece-by-piece, as in
LET FUNCTION NUM = EXP(-ALPHA*X)
LET FUNCTION DENOM = A+B*X
LET FUNCTION RATIO = NUM/DENOM
which is equivalent to
LET FUNCTION RATIO = EXP(-ALPHA+X)/(A+B X)
Parameters and Variables Need Not Be Defined First Functions can be defined before (or after) the parameters and variables contained in them are created, as in the following example involving a variable transformation:
LET FUNCTION F = X**2
.
1 2 3
END OF DATA
.
LET Y = F
This last statement (LET Y = F) is equivalent to
LET Y = X**2
and will (upon execution) result in the Y variable having the values 1, 4, and 9.

A more common example of functions being defined prior to use is in fitting:

LET FUNCTION Fl = A1+B1*SQRT(X)
LET FUNCTION F2 = A2+82*LOG(X)
.
1 1
2 1.5
3 2
4 2.3
5 2.5
END OP DATA
.
FIT Y = F1
FIT F = F2
Built-In Functions Dataplot provides a large number of built-in functions which can be used in user-defined functions.
Dataplot  / Dataplot Elementary Operations ]

Evaluating Functions

Distinction Between LET FUNCTION and LET The LET FUNCTION command and the LET command carry out two distinctly different operations. The LET FUNCTION command allows the analyst to create functions; the LET command allows the analyst to carry out function evaluations.
Example of the Distinction For example, suppose it is desired to evaluate the function sqrt(1-0.3*x**2) over the region x = 0 (.01) 2. This may be done in a number of ways. The most direct way is
LET X = SEQUENCE 0 .01 1
LET Y = SQRT(1-0.3*X**2)
WRITE X Y
PLOT Y X
The first LET command makes use of the SEQUENCE sub-capability of the LET command to create the variable X vith a sequence of 101 values in it--.00, .01, .02, 03, ..., .99, 1.00. The second LET command creates a variable Y (also with 101 elements) which has the desired function evalution va1ues in it. The WRITE command generates a list of X and Y values. The PLOT command will generate a plot of Y (vertically) versus X (horizontally).

A second way to evaluate the function would be

LET X = SEQUENCE 0 .01 1
LET FUNCTION F = SQRT(1-0.3*X**2)
LET Y = F
WRITE X Y
PLOT Y X
As before, the first LET statement would create the variable X with the specified sequence of 101 values. The LET FUNCTION command would then create the function F consisting of the following 16 characters--SQRT(1-0.3*X**2) . Note that the LET FUNCTION does not perform a function evaluation--it merely creates a function. The LET Y = F command would then recognize F as a pre-defined function, replace the name F with the specified 16-character string, and carry out the function evaluation. As before, the WRITE command prints out the results of the function evaluation and the PLOT command plots out the results of the function evaluation.

Note that if our ultimate objective is to simply plot the function (rather than creating variables containing evaluated values of the function), then the above code could be shortened directly to

PLOT SQRT(1-0.3+X**2) FOR X = 0 .01 1
or
LET FUNCTION F = SQRT(1-0.3+X**2)
PLOT F FOR X = 0 .01 1
Dataplot  / Dataplot Elementary Operations ]

LET Sub-Commands

LET Single Most Powerful Dataplot Command The LET command is the single most powerful commmand in DATAPLOT. The most important capability of the LET command is performing function evaluations and variable transformations. Such evaluations/transformations are general--any Fortran-like expression can be used.
Four General Categories of LET Sub-
Commands
In addition, the LET command can also be used to perform a broad spectrum of statistical, mathematical, and manipulative operations. These operations are specified by inclusion of sub-commands under the LET command. These sub-cammands fall into four general categories:

NIST is an agency of the U.S. Commerce Department.

Date created: 06/05/2001
Last updated: 09/20/2016