DATAPLOT Data Types
You do not need to pre-specify data types. DATAPLOT automatically
determines the correct data type based on usage. In fact, the
DATAPLOT language does not provide any data typing commands. In
most cases, you do not need to worry about correct data types.
Dataplot stores numbers internally as single precision floating
point numbers. Some internal calculations (e.g., fitting) are
performed using double precision arithmetic. However, the results
are saved in single precision. On some platforms (e.g., SUN and
most Unix workstations), Dataplot can be built in such a way that
single precision defaults to double precision. For most applications,
this should not be necessary. Contact the Dataplot authors if you
would like more information about this.
Dataplot recognizes the following data types
- Numbers
- Parameters
- Variables
- Strings
- Matrices
- Complex Numbers
Numbers
Numbers are unnamed scalars. They may appear in a variety of
different kinds of commands; note the 20 and 50 in
BOX 20 20 50 50
Note the 0, .1 and 10 in
PLOT SIN(X) FOR X = 0 .1 10
Note the 2.5 in
LET Y = X+2.5
Note the 2 in
FIT F = A+B*X+C+X**2
With the exception of the FIT and PRE-FIT commands, the general rule
in DATAPLOT is that anywhere a number appears in a command line, it
could equally well have been replaced by a parameter, as in the
following analogues to the above--
LET X1 = 20
LET Y1 = 20
LET X2 = 50
LET Y2 = 50
BOX X1 Y1 X2 Y2
LET START = 0
LET INC = .1
LET STOP = 10
PLOT SIN(X) FOR X = START INC STOP
LET A = 2.5
LET Y = X+A
However, note that expressions involving numbers and parameters
are not necessarily interchangeable with numbers and parameters.
For example, the following is NOT valid
BOX X1+20 Y1-10 X2+5 Y2-3
This should be coded in DATAPLOT as follows
LET X1 = X1+20
LET Y1 = Y1-10
LET X2 = X2+5
LET Y2 = Y2-3
BOX X1 Y1 X2 Y2
The FIT and PRE-FIT commands are an exception because the command
lines
LET D =2
FIT Y = A+B*X+C*X**D
will not be treated in the same manner as
FIT Y = A+B*X+C*X**2
In the first case, DATAPLOT will realize that D is a parameter and
so (like all parameters appearing in a fit) will determine the least
squares estimate for the parameter D along with the other parameters
A, B, and C. However, in the second case (FIT Y = A+B*X+C*X**2),
DATAPLOT will note the scalar number 2 and fit for the parameters A,
B, and C only. Be aware of this distinction in carrying out fits and
pre-fits.
All numbers are stored internally in DATAPLOT as single precision
floating point. If the analyst wishes to specify a decimal number,
as in
LET Y = X*"2.378
then the decimal point and trailing decimal digit
should of course be included. However, if the
number happens to be an integer, then the
analyst has the choice of including or excluding
the trailing decimal point, and including or
excluding any trailing zeros--thus the following
are all equivalent--
LET Y = X**2
LET Y = X**2.
LET Y = X**2.0
LET Y = X"*2.00
All such expressions will be stored and processed internally by
DATAPLOT in an identical fashion--the analyst gains nothing by
including the trailing decimal point and zeros. Simplicity
dictates that the first form be used, but if the analyst prefers
to use other forms, the results will be identical.
To define numbers with large exponents (for example, 7.4 raised to
the 15th power), the analyst should use the ** (exponentiation)
operator directly, as in
LET A = 7.4**15
The E format (as occurs in FORTRAN) is not permitted; thus
LET A = 7.4E15
is not a valid DATAPLOT command.
Negative exponents are handled in a similar fashion, as in
LET B = 7.4*" (-15)
Main Menu
Parameters
A parameter is a named scalar and can be defined via the LET command,
as in
LET A = 27.26
LET B = 3.97
LET C = -5.38
LET D = 2.4*10**(-8)
LET E = B**2-4*A*C
LET F = MEAN X
Two internally-provided parameters which the analyst can use are
PI
INFINITY
PI has the value 3.14159265; INFINITY has the
value of the largest floating point number which
the user's computer can store (that is,
INFINITY = machine infinity). PI and INFINITY can be
used at any time and like any other user-defined parameter. For example,
PLOT (1/SQRT(2*PI))*EXP(-0.5*X**2) FOR X = -3 .1 3
FIT Y = A+B*X**C EXCEPT X 100 TO INFINITY
Be wary of the use of PI in FIT and PRE-FIT
expressions; like all parameters, DATAPLOT will
attempt to determine least squares estimates for it.
Thus rather than use
FIT Y = AMP * SIN(2*PI*F*X)
one should explicitly use
FIT F = AMP * SIN(2*3.14159265*F*X)
With the exception of the above-mentioned FIT and
PRE-FIT exclusion, parameters can be substituted
anywhere that numbers appear. For example,
suppose the analyst wished to override the usual
plot frame coordinates and specify that all
succeeding plots have lower left corner at (20,50)
and for the plot to be 30 units wide and 30 units high
(that is, have the upper right corner at (50,80). This can
be done explicitly by
FRAME CORNER COORDINATES 20 50 50 80
or alternatively
LET X1 = 20
LET Y1 = 50
LET X2 = 50
LET Y2 = 80
FRAME CORNER COORDINATES X1 Y1 X2 Y2
or
LET X1 = 20
LET Y1 = 50
LET X2 = X1+30
LET Y2 = Y1+30
FRAME CORNER COORDINATES X1 Y1 X2 Y2
This capability of substituting parameters for
numbers is especially convenient for diagram
construction on terminals which have bui1t-in
hardware for inputting screen coordinates via
cross-hair, 1ight-pen, or equivalent. Suppose
it is desired to draw a line betveen 2 points on
the screen which the analyst will interactively
specify via the cross-hair. One way is to
- raise the cross-hair (via CROSS-HAIR);
- position it to the first point (via the thumbwheels);
- input and print the coordinates (via hitting any key (on Tektronix
terminals), or by hicting some predesignated key (on other
terminals);
- raise the cross-hair (via CROSS-HAIR);
- position it to the second point (via the thumbwheels);
- print the coordinates (via hitting any key);
- drav the line (via, for example, DRAW 20.4 35.3 78.4 80.5).
An easier way which avoids the handling of
absolute numbers and replaces it with the handling
of symbolic parameter names is
- raise the cross-hair (via CROSS-HAIR X1 Y1);
- position it to the first point (via the thumbwheels);
- copy the coordinates into X1 and Y1 (via hitting any key);
- raise the cross-hair (via CROSS-HAIR X2 Y2);
- position it to the second point (via thumbwheels);
- copy the coordinates into X2 and Y2 (via hitting any key);
- draw the line (via DRAW X1 Y1 X2 Y2).
Main Menu
Variables
A variable is a named vector (a named single-dimension array), and can
be defined via the LET, READ, SERIAL READ, and DATA commands, as in
the following examples
LET Y = SEQUENCE 1 1 10
LET Z = PATTERN 1 2 3 FOR I = 1 2 9
LET U = NORMAL RANDOM NUMBERS FOR I = 1 1 100
LET X2 = X**2-LOG(Y)
LET Y2 = SQRT(X+Y**3)
LET Y = DATA 1 5 10 25 34 46 22 17
or
READ X Y
1 1
2 4
3 9
4 16
5 25
END OF DATA
or
SERIAL READ X Y
1 1 2 4 3 9 4 16 5 25
END OF DATA
Variables are the most commonly-handled component in DATAPLOT, as in
PLOT Y X
FIT Y = A+B*LOG(X+C)
LET X2 = LOG(X)
Names for variab1es, parameters, and functions may be of any length, but
since only the first 8 characters are scanned and internally stored, no 2
names should be identical for the first 8 characters. Names must start with
an alphabetic character, but may be any combination of alphabetic and
numeric characters thereafter. It is the author's personal practice
to follow the usual mathematical custom of using characters toward the
end of the alphabet (X's, Y's, Z's, etc.) to represent variables, of
using characters toward the beginning of the alphabet (A's, B's, C's, etc.)
to represent parameters, and of using characters in the vicinity of F
(e.g., F's, G's, H's, etc.) to represent functions. Note, however, that
this is a personal preference and not a DATAPLOT requirement.
Main Menu
Strings
Dataplot provides limited support for strings. The most common usage
of strings is in labeling plots. Strings can be particularly useful
in this regard for reading titles and labels from a file in general
purpose macros. Another common usage is building file names in loops.
For example, suppose you want to perform the same analysis on the
files CALIB1.DAT to CALIB100.DAT. This can be encapsulated in a loop
as follows:
LET STRING BASE = CALIB
LET STRING EXT = .DAT
LOOP FOR K = 1 1 100
LET STRING NUMBER = ^K
LET STRING FILE = ^BASE&^NUMBER&^EXT
READ ^FILE X1 TO X10
... REST OF ANALYSIS
END OF LOOP
The above loop demonstrates the two operators that Dataplot provides
for manipulating and using strings. The
^ character is the Dataplot
substitute
character. It replaces the succeeding string or parameter with the
value of that string or paramaeter. This substitution is done before
the command is parsed, so it is very general. The
& character is the Dataplot
concatenate
character. It is used by Dataplot to concatenate two strings
together. At this time, Dataplot does not support any functions
for extracting a subset of a string.
There are two commands for creating strings in Dataplot. The
READ STRING command is used
to read a string from a file. The LET STRING command, demonstrated
in the loop above, can also be used. Both of these commands
preserve the case of the string as entered (versions of Dataplot
prior to 4/96 may convert all characters to upper case for the
LET STRING command).
Dataplot does not currently support arrays of strings. However,
this capability can be mimicked somewhat with the use of the
substitute character (^). For example, suppose you have the 50
state names in a file, one state per line. You can read these
into the strings S1 to S50 as follows:
LOOP FOR K = 1 1 50
LET NSKIP = K - 1
SKIP NSKIP
READ STATES.DAT S^K
END OF LOOP
The following example shows how to loop through the strings
and print them out.
LET XPOS = 50
LET YPOS = 97
LET YINC = 3
LOOP FOR K = 1 1 50
MOVE XPOS YPOS
TEXT ^S^K
LET YPOS = YPOS - YINC
IF YPOS < 5
YPOS = 97
END OF IF
END OF LOOP
Main Menu
Matrices
Matrices and matrix manipulation commands are useful for solving
linear algebra problems. They also find common usage in
multivariate statistics. For example, Dataplot provides macros
for performing discriminant analysis, canonical correlation, and
bi-plots using the matrix commands.
Dataplot provides the following commands for creating and using
matrices:
CHOLESKY DECOMPOSITION,
CORRELATION MATRIX,
DIAGONAL MATRIX,
MATRIX ADDITION,
MATRIX ADJOINT,
MATRIX AUGMENT,
MATRIX COFACTOR,
MATRIX DETERMINANT,
MATRIX DIAGONAL,
MATRIX DEFINITION,
MATRIX EIGENVALUES,
MATRIX EIGENVECTORS,
MATRIX ELEMENT,
MATRIX EUCLIDEAN NORM,
MATRIX INVERSE,
MATRIX ITERATIVE SOLUTION,
MATRIX MINOR,
MATRIX MULTIPLICATION,
MATRIX NUMBER OF COLUMNS,
MATRIX NUMBER OF ROWS,
MATRIX RANK,
MATRIX REPLACE ELEMENT,
MATRIX REPLACE ROW,
MATRIX ROW,
MATRIX SIMPLEX SOLUTION,
MATRIX SOLUTION,
MATRIX SPECTRAL NORM,
MATRIX SPECTRAL RADIUS,
MATRIX SUBMATRIX,
MATRIX SUBTRACTION,
MATRIX TRACE,
MATRIX TRANSPOSE,
PRINCIPAL COMPONENTS,
SINGULAR VALUES,
SINGULAR VALUE DECOMPOSITION,
SINGULAR VALUE FACTORIZATION,
TRIANGULAR INVERSE,
TRIANGULAR SOLUTION, and
TRIDIAGONAL SOLUTION.
Matrices are created with either the
READ MATRIX or the
MATRIX DEFINITION command.
The columns of the matrix can be accessed by appending the column
number to the matrix name (e.g., the columns of matrix M can be
accessed via M1, M2, etc.). The rows of the matrix cannot be
accessed directly. However, the MATRIX ROW command can be used
to copy the contents of a matrix row to a column vector. A single
element of an array can be extracted with the MATRIX ELEMENT command
or by using something like M3(5) (this refers to the element in
column 3 and row 5). Matrices cannot be used outside of the commands
listed above. For example, you cannot enter LET S = SIN(M) where M is
a matrix to compute the sine of all elements in a matrix.
Main Menu
Complex Numbers
Dataplot operations and built-in functions assume single precision
floating point numbers. In general, these cannot be replaced with
complex numbers.
The following LET sub-commands specifically operate on complex
numbers (the complex numbers are provided as a pair of real
numbers):
COMPLEX ADDITION,
COMPLEX CONJUGATE,
COMPLEX DIVISION,
COMPLEX EXPONENTIATION,
COMPLEX MULTIPLICATION,
COMPLEX ROOTS,
COMPLEX SQUARE ROOT, and
COMPLEX SUBTRACTION.
In addition, a number of built-in library functions can work with
complex numbers. These can be somewhat cumbersome since the real
and complex component are extracted with distinct functions.
For example, to compute the complex sin of a complex number,
enter the following 2 commands:
LET AR = CSIN(-2,1)
LET AC = CSIN(-2,1)
The parameter AR will contain the real component and the parameter
AC will contain the complex component.
The following built-in functions support complex numbers:
CABS (complex absolute value),
CBESSI (complex modified
Bessel function),
CBESSJ (complex
Bessel function of the first kind),
CBESSK (complex modified
Bessel function of the third kind),
CBESSY (complex
Bessel function of the second kind),
CCOS (complex cosine),
CEXP (complex exponential),
CLOG (complex natural logarithm),
CSIN (complex sine), and
CSQRT (complex square root).
Main Menu