public Matrix inverse() {
		if(!isInvertable())
			throw new IllegalArgumentException("Cannot invert matrix");
		
		Matrix inv = new Matrix(numRows, numColumns);
		if(numRows == 1) {
			inv.set(0, 0, 1 / elements[0][0]);
			return inv;
		}
		
		float det = getDeterminant();
		for(int i = 0; i < numRows; i++) {
			for(int j = 0; j < numColumns; j++) {
				float sign = (i + j) % 2 == 0 ? 1 : -1;
				float minor = getExcludedMatrix(i, j).getDeterminant();
				inv.elements[j][i] = sign * minor / det;
			}
		}
		return inv;
	}