Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Excel's solver, one can define how many iterations are to be done, to one's liking.

I am wondering if this is possible to do with NSolve in Mathematica?


This is what I'm working with:

A = 3580/1000; (*constante*)
B = 736/1000;(*constante*)
R1 = 5/1000;(*0-1.5*)
R2 = 17/1000;(*0-1.5*)

fR1 = ((A + B) (1 - a)^2 (1/15 + P2/21 - (4 P4)/35))/
    (A (1/15 (3 + 4 a + 8 a^2) + 4/21 (3 + a - 4 a^2) P2 + 
      8/35 (1 - a)^2 P4) + B (1 - a)^2 (1/15 + P2/21 - (4 P4)/35));
fR2 = (A (1 - a)^2 (1/15 + P2/21 - (4 P4)/35) + B (1 - a)^2 (1/15 - (2 P2)/21 + P4/35))/
    (A (1/15 (3 + 4 a + 8 a^2) - 2/21 (3 + a - 4 a^2) P2 + 
      3/35 (1 - a)^2 P4) + B (1 - a)^2 (1/15 - (2 P2)/21 + P4/35));
fP4 = -((83 P2)/1000) + (1366 P2^2)/1000 - (1899 P2^3)/1000 + (1616 P2^4)/1000;
fRho = ((A + B) (1 - a)^2)/(A (8 a^2 + 4 a + 3) + B (1 - a)^2);

NSolve[R1 == fR1 && R2 == fR2 && P4 == fP4 && rho == fRho, {P2, P4, a, rho}, Reals];
share|improve this question
up vote 5 down vote accepted

The main algorithm behind NSolve is, I believe, the Jenkins-Traub algorithm, which is indeed iterative in nature. I don't believe that you can specifiy the number of iterates directly, however. Isn't it better to specify the desired precision, though? Mathematica tries to find the solution to a certain precision, and you can specify the precision that you want, as in

eqs = {R1==fR1, R2==fR2, P4==fP4, rho==fRho};
sols= NSolve[eqs, {P2, P4, a, rho}, Reals,
  WorkingPrecision -> 20];

You can always check the quality of the results, as well, using something like so:

(#[[1]] - #[[2]] & /@ eqs) /. sols

This will let you know exactly how close you are on each equation.

share|improve this answer
I'm asking this on behalf of a colleague who's wondering if the algorithm could stop when it finds a local minimum, thus missing the global one. Since we're looking for intersecting points, I can't see how that situation could happen with NSolve, but maybe I'm wrong. Would that be possible? – CHM Apr 18 '12 at 2:56
@CHM I believe that the answer to that question is No. At least the algorithm is designed to be a global solver with a global stopping criterion. Again, even if one is not sure, it's very easy to plug back in to check the quality of the solutions. – Mark McClure Apr 18 '12 at 3:00
Thank you. I had suggested to augment the WorkingPrecision, but the data apparently still didn't meet the expectations. It seems like the model has found its limits! – CHM Apr 18 '12 at 3:05
@CHM Really? I get differences on the order of 10^(-20) or less on each equation. – Mark McClure Apr 18 '12 at 3:07
FindRoot[], however, does take a MaxIterations option... – J. M. Apr 18 '12 at 6:25

From this documentation page,

"For systems of algebraic equations, NSolve computes a numerical Gröbner basis using an efficient monomial ordering, then uses eigensystem methods to extract numerical roots."

When one restricts to work over the reals this is no longer necessarily how it is done. In any case, NSolve is not using iterative methods. (In particular it is not using Jenkins-Traub, because that only applies to univariate polynomials.) Upshot: One cannot limit the iterations. Also I'll confirm that for polynomial systems (or rational functions), NSolve does in fact find all solutions (barring extreme numerical instability).

About the WorkingPrecision option. It does not do much to guarantee the precision of the output. It can be used to force high precision. This can be helpful in cases where the eigensystem extraction is not well behaved, or where high precision is really needed to get small residuals due to instability of the inputs. (How might one know? By checking the results from running NSolve without setting that option, and noticing fairly large residuals.)

share|improve this answer
Sorry for asking here in a comment, but could you by any chance suggest a good introductory learning resource about Gröbner bases? – Szabolcs Apr 18 '12 at 15:57
"Ideals, Varieties, and Algorithms" by Cox, Little, O'Shea (Springer Undergraduate Texts in Mathematics). Also there is "An Introduction to Gröbner Bases" by Adams and Loustaunau (AMS Graduate Studies in Mathematics). – Daniel Lichtblau Apr 18 '12 at 16:02
@Szabolcs: Here is their webpage; if you're going to be solving a lot of multivariate algebraic equations, learning how Gröbner works will be profitable. See also this math.SE question. – J. M. Apr 18 '12 at 16:37
Thanks @J.M.! The book can be downloaded here (if your university is a subscriber). – Szabolcs Apr 18 '12 at 16:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.