title: Unable to solve univariate function using Apache Commons Math library
body: <p>I'm using the <code>Apache Commons Math Library 3.4</code>. I have implemented an univariate function name <code>PFunction</code>. In my Main class, I tried to solve for <code>2 * p * Math.log(p) / (p + 1) -w</code>, where <code>w</code> is <code>-0.5</code>.</p>
  
  <p>However, I get an error of:</p>
  
  <pre><code>org.apache.commons.math3.exception.NoBracketingException: function values at endpoints do not have different signs, endpoints: [1, 1,000], values: [0.5, 14.302]
      at org.apache.commons.math3.analysis.solvers.BrentSolver.doSolve(BrentSolver.java:122)
      at org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.solve(BaseAbstractUnivariateSolver.java:195)
      at org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.solve(BaseAbstractUnivariateSolver.java:200)
      at Main.main(Main.java:43)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
  </code></pre>
  
  <p>I have tried other solvers, e.g. Muller's Method, and they show the same error. Also, I found that a positive value of w, e.g 0.5, do not give me an error. Thanks for your help.</p>
  
  <pre><code>import org.apache.commons.math3.analysis.UnivariateFunction;
  
  public class PFunction implements  UnivariateFunction {
      private double w;
  
      public PFunction(double w) {
          this.w = w;
      }
  
      @Override
      public double value(double p) {
          return 2 * p * Math.log(p) / (p + 1) -w;
      }
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>import org.apache.commons.math3.analysis.UnivariateFunction;
  import org.apache.commons.math3.analysis.solvers.*;
  
  public class Main {
      public static void main(String[] args) {
          double p;
          UnivariateFunction univariateFunction = new PFunction(-0.5);
          BrentSolver brentSolver = new BrentSolver();
  
          try {
              p = brentSolver.solve(1000, univariateFunction, 1, 1000);
              System.out.println("Brent solver, p: " + p);
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>