Here you can find the source of normalize(double[] x)
public static double normalize(double[] x)
//package com.java2s; //License from project: Open Source License public class Main { public static double normalize(double[] x) { double len = 0; for (int i = 0; i < x.length; i++) len += x[i] * x[i];/*from ww w . j a va2s . c om*/ len = Math.sqrt(len); if (len <= 0.0) return 0.0; scale(x, 1.0 / len); return len; } public static void scale(double[] x, double s) { for (int i = 0; i < x.length; i++) x[i] *= s; } public static void scale(double[][] m, double s) { for (int i = 0; i < m.length; i++) scale(m[i], s); } }