code: public double[][] diff_x(double matx[][]) {
          mat3 = new double[width][height];
          double mat1, mat2;
          for (int i = 0; i < width; i++) {
              for (int j = 0; j < height; j++) {
                  if (j == 0) {
                      mat1 = matx[i][j];
                      mat2 = matx[i][j + 1];
                  } else if (j == height - 1) {
                      mat1 = matx[i][j - 1];
                      mat2 = matx[i][j];
                  } else {
                      mat1 = matx[i][j - 1];
                      mat2 = matx[i][j + 1];
                  }
                  mat3[i][j] = (mat2 - mat1) / 2;
              }
          }
          return mat3;
      }
docs: Function : diff_x - To compute differntiation along x axis.