Magnitude (Haskell)

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.hs>>=
magnitude :: (Num a) => [a] -> a
magnitude us = sqrt (dot us us)
Download code
hijacker
hijacker
hijacker
hijacker