code: public static MathModel createPolynom(int degree) {
          if (degree < 0) {
              throw new IllegalArgumentException("Degree must be positive");
          }
          double[] params = new double[degree + 1];
          params[0] = 1;
          StringBuilder format = new StringBuilder();
          for (int i = degree; i >= 0; i--) {
              if (i > 0) {
                  format.append("%f*n");
                  if (i > 1) {
                      format.append('^');
                      format.append(i);
                  }
                  format.append(" + ");
              }
          }
          format.append("%f");
          Function<double[], DoubleUnaryOperator> equation = new Function<double[], DoubleUnaryOperator>() {
              @Override
              public DoubleUnaryOperator apply(double[] doubles) {
                  return x -> {
                      double sum = 0;
                      for (int i = degree; i >= 0; i--) {
                          sum += doubles[degree - i] * Math.pow(x, i);
                      }
                      return sum;
                  };
              }
          };
          String name;
          switch (degree) {
              case 0:
                  name = "O(1)";
                  break;
              case 1:
                  name = "O(n)";
                  break;
              default:
                  name = "O(n^" + degree + ")";
                  break;
          }
          return new MathModel(name, format.toString(), equation, params);
      }
docs: Create an n<sup>th</sup> degree polynomial model.
  
  e.g. <code>createPolynom(4)</code> would create an O(n<sup>4</sup>)
  model.
  
  @param degree
  the polynomial degree
  @return a MathModel representing the specified degree.