Ejemplo n.º 1
0
/**
 * Calculate the length of a vector.
 *
 * @param
 *        	input
 *        	The matrix to calculate the length of.
 *        	
 * @return Vector length.
 */
function vectorLength(Matrix $input)
{
    if (!$input->isVector()) {
        throw new MatrixError("Can only take the vector length of a vector.");
    }
    $v = $input->toPackedArray();
    $rtn = 0.0;
    foreach ($v as $element) {
        $rtn += pow($element, 2);
    }
    return sqrt($rtn);
}