How to multiply a vector by a scalar in Matlab / Octave

To multiply a vector by a scalar number in Matlab / Octave use the multiplication operator *

v*n

The term v is a vector and the term n is a scalar number.

This operation outputs another vector.

$$\vec{v} \cdot n = \begin{pmatrix} a_1 \\ a_2 \\ a_3 \end{pmatrix} \cdot n = \begin{pmatrix} a_1 \cdot n \\ a_2 \cdot n \\ a_3 \cdot n \end{pmatrix}$$

Ogni elemento del vettore v è moltiplicato per il numero scalare n.

Note. The product of a vector by a scalar number satisfies the commutative property. $$\vec{v} \cdot n = n \cdot \vec{v}$$

Examples

Example 1

Define a vector

>> v=[1;2;3]
v =
1
2
3

Multiply the vector by the scalar number n = 2

>> v*2
ans =
2
4
6

The output result is another vector.

Vector elements are multiplied by two.

$$\vec{v} \cdot 2 = \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix} \cdot 2 = \begin{pmatrix} 1 \cdot 2 \\ 2 \cdot 2 \\ 3 \cdot 2 \end{pmatrix} = \begin{pmatrix} 2 \\ 4 \\ 6 \end{pmatrix}$$

Example 2

Multiply the scalar number 2 by the vector v

>> 2*v
ans =
2
4
6

The result is the same because multiplication satisfies the commutative property.

$$2 \cdot \vec{v} = 2 \cdot \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix} = \begin{pmatrix} 2 \cdot 1 \\ 2 \cdot 2 \\ 2 \cdot 3 \end{pmatrix} = \begin{pmatrix} 2 \\ 4 \\ 6 \end{pmatrix}$$

https://how.okpedia.org/en/matlab/how-to-multiply-a-vector-by-a-scalar-in-matlab--octave

Report us an error or send a suggestion to improve this page