# Arithmetic Operations¶

## Elementary Arithmetic¶

### zeros¶

Syntax

```zeros
zeros(dimensions…)
zeros(dimensions…, assumedType)
```

Description

Returns an array containing all zero elements.

• When called with no arguments, `zeros` will return the scalar value `0`.
• If `dimensions` are provided, they must contain non-negative integers supplying the dimensions of the array to be returned.
• If called with a scalar, `zeros(n)`, this operator will return a square `n x n` matrix filled with zeros.
• If `assumedType` is provided, it creates an array of zeros of the given data type. When `single` type is provided, no conversion to single precision is performed, it remains a double precision value.

### ones¶

Syntax

```ones
ones(dimensions…)
ones(dimensions…, assumedType)
```

Description

Returns an array whose elements all contain the scalar value one.

• When called with no arguments, `ones` will return the scalar value `1`.
• If `dimensions` are provided, they must contain non-negative integers supplying the dimensions of the array to be returned.
• If called with a scalar, `ones(n)`, this operator will return a square `n x n` matrix filled with ones.
• If `assumedType` is provided, it creates an array of ones of the given data type. When `single` type is provided, no conversion to single precision is performed, it remains a double precision value.

### uplus¶

Syntax

```uplus(x)
+x
```

Description

Unary plus returns the value of the operand `x`.

### uminus¶

Syntax

```uminus(x)
-x
```

Description

Unary minus returns the negation of the operand, `x`.

### plus¶

Syntax

```x + y
plus(x,y)
```

Description

Perform elementwise addition of two operands, `x` and `y`. If both `x` and `y` are arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before addition. Note that `x` and `y` may be symbolic.

### minus¶

Syntax

```x - y
minus(x,y)
```

Description

Perform elementwise subtraction of two operands, `x` and `y`. If both `x` and `y` are arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before subtraction. Note that `x` and `y` may be symbolic.

### times¶

Syntax

```x .* y
times(x,y)
```

Description

Multiply each element in `x` by the corresponding element in `y`. If both `x` and `y` are arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before multiplication. Note that `x` and `y` may be symbolic.

### mod¶

Syntax

```mod(x,y)
```

Description

The modulo operation returns the remainder of `x` after division by operand `y`. Both inputs are required to be real.

• Note that the dividend `x` and divisor `y` may be symbolic. However, whenever the divisor is symbolic the resulting expression will be non-linear. You will need to configure Grackle to use a solver that supports non-linear equations, see Constraint Solving.

### ldivide¶

Syntax

```a .\ b
ldivide(a,b)
```

Description

The left array division operator will divide each element in `a` by the corresponding element in `b`. If both `a` and `b` are arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before division.

• If the divisor is symbolic, you will need to configure Grackle to use a solver that supports non linear equations, see Constraint Solving.

### rdivide¶

Syntax

```b ./ a
rdivide(b,a)
```

Description

The right array division operator will divide each element in `b` by the corresponding element in `a`. If both `a` and `b` are arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before division.

• If the divisor is symbolic, you will need to configure Grackle to use a solver that supports non-linear equations, see Constraint Solving.

### mtimes¶

Syntax

```x * y
mtimes(x,y)
```

Description

Multiplication of two matrices, `x` and `y`. The number of columns in `x` must be equal to the number of rows in `y` for the matrices to multiply properly.

• If either input is a scalar, the resulting operation is equivalent to `times` or `.*`. Note that `x` and `y` may be symbolic.

### mldivide¶

Syntax

```a \ b
mldivide(a,b)
```

Description

The matrix left division operator will divide each element in `b` by the scalar value, `a`. It does not currently support solving a system of linear equations of the form `a*x = b` for `x`.

