-2

can you help and teach me how to make a flowchart from this code ? Thank You

public BigDecimal[][] calcMatrixHessian(BigDecimal[][] polynomialMatrix, int[] classification, double λ) {
  return IntStream.range(0, polynomialMatrix.length)
      .mapToObj(i -> IntStream.range(0, polynomialMatrix[i].length)
          .mapToObj(j -> polynomialMatrix[i][j]
              .multiply(BigDecimal.valueOf(classification[i]*classification[j]))
              .add(BigDecimal.valueOf(Math.pow(λ,2))))
          .toArray(BigDecimal[]::new))
      .toArray(BigDecimal[][]::new);
Alan Dida
  • 3
  • 1

1 Answers1

0

Flowcharts are useful to draw for procedural/imperative paradigms. Java Streams are quite functional and so it is not useful to draw a flowchart of that, because you will just get:

start -> return IntStream.range(0, polynomialMatrix.length)
  .mapToObj(i -> IntStream.range(0, polynomialMatrix[i].length)
      .mapToObj(j -> polynomialMatrix[i][j]
          .multiply(BigDecimal.valueOf(classification[i]*classification[j]))
          .add(BigDecimal.valueOf(Math.pow(λ,2))))
      .toArray(BigDecimal[]::new))
  .toArray(BigDecimal[][]::new); -> end

So we have to convert this to a more procedural algorithm. Here is some pseudocode:

retVal = new BigDecimal[polynomialMatrix[0].length][polynomialMatrix.length]
for i = 0 to polynomialMatrix.length
    for j = 0 to polynomialMatrix[i].length
       retVal[i][j] = polynomialMatrix[i][j] * classification[i]*classification[j]
       retVal[i][j] += Math.pow(λ,2)
return retVal

Now it should be easier to convert this to a flowchart. Try it yourself!

Sweeper
  • 213,210
  • 22
  • 193
  • 313