Magnitude (Python)

From LiteratePrograms
Jump to: navigation, search
Other implementations: Haskell | Python

Magnitude of a vector


|\overrightarrow{u}|
=
|\begin{bmatrix} 
u_1 & u_2 & ... & u_n
\end{bmatrix}|
=
\sqrt{\overrightarrow{u} \cdot \overrightarrow{u}}
=
\sqrt{
v_1 \cdot v_1 + v_2 \cdot v_2 + ... + v_n \cdot v_n
}

<<magnitude_with_dot.py>>=
import math

def magnitude(vector):
    return math.sqrt(dot(vector, vector))
Download code
hijacker
hijacker
hijacker
hijacker