Here you can find the source of normalizeVector(Double[] vector)
Parameter | Description |
---|---|
a | arbitrary vector in \mathbb{R}^n |
public static Double[] normalizeVector(Double[] vector)
//package com.java2s; public class Main { /**/* w ww. j a v a 2s .co m*/ * Takes a vector and returns it normal * * @param a arbitrary vector in \mathbb{R}^n * @return The normal of the given vector */ public static Double[] normalizeVector(Double[] vector) { Double norm = vectorLength(vector); for (int i = 0; i < vector.length; i++) { vector[i] = vector[i] / norm; } return vector; } /** * Computes the 2-Norm of a given vector * * @param vector * @return The 2-Norm of the given vector */ public static Double vectorLength(Double[] vector) { Double sum = 0.0; for (Double d : vector) { sum += Math.pow(d, 2); } sum = Math.sqrt(sum); return sum; } }