# Help ArrayIndexOutOfBoundsException

#### hijungshin

I am making a set of classes to implement the Gauss-Seidel method to solve the linear equation Ax = b.

The Test.java creates a random matrix A, a random vector b, and uses the GaussSeidel instance to solve for the solution vector x. However, I keep getting an ArrayIndexOutOfBoundsException while creating the random matrix.

Test.java has a main method which includes the line:
VectorMatrix<Double> A = RandomGenerator.randomDiagonalMatrix(10, 256.0);

RandomGenerator.java looks sth like:
public class RandomGenerator {

public static VectorMatrix<Double> randomDiagonalMatrix(int N, double upperbound){
//generates a random, double, N by N diagonal matrix
VectorMatrix<Double> diagMatrix = new VectorMatrix<Double>(N, N);
Random generator = new Random();
for (int i = 0; i < N; i++){
diagMatrix.set(i, i, generator.nextDouble() * upperbound);
}
return diagMatrix;
}
}

and finally the VectorMatrix looks like:

public class VectorMatrix<T> implements Matrix<T> {
int N;
int M;
Vector<T> A;

public VectorMatrix(int N, int M) {
this.N = N;
this.M = M;
A = new Vector<T>(N*M);
}
public void set(int i, int j, T x) {
A.set(i + N*j, x);
}
public int size(){
return N*M;
}

}

I can't find what is the problem. Help!