Java Matrix Multiply multiplyMatrixes(double[][] m1, double[][] m2)

Here you can find the source of multiplyMatrixes(double[][] m1, double[][] m2)

Description

multiplies matrixes result = m1*m2

License

Open Source License

Parameter

Parameter Description
m1 a matrix (double[3][3])
m2 a matrix (double[3][3])

Return

a matrix (double[3][3])

Declaration

public static double[][] multiplyMatrixes(double[][] m1, double[][] m2) 

Method Source Code

//package com.java2s;
/*//  w ww  .j  a  v  a2s .c  o m
 * Scaffold Hunter
 * Copyright (C) 2006-2008 PG504
 * Copyright (C) 2010-2011 PG552
 * See README.txt in the root directory of the Scaffold Hunter source tree
 * for details.
 *
 * Scaffold Hunter 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.
 *
 * Scaffold Hunter 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 {
    /**
     * multiplies matrixes
     * 
     * result = m1*m2
     * 
     * @param m1
     *  a matrix (double[3][3])
     * @param m2
     *  a matrix (double[3][3])
     * @return
     *  a matrix (double[3][3])
     */
    public static double[][] multiplyMatrixes(double[][] m1, double[][] m2) {
        double[][] result = new double[3][3];
        multiplyMatrixes(m1, m2, result);
        return result;
    }

    /**
     * multiplies matrixes
     * 
     * result = m1*m2
     * 
     * @param m1
     *  a matrix (double[3][3])
     * @param m2
     *  a matrix (double[3][3])
     * @param result
     *  a matrix (double[3][3])
     */
    public static void multiplyMatrixes(double[][] m1, double[][] m2, double[][] result) {
        result[0][0] = m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0] + m1[0][2] * m2[2][0];
        result[0][1] = m1[0][0] * m2[0][1] + m1[0][1] * m2[1][1] + m1[0][2] * m2[2][1];
        result[0][2] = m1[0][0] * m2[0][2] + m1[0][1] * m2[1][2] + m1[0][2] * m2[2][2];

        result[1][0] = m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0] + m1[1][2] * m2[2][0];
        result[1][1] = m1[1][0] * m2[0][1] + m1[1][1] * m2[1][1] + m1[1][2] * m2[2][1];
        result[1][2] = m1[1][0] * m2[0][2] + m1[1][1] * m2[1][2] + m1[1][2] * m2[2][2];

        result[2][0] = m1[2][0] * m2[0][0] + m1[2][1] * m2[1][0] + +m1[2][2] * m2[2][0];
        result[2][1] = m1[2][0] * m2[0][1] + m1[2][1] * m2[1][1] + +m1[2][2] * m2[2][1];
        result[2][2] = m1[2][0] * m2[0][2] + m1[2][1] * m2[1][2] + +m1[2][2] * m2[2][2];
    }
}

Related

  1. multiplyMatrices(double[][] a, double[][] b)
  2. multiplyMatrices(float[][] left, float[][] right)
  3. multiplyMatrices(int[][] mat1, int[][] mat2)
  4. multiplyMatrix(int[][] a, int[] b, int mod)
  5. multiplyMatrixByMatrix(double[][] a, double[][] b)
  6. multiplyQuad(final double[][] A, final double[][] B, final double[][] dest, int n)
  7. multiplyScalars(float[][] x, float[][] y)
  8. multiplyScalars_optimizedByKnowingBothAreRectangle(float[][] x, float[][] y)
  9. multiplySparse2dense(int[][][] as, int A, int[][][] bs, int B, int[][] c)