### 8.3 Arithmetic Operators ¶

The following arithmetic operators are available, and work on scalars and matrices. The element-by-element operators and functions broadcast (see Broadcasting).

x + y ¶

  Addition (always works element by element). 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 ¶

  Subtraction (always works element by element). 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 ¶

  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

      (inv (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

      inv (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 ¶

  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 ¶

  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.

Note also that some combinations of binary operators and whitespace can create apparent ambiguities with the Command Syntax form of calling functions. See Command Syntax and Function Syntax for a description of how Octave treats that syntax.

`B =` ctranspose `(A)` ¶

  Return the complex conjugate transpose of A.

  This function and `A'` are equivalent.

  See also: transpose.

`y =` pagectranspose `(A)` ¶

  Return the page-wise complex conjugate transpose of the N-dimensional array A.

  This is equivalent to `A(:,:, k)'` for each page k.

  See also: pagetranspose, ctranspose, permute.

`C =` ldivide `(A, B)` ¶

  Return the element-by-element left division of A and B.

  This function and `A .\ B` are equivalent.

  See also: rdivide, mldivide, times, plus.

`C =` minus `(A, B)` ¶

  This function and `A - B` are equivalent.

  See also: plus, uminus.

`C =` mldivide `(A, B)` ¶

  Return the matrix left division of A and B.

  This function and `A \ B` are equivalent.

  If the system is not square, or if the coefficient matrix is singular, a minimum norm solution is computed.

  See also: mrdivide, ldivide, rdivide, linsolve.

`C =` mpower `(A, B)` ¶

  Return the matrix power operation of A raised to the B power.

  This function and `A ^ B` are equivalent.

  See also: power, mtimes, plus, minus.

`C =` mrdivide `(A, B)` ¶

  Return the matrix right division of A and B.

  This function and `A / B` are equivalent.

  If the system is not square, or if the coefficient matrix is singular, a minimum norm solution is computed.

  See also: mldivide, rdivide, plus, minus.

`C =` mtimes `(A, B)` ¶
`C =` mtimes `(A1, A2, …)` ¶

  Return the matrix multiplication product of inputs.

  This function and `A * B` are equivalent. If more arguments are given, the multiplication is applied cumulatively from left to right:

      (...((A1 * A2) * A3) * ...)

  See also: times, plus, minus, rdivide, mrdivide, mldivide, mpower, tensorprod.

`C =` plus `(A, B)` ¶
`C =` plus `(A1, A2, …)` ¶

  This function and `A + B` are equivalent.

  If more arguments are given, the summation is applied cumulatively from left to right:

      (...((A1 + A2) + A3) + ...)

  See also: minus, uplus.

`C =` power `(A, B)` ¶

  Return the element-by-element operation of A raised to the B power.

  This function and `A .^ B` 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, realpow, realsqrt, cbrt, nthroot.

`C =` rdivide `(A, B)` ¶

  Return the element-by-element right division of A and B.

  This function and `A ./ B` are equivalent.

  See also: ldivide, mrdivide, times, plus.

`C =` times `(A, B)` ¶
`C =` times `(A1, A2, …)` ¶

  Return the element-by-element multiplication product of inputs.

  This function and `A .* B` are equivalent. If more arguments are given, the multiplication is applied cumulatively from left to right:

      (...((A1 .* A2) .* A3) .* ...)

  See also: mtimes, rdivide.

`B =` transpose `(A)` ¶

  Return the transpose of A.

  This function and `A.'` are equivalent.

  See also: ctranspose.

`B =` pagetranspose `(A)` ¶

  Return the page-wise transpose of the N-dimensional array A.

  This is equivalent to `A(:,:, k).'` for each page k.

  See also: pagectranspose, transpose, permute.

`B =` uminus `(A)` ¶

  This function and `- A` are equivalent.

  See also: uplus, minus.

`B =` uplus `(A)` ¶

  This function and `+ A` are equivalent.

  See also: uminus, plus.