[ https://issues.apache.org/jira/browse/MATH-631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13080608#comment-13080608 ]
Gilles commented on MATH-631: ----------------------------- > (which is difficult to see as you also change other things in the same commit) Sorry, but I didn't hit the solution right away, i.e. before changing those two additional little things to make the code clearer (for me)... The only actual change is that the {{REGULA_FALSI}} enum was not used (i.e. with the {{switch}} little change, the corresponding {{case}} would have been empty) whereas now it contains the update of x0 to avoid an infinite loop. The other (cosmetic) change was to take these two statements {code} x1 = x; f1 = fx; {code} out of the previous {{if}} and {{else}} blocks, as they were duplicated there (which made me wonder whether it was a bug that they were _not_ different). You say > [...] convergence is guaranteed [...] > [...] it converges very slowly for certain problems, [...] > [...] The limited convergence of the algorithm is a property of the > algorithm, [...] All the above imply that one expects that the algorithm _can_ find the solution. However, in this implementation, it _can't_. Therefore there is a bug, somewhere. I agree that it is a limitation of double precision. But, IMHO, leaving the code as-is is not a good idea because because it leads to the impression that the "Regula Falsi" mathematical algorithm can fail to converge, which is not correct (IIUC). Therefore, we could add a comment stating that the _implementation_ with limited precision can fail to converge but that would be akin to saying to users: "Here is a code, but don't use it." Personally, I would prefer to say: "Because of limited precision, the implementation can fail to converge. In those cases, we slightly modified the original algorithm in order to avoid failure." > "RegulaFalsiSolver" failure > --------------------------- > > Key: MATH-631 > URL: https://issues.apache.org/jira/browse/MATH-631 > Project: Commons Math > Issue Type: Bug > Reporter: Gilles > Fix For: 3.0 > > > The following unit test: > {code} > @Test > public void testBug() { > final UnivariateRealFunction f = new UnivariateRealFunction() { > @Override > public double value(double x) { > return Math.exp(x) - Math.pow(Math.PI, 3.0); > } > }; > UnivariateRealSolver solver = new RegulaFalsiSolver(); > double root = solver.solve(100, f, 1, 10); > } > {code} > fails with > {noformat} > illegal state: maximal count (100) exceeded: evaluations > {noformat} > Using "PegasusSolver", the answer is found after 17 evaluations. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira