# How to calculate the product of the elements of a vector in Matlab and Octave

Use the prod() function to calculate the product of the elements of a vector in Matlab and Octave

**prod(v)**

The parameter v is the vector.

The prod() function multiplies the values of the vector elements and outputs the product.

## Example

Define a vector

>> v=[1 2 3 4]

v =

1 2 3 4

Calculate the product of the elements of the vector using the **prod(v)** function

>> prod(v)

ans = 24

The product of the elements of the vector is equal to 24

$$ 1 \cdot 2 \cdot 3 \cdot 4 = 24 $$

https://how.okpedia.org/it/matlab/how-to-calculate-the-product-of-the-elements-of-a-vector-in-matlab-and-octave

**Segnala un errore o invia un suggerimento per migliorare la pagina**