Here you can find the source of multiply(double[][] x, double[][] y)
Parameter | Description |
---|---|
x | a parameter |
y | a parameter |
public static double[][] multiply(double[][] x, double[][] y)
//package com.java2s; /*//from ww w . j av a2s .c om * Copyright (C) 2017 Daniel H. Huson * * (Some files contain contributions from other authors, who are then mentioned separately.) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * matrix multiplication * * @param x * @param y * @return x*y */ public static double[][] multiply(double[][] x, double[][] y) { final int rowsX = x.length; final int colsX = x[0].length; final int rowsY = y.length; final int colsY = y[0].length; if (colsX != rowsY) throw new RuntimeException("multiply(x,y): incompatible dimensions"); final double[][] z = new double[rowsX][colsY]; for (int a = 0; a < rowsX; a++) { for (int b = 0; b < colsY; b++) { double value = 0; for (int c = 0; c < colsX; c++) { value += x[a][c] * y[c][b]; } z[a][b] = value; } } return z; } }