Operations on Vectors in Octave

Description

We can multiply the vector a = [1 2 3 4 5] by a scalar, say 2, by simply entering the command 2*a or a*2.

Sage Cell

Code

a = [1 2 3 4 5]
2*a

Options

Option

We can add and subtract vectors using the operators + and -.

Code

a = [1 2 3 4 5]
b = [-4 2 8 0 7]
a + b

Option

Multiplying one vector by another follows the rules of matrix notation; however, element-by-element multiplication or division is possible using the operators .* and ./.

Code

a = [1 2 3 4 5]
b = [-4 2 8 0 7]
a.*b

Option

It is also possible to take the power of each entry in a vector using the operators ^*.

Code

a = [1 2 3 4 5]
a.^3

Tags

Primary Tags:

Secondary Tags:

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 10 Dec 2018 15:25

Submitted by: Tom Judson

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License