OKPEDIA MATLAB EN VETTORI

How to divide term by term a vector in Matlab and Octave

To calculate the term-to-term division of two vectors in Matlab / Octave use the operator ./

v./w

The terms v and w are two vectors of the same size.

The result is a vector of the same size where each coefficient is the quotient of the elements of the two vectors that are in the same position.

$$ \frac{ \vec{v} }{ \vec{w} } = \begin{pmatrix} v_1 \\ v_2 \\ v_3 \\ \vdots \\ v_n \end{pmatrix} \ : \ \begin{pmatrix} w_1 \\ w_2 \\ w_3 \\ \vdots \\ w_n \end{pmatrix} = \begin{pmatrix} \frac{ v_1 }{ w_1 } \\ \frac{ v_2 }{ w_2 } \\ \frac{ v_3 }{ w_3 } \\ \vdots \\ \frac{ v_n }{ w_n } \end{pmatrix} $$

Note. This type of division is also known as element-wise division.

Example

Define a vector v with three elements

>> v=[4;9;15]
v =
4
9
15

Define another column vector w with three elements

>>w=[2;3;5]
w =
2
3
5

Calculate the term-to-term division of the two vectors

>> v./w
ans =
2
3
3

The result is a vector in which each element is the quotient of the elements of the two vectors v and w that are in the same position

$$ \frac{ \vec{v} }{ \vec{w} } = \begin{pmatrix} 4 \\ 9 \\ 15 \end{pmatrix} \ : \ \begin{pmatrix} 2 \\ 3 \\ 5 \end{pmatrix} = \begin{pmatrix} \frac{4}{2} \\ \frac{9}{3} \\ \frac{15}{3} \end{pmatrix} = \begin{pmatrix} 2 \\ 3 \\ 3 \end{pmatrix} $$

https://how.okpedia.org/en/matlab/how-to-divide-term-by-term-a-vector-in-matlab-and-octave


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


Arrays and Vectors


FacebookTwitterLinkedinLinkedin