2
$\begingroup$

I am trying to solve a system with two transcendental equations and an additional condition and it does not work the way I want it to.

I am using this table with coefficients

coeff = {-9.59079, -7.62064, 0.154122}

and the code for solving the system is

FindRoot[{Cos[x]/x == -coeff[[1]], 
    Cos[y]/y == -coeff[[2]], 
    x == y + coeff[[3]]/R}, 
   {{x, .01}, {y, .01}, {R, .1}}, 
   AccuracyGoal -> Infinity][[1, 2]]

Now you can see that I used AccuracyGoal -> Infinity hoping the error would vanish, but it does not! The error saying:

The line search decreased the step size to within tolerance specified \ by AccuracyGoal and PrecisionGoal but was unable to find a sufficient \ decrease in the merit function. You may need more than \ MachinePrecision digits of working precision to meet these tolerances.

Is still there. I even tried with PrecisionGoal, changing MachinePrecision and nothing works. I am loosing my mind here.

EDIT: In case this is useful information: The initial values I gave 1/100 and 1/10 are simply my guess based on nothing actually.

$\endgroup$
1
  • $\begingroup$ I simplified the example to get rid of bits of code which are ancillary to the actual problem. $\endgroup$ Commented Sep 10, 2015 at 12:42

2 Answers 2

4
$\begingroup$

If you rearrange the problem as follows (using R(x-y) == c instead of x-y == c/R):

FindRoot[{Cos[x]/x == 9.59079, 
  Cos[y]/y == 7.62064, 
  R (x - y) == 0.154122},
{{x, 0.01}, {y, 0.01}, {R, 0.1}},
AccuracyGoal -> Infinity]

Mathematica tells you there is a singular Jacobian at the point given. Essentially, Mathematica finds roots by constructing a suitable hill for which the bottom of the hill corresponds to a root, and then rolling down it. If the hill happens to have a flat bit somewhere, and you specify that you want it to start from the flat bit, then the rolling won't get you anywhere. Mathematica didn't happen to notice that this would happen, in your formulation, so it just spat out that it couldn't find a solution; my slight rearrangement allowed Mathematica to realise the problem and tell me what it was.

If you change y from 0.01 to 0.05, it finds an answer - basically manually changing the starting point to one where the hill is not flat any more. Of course, Mathematica complains that it couldn't meet the accuracy requirements, because you asked it for infinite accuracy. Instead, ask it to find only $MachinePrecision amounts of accuracy (by removing the AccuracyGoal), and it becomes happy with its answer.

If you want more precision from your answers for some reason, you're going to have to increase the precision of your inputs as Nikolay Gromov points out, by using SetPrecision on coeffs and by using exact starting points 1/100, 5/100, 1/10 rather than 0.01, 0.05, 0.1. Once you've done that, you can specify a larger AccuracyGoal.

$\endgroup$
5
  • $\begingroup$ Hi Patrick, I have the same problem again (encountered singular jacobian). Same equation, same problem, only different numerical values. My question is: How did you find out that I have to change y from 0.01 to 0.05? Were you only trying or is there a nice mathematical way to see that? $\endgroup$
    – skrat
    Commented Dec 17, 2015 at 15:03
  • 1
    $\begingroup$ @skrat It was a guess. I'd imagine that most possible choices would work, though: unless your problem is peculiarly horrible, I'd have thought the Jacobian shouldn't be singular in very many places. $\endgroup$ Commented Dec 18, 2015 at 18:03
  • $\begingroup$ Was it also a guess that y was the right parameter to change or did you somehow know that? $\endgroup$
    – skrat
    Commented Dec 18, 2015 at 19:41
  • 1
    $\begingroup$ @skrat Also a guess. $\endgroup$ Commented Dec 18, 2015 at 20:14
  • $\begingroup$ That's bad news for me! :) Thank you for your time! $\endgroup$
    – skrat
    Commented Dec 18, 2015 at 20:19
3
$\begingroup$

There are several things to change. First, having AccuracyGoal bigger than the working precision does not make sense so also change WorkingPrecision -> 100 and also you may need MaxIterations -> 100. Second, your coefficients has a limited precision. You should do

coeff = SetPrecision[coeff,100]

And finally change all approximate numbers 0.01 and 0.1 to exact 1/100 and 1/10. And change the starting point for R {R, -1/10}

Result is:

{Cos[x]/x + coeff[[1, 1]], Cos[y]/y + coeff[[1, 2]], -x + y + coeff[[1, 3]]/R} /. fr
(*{0.*10^-80, 0.*10^-80, 0.*10^-81}*)
$\endgroup$
10
  • $\begingroup$ This is not the answer. Even working with all exact inputs, the problem is that there is a singular Jacobian: FindRoot[{Cos[x]/x == Rationalize[9.59079], Cos[y]/y == Rationalize[7.62064], R (x - y) == Rationalize[0.154122]}, {{x, 1/100}, {y, 1/100}, {R, 1/10}}, WorkingPrecision -> 100] $\endgroup$ Commented Sep 10, 2015 at 12:46
  • $\begingroup$ It is solution, see the output above (one should also change starting points) $\endgroup$ Commented Sep 10, 2015 at 12:50
  • $\begingroup$ "One should also change starting points" - that is the answer. Yes, it makes no sense to have AccuracyGoal bigger than working precision. However, none of the rest of what you've written is necessary. $\endgroup$ Commented Sep 10, 2015 at 12:52
  • $\begingroup$ The question was about getting the result with decent accuracy. Without modifications I listed you will never get more then 15 digits. (Giving me -1 and posting another answer is not nice btw) $\endgroup$ Commented Sep 10, 2015 at 12:56
  • 2
    $\begingroup$ your answer misses the point of the question! The reason the OP's code wasn't converging was because of the initial conditions, and is nothing to do with the precision. If you work entirely with machine precision, setting a different initial condition, and still specify AccuracyGoal -> Infinity, it provides a good answer to machine precision, and complains that it couldn't get enough precision. If you use OP's code, it doesn't provide a good answer at all. OP wanted a way to find an answer, not to improve the precision of a spurious answer. $\endgroup$ Commented Sep 10, 2015 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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