Here you can find the source of modifiedGramSchmidt(double[][] s)
public static double[][] modifiedGramSchmidt(double[][] s)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w. ja v a 2 s .c o m * Orthonormalizes a set of vectors. */ public static double[][] modifiedGramSchmidt(double[][] s) { // TODO: use Householder reflections for numerical stability double[][] u = new double[s.length][s[0].length]; // orthogonalize for (int i = 0; i < s.length; i++) { u[i] = s[i]; for (int j = 0; j < i; j++) { u[i] = sumArrays(u[i], scalarProduct(-1, project(u[j], u[i]))); } } // normalize for (int i = 0; i < u.length; i++) { u[i] = normalize(u[i]); } return u; } public static double[] sumArrays(double[] xs1, double[] xs2) { double[] sum = new double[xs1.length]; for (int i = 0; i < xs1.length; i++) { sum[i] = xs1[i] + xs2[i]; } return sum; } public static double[] scalarProduct(double x, double[] xs) { double[] product = new double[xs.length]; for (int i = 0; i < product.length; i++) { product[i] = x * xs[i]; } return product; } /** * Returns the projection of v in the u direction. */ public static double[] project(double[] u, double[] v) { return scalarProduct(dotProduct(u, v) / dotProduct(u, u), u); } public static double[] normalize(double[] xs) { double l2norm = Math.sqrt(dotProduct(xs, xs)); return scalarProduct(1.0 / l2norm, xs); } public static double dotProduct(double[] xs1, double[] xs2) { double product = 0; for (int i = 0; i < xs1.length; i++) { product += xs1[i] * xs2[i]; } return product; } }