Implement a function to compute the magnitude (also known as the Euclidean norm) of a given vector. The magnitude of a vector is a fundamental concept in linear algebra and vector calculus, as it represents the "length" or "size" of the vector.
The magnitude of a vector v=[v1,v2,...,vn] can be calculated using the formula ∣∣v∣∣=v12+v22+...+vn2. To calculate this, follow these steps:
This technique is widely used in computer vision for image and signal processing.
magnitude([3, 4])
5.0000
Step-by-step calculation using the Euclidean norm formula:
∥v∥=∑i=1nvi2
Square each element:
Sum the squared values: 9+16=25
Take the square root: 25=5
Result: 5.0000
This is the classic 3-4-5 right triangle! The magnitude represents the length of the vector from origin to point (3,4).