Anybody good with java programming? I need help with multiplying matrices in java.
i can try to fix your code, im a bit rusty but ill see if the math is right
Ok, thank you for your willingness to help me. Here is my matrix multiplication method.
public class Matrix extends Object { // postcondition: all elements in the return value are in the range of 0...mod-1 public static int[][] mult(int[][] a, int[][] b, int mod) { int ra = a.length; int ca = a[0].length; int rb = b.length; int cb = b[0].length; int[][] mult = new int[ra][cb]; for (int r = 0; r < ra; r++) { for (int c = 0; c < cb; c++) { for (int i = 0; i < ca; i++) { mult[r][c] += a[r][i] * b[i][c]; } } } return mult; } public static void main(String[] args) { int[][] a = {{2, 1, 3}, {6, 5, 9}}, b = {{4, 6, 8}, {7, 1, 3}}; System.out.println("a*b="+java.util.Arrays.deepToString(Matrix.mult(a, b, 11))); //System.out.println("det(a)="+Matrix.det(a, 11)); } }
Copy paste this code to compilejava.net
hi im here
okay so lets do this
I need to know why I'm getting an index out of bounds error.
you mixing up col and rows
What? How?
okay so A.length ==?
hmm it looks right
try changing it to ra-1 see if it fixes it
oh wait it say index out of range for mult
you can try making sure the size of mult exists already
define mult to be a zero matrix with col of A and rows of B
its rows are Col of A and its col are rows of B
Join our real-time social learning platform and learn together with your friends!