Java Square square(double[][] m)

Here you can find the source of square(double[][] m)

Description

Multiply a square matrix by itself

License

Open Source License

Declaration

public static double[][] square(double[][] m) 

Method Source Code

//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;
    }
}

Related

  1. square(double a)
  2. square(double[] in, double[] out)
  3. square(final double num)
  4. square(float number, int power)
  5. square(int n)
  6. square(int value)