# MATLAB Magnitude of a Vector - MATLAB

## What is MATLAB Magnitude of a Vector?

Magnitude of a vector v with elements v1, v2, v3, …, vn, is given by the equation −

|v| = √(v12+ v22+ v32+ … + vn2)

You need to take the following steps to calculate the magnitude of a vector −

• Take the product of the vector with itself, using array multiplication (.*). This produces a vector sv, whose elements are squares of the elements of vector v.

sv = v.*v;

• Use the sum feature to get the sum of squares of elements of vector v. this is also called the dot product of vector v.

dp= sum(sv);

• Use the sqrt function to get the rectangular root of the sum which is also the magnitude of the vector v.

mag = sqrt(s);

## Example

Create a script record with the subsequent code −

When you run the file, it displays the following result –