Java examples for java.lang:Math Vector
Returns the norm (i.e length) of a given vector
//package com.java2s; public class Main { /** //from w w w. j a v a 2s. co m * Returns the norm (i.e length) of a given vector * @param vector Array containing the set of numbers * @return Double containing the norm of the given vector */ public static <T> Double getNorm(T[] vector) { Double norm = 0.0; for (int i = 0; i < vector.length; i++) { norm = norm + (Double) vector[i]; } norm = Math.sqrt(norm); return norm; } }