octave: Arithmetic Ops
8.3 Arithmetic Operators
========================
The following arithmetic operators are available, and work on scalars
and matrices. The element-by-element operators and functions broadcast
(Broadcasting).
X + Y
Addition. If both operands are matrices, the number of rows and
columns must both agree, or they must be broadcastable to the same
shape.
X .+ Y
Element-by-element addition. This operator is equivalent to ‘+’.
X - Y
Subtraction. If both operands are matrices, the number of rows and
columns of both must agree, or they must be broadcastable to the
same shape.
X .- Y
Element-by-element subtraction. This operator is equivalent to
‘-’.
X * Y
Matrix multiplication. The number of columns of X must agree with
the number of rows of Y.
X .* Y
Element-by-element multiplication. If both operands are matrices,
the number of rows and columns must both agree, or they must be
broadcastable to the same shape.
X / Y
Right division. This is conceptually equivalent to the expression
(inverse (y') * x')'
but it is computed without forming the inverse of Y’.
If the system is not square, or if the coefficient matrix is
singular, a minimum norm solution is computed.
X ./ Y
Element-by-element right division.
X \ Y
Left division. This is conceptually equivalent to the expression
inverse (x) * y
but it is computed without forming the inverse of X.
If the system is not square, or if the coefficient matrix is
singular, a minimum norm solution is computed.
X .\ Y
Element-by-element left division. Each element of Y is divided by
each corresponding element of X.
X ^ Y
X ** Y
Power operator. If X and Y are both scalars, this operator returns
X raised to the power Y. If X is a scalar and Y is a square
matrix, the result is computed using an eigenvalue expansion. If X
is a square matrix, the result is computed by repeated
multiplication if Y is an integer, and by an eigenvalue expansion
if Y is not an integer. An error results if both X and Y are
matrices.
The implementation of this operator needs to be improved.
X .^ Y
X .** Y
Element-by-element power operator. If both operands are matrices,
the number of rows and columns must both agree, or they must be
broadcastable to the same shape. If several complex results are
possible, the one with smallest non-negative argument (angle) is
taken. This rule may return a complex root even when a real root
is also possible. Use ‘realpow’, ‘realsqrt’, ‘cbrt’, or ‘nthroot’
if a real result is preferred.
-X
Negation.
+X
Unary plus. This operator has no effect on the operand.
X’
Complex conjugate transpose. For real arguments, this operator is
the same as the transpose operator. For complex arguments, this
operator is equivalent to the expression
conj (x.')
X.’
Transpose.
Note that because Octave’s element-by-element operators begin with a
‘.’, there is a possible ambiguity for statements like
1./m
because the period could be interpreted either as part of the constant
or as part of the operator. To resolve this conflict, Octave treats the
expression as if you had typed
(1) ./ m
and not
(1.) / m
Although this is inconsistent with the normal behavior of Octave’s
lexer, which usually prefers to break the input into tokens by
preferring the longest possible match at any given point, it is more
useful in this case.
-- : ctranspose (X)
Return the complex conjugate transpose of X.
This function and X’ are equivalent.
See also: transpose XREFtranspose.
-- : ldivide (X, Y)
Return the element-by-element left division of X and Y.
This function and X .\ Y are equivalent.
See also: rdivide XREFrdivide, mldivide XREFmldivide,
times XREFtimes, plus XREFplus.
-- : minus (X, Y)
This function and X - Y are equivalent.
See also: plus XREFplus, uminus XREFuminus.
-- : mldivide (X, Y)
Return the matrix left division of X and Y.
This function and X \ Y are equivalent.
See also: mrdivide XREFmrdivide, ldivide XREFldivide,
rdivide XREFrdivide.
-- : mpower (X, Y)
Return the matrix power operation of X raised to the Y power.
This function and X ^ Y are equivalent.
DONTPRINTYET See also: power XREFpower, mtimes XREFmtimes, *noteDONTPRINTYET See also: power XREFpower, mtimes XREFmtimes,
plus XREFplus, minus XREFminus.
-- : mrdivide (X, Y)
Return the matrix right division of X and Y.
This function and X / Y are equivalent.
See also: mldivide XREFmldivide, rdivide XREFrdivide,
plus XREFplus, minus XREFminus.
-- : mtimes (X, Y)
-- : mtimes (X1, X2, ...)
Return the matrix multiplication product of inputs.
This function and X * Y are equivalent. If more arguments are
given, the multiplication is applied cumulatively from left to
right:
(...((X1 * X2) * X3) * ...)
At least one argument is required.
DONTPRINTYET See also: times XREFtimes, plus XREFplus, *noteDONTPRINTYET DONTPRINTYET See also: times XREFtimes, plus XREFplus,
minus XREFminus, rdivide XREFrdivide, *notemrdivide:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: times XREFtimes, plus XREFplus,
minus XREFminus, rdivide XREFrdivide, mrdivide
XREFmrdivide, mldivide XREFmldivide, *notempower:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: times XREFtimes, plus XREFplus,
minus XREFminus, rdivide XREFrdivide, mrdivide
XREFmrdivide, mldivide XREFmldivide, mpower
XREFmpower.
-- : plus (X, Y)
-- : plus (X1, X2, ...)
This function and X + Y are equivalent.
If more arguments are given, the summation is applied cumulatively
from left to right:
(...((X1 + X2) + X3) + ...)
At least one argument is required.
See also: minus XREFminus, uplus XREFuplus.
-- : power (X, Y)
Return the element-by-element operation of X raised to the Y power.
This function and X .^ Y are equivalent.
If several complex results are possible, returns the one with
smallest non-negative argument (angle). Use ‘realpow’, ‘realsqrt’,
‘cbrt’, or ‘nthroot’ if a real result is preferred.
See also: mpower XREFmpower, realpow XREFrealpow,
DONTPRINTYET realsqrt XREFrealsqrt, cbrt XREFcbrt, *notenthroot:
DONTPRINTYET realsqrt XREFrealsqrt, cbrt XREFcbrt, nthroot
XREFnthroot.
-- : rdivide (X, Y)
Return the element-by-element right division of X and Y.
This function and X ./ Y are equivalent.
See also: ldivide XREFldivide, mrdivide XREFmrdivide,
times XREFtimes, plus XREFplus.
-- : times (X, Y)
-- : times (X1, X2, ...)
Return the element-by-element multiplication product of inputs.
This function and X .* Y are equivalent. If more arguments are
given, the multiplication is applied cumulatively from left to
right:
(...((X1 .* X2) .* X3) .* ...)
At least one argument is required.
See also: mtimes XREFmtimes, rdivide XREFrdivide.
-- : transpose (X)
Return the transpose of X.
This function and X.’ are equivalent.
See also: ctranspose XREFctranspose.
-- : uminus (X)
This function and - X are equivalent.
See also: uplus XREFuplus, minus XREFminus.
-- : uplus (X)
This function and + X are equivalent.
DONTPRINTYET See also: uminus XREFuminus, plus XREFplus, *noteDONTPRINTYET See also: uminus XREFuminus, plus XREFplus,
minus XREFminus.