Here you can find the source of square(double[][] m)
public static double[][] square(double[][] m)
//package com.java2s; //License from project: Open Source License public class Main { /**// ww w .jav a2 s. co m * Multiply a square matrix by itself */ public static double[][] square(double[][] m) { assert (m[0].length == m.length); int n = m.length; double[][] res = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { double sum = 0.0; for (int k = 0; k < n; k++) sum += m[i][k] * m[j][k]; res[i][j] = sum; res[j][i] = sum; } } return res; } }