Here you can find the source of multiplySquares(float[] mat1, float[] mat2, int sidelength)
Parameter | Description |
---|---|
mat1 | first matrix |
mat2 | second matrix |
sidelength | side lengths of both matrix |
public static float[] multiplySquares(float[] mat1, float[] mat2, int sidelength)
//package com.java2s; public class Main { /**//from w ww. j a v a 2 s . co m * multiplies two square matrices (same width and height) * @param mat1 first matrix * @param mat2 second matrix * @param sidelength side lengths of both matrix * @return resulting matrix of multiplication */ public static float[] multiplySquares(float[] mat1, float[] mat2, int sidelength) { float[] newMat = new float[sidelength * sidelength]; for (int r = 0; r < sidelength * sidelength; r += sidelength) { for (int c = 0; c < sidelength; c++) { float sum = 0; for (int x = 0; x < sidelength; x++) { sum += mat1[r + x] * mat2[c + x * sidelength]; } newMat[r + c] = sum; } } return newMat; } }