In the introductory example in Section 1.1, we have only considered two numbers 1 and 2, and the addition operator +. Other standard operators are available:
2*2+3gives in the output window
7since the operator * has precedence on the operator +. Thus, the computation 2*2 is carried out first and gives 4 as result, which is added to 3 to yield 7.
The exponent operator
has the highest level of precedence.
Next, the operators *
and /
have the same order of precedence, and
have precedence over the operators +
and -.
As in standard paper and pencil calculus, you can force these
precedence rules by using parentheses: the command line
(3*4)^2gives
144as the expression (3*4) is enclosed in parentheses, and is then evaluated independently from the other operations. The outcome of this operation, 12, is squared to obtain 144.
As in pencil and paper calculus, parentheses could be nested, although left and right parentheses must match. Assume that you enter the instruction:
(1+(3*4)^2which is incomplete since the two left parentheses are matched by only one right parenthesis. This incomplete instruction ends in a error message, i.e. the syntax analyzer of XploRe , or parser, has detected that something went wrong and gives the cause of the mistake.
In the previous subsection, we have considered numeric expressions which -- once evaluated -- are ``lost'' since they are not stored anywhere. If you need to keep the result of a numeric expression for further calculation, you can store it in a precise location by assigning it to a variable.
The assignment is done with the assignment operator denoted by the symbol = which means ``equal''. For example,
a = 2*3assigns the value 6 to the variable a.
We assign a variable by either storing in it a number or the content of another variable. The following command
b = aassigns into the variable b the content of the variable a. We can verify this by displaying the content of b by typing its name:
bprints
Contents of b [1,] 6in the output window.
The name of a variable should be a string of alphabetic or numeric characters: a, b, product, result are possible variable names. Not allowed for the use in variable names are spaces (blanks) and underscore symbols (_).
The XploRe parser is case sensitive, i.e. the variables a, A, as well as result, Result, ResulT and RESULT are considered as distinct. Thus, assigning the value 5 to the variable A
A = 5does not affect the content of the variable a which still contains the number 6. We display the content of both A and a by typing
A awhich gives in the output window
Contents of A [1,] 5 Contents of a [1,] 6
Lastly, some labels which represent standard constants in
XploRe
are
protected and cannot be used as variable names. These are
pi for the constant
3.1415926...
and eh for the constant
2.7182818....
The environment XploRe provides several hundreds of functions for data handling, statistical data analysis, graphics and user interaction. There are two types of functions:
Among the commands, you find all important mathematical functions, such as
![]() ![]() ![]() |
logarithm and exponential functions |
![]() ![]() ![]() |
trigonometric functions |
![]() |
absolute value |
![]() |
square root |
![]() ![]() ![]() |
rounding functions |
Since XploRe is a matrix-oriented language, applying a mathematical function to a data matrix means that the function is applied to all elements of this matrix. For example,
x=#(1,2,3) ; vector of 1, 2, and 3 log(x)returns
Contents of log [1,] 0 [2,] 0.69315 [3,] 1.0986i.e. the
Quantlets are used in the same way
as the built-in commands, except for the fact that
a quantlib has to be loaded first. For example, the
function
mean
is a built-in command while
the function
median
is a quantlet from the
xplore
library. If you want to compute the
median of a data vector, you first have to load
the
xplore
library:
library("xplore") x=#(1,2,3) ; vector of 1, 2, and 3 median(x)To find out which library a function belongs to, consult the APSS help file of this function.
Any file which consists of XploRe instructions is called a quantlet. Quantlets are saved as text files using the file extension .xpl.
We use the term quantlet for two types of .xpl files:
All quantlet files can be loaded by using
the Open item from the
Program menu. This opens an
editor window containing the quantlet code.
We execute the quantlet
by clicking the Execute item in the menu bar
or by entering Alt E
.
If the quantlet contains a code to be executed line by line, the execution is immediately started. If the quantlet defines a procedure, an additional instruction to carry out the procedure is required. We recommend to study Quantlets and Quantlibs (17) for using such procedure quantlets.