multiply Matrix - Android java.lang

Android examples for java.lang:Math Matrix

Description

multiply Matrix

Demo Code


//package com.java2s;

public class Main {
    public static float[][] multiplyMatrix4nF(float[][] m1, float[][] m2) {
        if (m1[0].length != m2.length) {
            return null;
        }//from ww w  .  j a  v  a2  s . co m

        int rows = m1.length;
        int cols = m2[0].length;
        float result[][] = new float[rows][cols];

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                float sum = 0.f;
                for (int k = 0; k < m1[i].length; k++) {
                    sum += m1[i][k] * m2[k][j];
                }
                result[i][j] = sum;
            }
        }

        return result;
    }
}

Related Tutorials