• Since `mldivide` suports division by a scalar value only, the resulting operation is equivalent to `ldivide` or `.\`.

### mrdivide¶

Syntax

```b / a
mrdivide(b,a)
```

Description

The matrix right divide operator will divide each element in `b` by the scalar, `a`. It does not currently support solving a system of linear equations of the form `x*a = b` for `x`.

• Since `mrdivide` suports division by a scalar value only, the resulting operation should be equivalent to `rdivide` or `./`.

### mpower¶

Syntax

```x ^ y
mpower(x,y)
```

Description

Raises the square matrix `x` to the power of `y`. `mpower` additionally requires the exponent `y` to be a natural number.

### ceil¶

Syntax

```ceil(x)
```

Description

Rounds to the nearest integer greater than or equal to `x`. If `x` is an array, it will take the ceiling of each element within `x`. Note that `x` may be symbolic.

### floor¶

Syntax

```floor(x)
```

Description

Rounds to the nearest integer less than or equal to `x`. If `x` is an array, it will take the floor of each element within `x`. Note that `x` may be symbolic.

### round¶

Syntax

```round(x)
```

Description

Rounds to the nearest integer. When two integers are equi-distant from the operand, as the case where `x` contains a fractional part of 0.5, `x` is rounded away from `0`. Note that `x` may be symbolic.

## Complex Numbers¶

### i¶

Syntax

```i
```

Description

`i` is the imaginary unit. It can be used to construct complex numbers.

### imag¶

Syntax

```imag(x)
```

Description

Returns the imaginary part of a complex value. For example, ```imag(a + bi)``` returns `b`.

### real¶

Syntax

```real(x)
```

Description

Returns the real part of a complex number. For example, ```real(a + bi)``` returns `a`.

### abs¶

Syntax

```abs(x)
```

Description

Returns the absolute value of `x`. If `x` is an array, it will evaluate the absolute value of each element. For complex numbers, `x=a+bi`, it returns the complex magnitude, `sqrt(a^2 + b^2)`.

• The result of `abs` operation may be irrational. In those cases, Grackle will switch to floating point precision to represent the result.

## Exponents¶

The operations in this section may generate results that are irrational. In these cases, Grackle will switch to floating point precision to represent the result.

### exp¶

Syntax

```exp(x)
```

Description

Returns the exponential of the operand, `e^x`. If `x` is an array, it will evaluate the exponential of each element in `x`. For complex elements, `x=a+bi` it returns the complex exponential, `(e^a)(cos(b) + i*sin(b))`.

### log¶

Syntax

```log(x)
```

Description

Returns the natural logarithm of a non-zero input, `x`. If `x` is an array, it will evaluate the natural log of each element in `x`. For negative and complex elements, `x=a+bi`, the complex logarithm returns `log(abs(x)) + i*atan2(b,a)`.

logarithm returns `log(abs(x))/log(2) + i*atan2(b,a)/log(2)`.

### log2¶

Syntax

```log2(x)
```

Description

Returns the logarithm base 2 of a non-zero input. The value of `log2(x)` is equivalent to `log(x)/log(2)`.

### log10¶

Syntax

```log10(x)
```

Description

Returns the logarithm base 10 of a non-zero input. The value of `log10(x)` is equivalent to `log(x)/log(10)`.

### sqrt¶

Syntax

```sqrt(x)
```

Description

Returns the principal square root of an input, `x`. If the input is an array, it will evaluate the square root of each element in `x`.

• If the input is symbolic the resulting expression will be non-linear. You will need to configure Grackle to use a solver that supports non-linear equations, see Constraint Solving.

## Trigonometric¶

Operations in this section may generate results that are irrational. In these cases, Grackle will switch to double precision floating point to evaluate the functions and represent the result. Furthermore, symbolic input is permitted, however, very few solvers support them. See Constraint Solving.

### atan2¶

Syntax

```atan2(y,x)
```

Description

Returns the arctangent of `y/x` with a range of `[-pi,pi]`; this corresponds to the angle in radians between the positive x-axis and the line from the origin `(x,y)`. If `x` and `y` are arrays, it will evaluate the inverse tangent for each pair of elements in the arrays. The dimensions of the input arrays must agree.

• The inputs to `atan2` are required to be real.

### cos¶

Syntax

```cos(x)
```

Description

Returns the cosine of the operand in radians. If `x` is an array, it will evaluate the cosine of each of its elements. For complex elements, `x=a+bi` it returns the sine for complex numbers, `cos(a+bi) = cos(a)cosh(b) - i*sin(a)sinh(b)` where `cosh` and `sinh` are the hyperbolic cosine and hyperbolic sine functions respectively.

### hypot¶

Syntax

```hypot(x)
```

Description

Returns the square root of sum of squares, `sqrt(abs(x)^2 + abs(y)^2)`.

If both `x` and `y` are arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before computing the result.

### pi¶

Syntax

```pi
```

Description

Returns the floating point representation of π.

### sin¶

Syntax

```sin(x)
```

Description

Returns the sine of the operand in radians. If `x` is an array, it will evaluate the sine of each of its elements. For complex elements, `x=a+bi` it returns the sine for complex numbers, ```sin(a+bi) = sin(a)cosh(b) + i*cos(a)sinh(b)``` where `cosh` and `sinh` are the hyperbolic cosine and hyperbolic sine functions respectively.

### tan¶

Syntax

```tan(x)
```

Description

Returns the tangent of the operand in radians, where `tan(x)=sin(x)/cos(x)`. If `x` is an array, it will evaluate the tangent of each of its elements.