operators-arithmetic

Programming

Arithmetic operations. + - * / ^ work on scalars and matrices (matrix multiplication for *). Element-wise operators: .* (element multiply), ./ (element divide), .^ (element power). Use element-wise operators when you want to operate on corresponding elements of arrays.

Syntax

a + b
a - b
a * b
a / b
a ^ b
a .* b
a ./ b
a .^ b

Examples

3 + 4
▶ Run
[1, 2, 3] * 2
▶ Run
[1, 2; 3, 4] * [5; 6]  % matrix multiply
▶ Run
[1, 2, 3] .* [4, 5, 6]  % element-wise: [4, 10, 18]
▶ Run
[1, 2, 3] .^ 2  % element-wise: [1, 4, 9]
▶ Run

See Also

Try SimLab — Free MATLAB® Alternative

466 functions. Runs in your browser. No install.

Open SimLab

Stay Updated

Get notified about new simulations and tools. We send 1-2 emails per month.