We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Matrix multiplication
Page Index Toggle Pages: 1
Matrix multiplication (Read 684 times)
Matrix multiplication
Mar 30th, 2008, 7:45am
 
i need help with simple matrix multiplication code in Processing
am using this code.

int[][] matrixA = {{3,2,-1},{0,4,6}};
int[][] matrixB= {{1,0},{5,3},{6,4}};
int[][] matrixC;


void setup()
{

 
  for(int i=0; i<2; i++){
           for(int j=0; j<2; j++){
               for(int k=0; k<3; k++){
               
               
                 matrixC[i][j]= matrixC[i][j]+ matrixA[i][k] * matrixB[k][j];
             
               }
           }
       }
}

 
it gives me the error

java.lang.NullPointerException at temporary_8356_2317.setup(Temporary_8356_2317.java:32)
at processing.core.PApplet.handleDisplay(PApplet.java:1390)
at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
at processing.core.PApplet.run(PApplet.java:1562)
at java.lang.Thread.run(Unknown Source)
pleas help
Re: Matrix multiplication
Reply #1 - Mar 30th, 2008, 11:43am
 
You need to give MatrixC a size before you can assign values to it.
So chance int[][] matrixC;
to
int[][]matrixC=new int[3][3];
//change 3 3 to the right values, I'm not sure what dimensions a 2x3 * 3x2 gives.
Re: Matrix multiplication
Reply #2 - Mar 31st, 2008, 1:58am
 
thanks...i figured that out after a couple of tries..
but thanks for the answer.
it was really lame of me..
Page Index Toggle Pages: 1