# Reference

Version:

MathScript operators direct the compiler to complete specific tasks.

Operator Name Description Example
= Assign Assigns values to variables. a = 1
: Colon Creates ranges or specifies all values when indexing an array.

a = 1:10

A(:) = 2

; Semicolon Terminates statements or separates rows when defining a matrix. Suppresses the output of a formula in the MathScript Console.

c = 3;cos(c)

b = [1; 2; 3]

sin(0.5);

. Dot Defines the field of a structure. a(1).x = 2

a(1).y = 5

a(1).color = 'green'

, Comma Separates columns or terminates statements.

a = [1, 2]

b = [3, 4],

[ ] Brackets Defines matrices and multiple outputs of a function. a = [1 2 3; 4 5 6]
( ) Parentheses Contains parameters of a function, indexes matrices in expressions, or groups expressions.

a = sin(1)

c = b(2, 3)

~ Not Negates a logical expression.

a = [1, 0]

~(a)

+ Plus Adds. a + b
- Minus Subtracts or negates.

a - b

-a

* Multiplication Multiplies or performs matrix multiplication on matrices. One element must be a scalar. a = 2* b
/ Division Divides or performs matrix division on matrices. The divisor must be a scalar. a / b
.* Elementwise Multiplication Multiplies every element of a matrix with either a scalar or with every element of another matrix.

a = [1 2 3; 4 5 6]

b = [2 3 5; 7 9 1]

a .* b

./ Elementwise Division Divides every element of a matrix with either a scalar or with every element of another matrix. a ./ b
.' Transposition Transposes a matrix.

a = [1; 2; 3]

a .' b

.^ Elementwise Power Performs exponentiation of every element of a matrix with either a scalar or with every element of another matrix. a .^ b
' Conjugate Transposition Transposes the complex conjugate of a matrix and negates the imaginary parts.

a = [-i; 1 + i; 2 - 3i]

a' = [i, 1 - i, 2 + 3i]

^ Power Exponentiates. Both elements must be scalars.

A = 8

B = 3

A ^ B

== Equals Compares equality. a == b
< Less Determines if one element is less than another element. a < b
<= Less or Equal Determines if one element is less than or equal to another element. a <= b
> Greater Determines if one element is greater than another element. a > b
>= Greater or Equal Determines if one element is greater than or equal to another element. a >= b
~= Not Equal Compares inequality. a ~= b
|| Or Performs logical OR (only when both arguments are scalar). The || operator uses short-circuit evaluation, which means that the second part of the expression does not execute because the first part is already True. a || b
&& And Performs logical AND (only when both arguments are scalar). The && operator uses short-circuit evaluation, which means that the second part of the expression does not execute because the first part is already False. a && b
| Elementwise Or Performs elementwise logical OR of every element of a matrix with either a scalar or with every element of another matrix. a | b
& Elementwise And Performs elementwise logical AND of every element of a matrix with either a scalar or with every element of another matrix. a & b