next up previous contents index
Next: Math Functions Up: Plots, Vectors and Expressions Previous: The constants Plot   Contents   Index


Operators in Expressions

The operations available in vector expressions are listed below. They all take two operands, except for unary minus and negation.

addition operator: +
Add the two operands.

subtraction amd negation operator: -
Evaluates to the first argument minus the second, and also may be used as unary minus. In commands that take a list of vectors as arguments, such as plot, one can force a unary minus with '-', for example:
plot v(1) -v(4)
would plot v(1)-v(4) (i.e., the difference) whereas
plot v(1) -v(4)
would plot v(1) and -v(4) (two traces).

multiply operator: *
Multiply the two operands.

divide operator: /
The first operand divided by the second.

modulo operator: %
This operates in the manner of the C fmod() function, returning the remainder. That is, for x%y, the value of x-i*y is returned for some integer i such that the result has the same sign of x and magnitude less than the magnitude of y. An error is indicated if y is zero. If x or y is complex, the magnitudes are used in the division.

power operator: ^
Evaluates to the first operand raised to the power of the second.

and operator: & or and
Evaluates to 1 if both operands are non-zero, 0 otherwise.

or operator: | or or
Evaluates to 1 if either of the two operands is nonzero, 0 otherwise.

not operator: ~ or not
Evaluates to 1 if the operand is 0, 0 otherwise.

greater-than operator: > or gt
Evaluates to 1 if the first operand is greater than the second, 0 otherwise.

greater-than-or-equal operator: > = or ge
Evaluates to 1 if the first operand is greater than or equal to the second, 0 otherwise.

less-than operator: < or lt
Evaluates to 1 if the first argument is less than the second, 0 otherwise.

less-than-or-equal operator: < = or le
Evaluates to 1 if the first argument is less than or equal to the second, 0 otherwise.

not-equal operator: < > or ne
Evaluates to 1 if the two operands are not equal, 0 otherwise.

equal operator: = or eq
Evaluates to 1 if both operands are equal, 0 otherwise.

comma operator: ,
The notation a,b refers to the complex number with real part a and imaginary part b. Such a construction may not be used in the argument list to a macro function, however, since commas are used to separate the arguments and parentheses may be ignored. The expression a + j(b) is equivalent. The comma does not behave as an operation (return a value) as it does in C.

The logical operations are & (and), | (or), ~ (not), and their synonyms. A nonzero operand is considered ``true''. The relational operations are <, >, < =, > =, =, and < > (not equal), and their synonyms. If used in an algebraic expression they work like they would in C, producing values of 0 or 1. The synonyms are useful when < and > might be confused with IO redirection (which is almost always).

Vectors may be indexed by value[index] or value[low,high].

The first notation refers to the index'th element of value. The second notation refers to all of the elements of value which fall between the high'th and the low'th element, inclusive. If high is less than low, the order of the elements in the result is reversed. Note that a complex index will have the same effect as using the real part for the lower value and the imaginary part for the upper, since this is the way the parser reads this expression. Multi-dimensional vectors are referenced as Vec[indN][indN-1]...[ind0], where each of the indI can be a range, or single value. The range must be within the vector's spanning space. If fewer than the vector's dimensions are specified, the resulting object is a sub-dimensional vector.

Finally, there is the ran operator: value1[[value2]] or value[[low,high]].

The first notation refers to all the elements of value1 for which the element of the corresponding scale equals value2. The second notation refers to all of the elements of value for which the corresponding elements of the scale fall between high and low, inclusive. If high is less than low, the order of the elements in the result is reversed.


next up previous contents index
Next: Math Functions Up: Plots, Vectors and Expressions Previous: The constants Plot   Contents   Index
Stephen R. Whiteley 2006-10-23