How to get fsolve to find a solution when entering in the solution as a guess?

1 visualizzazione (ultimi 30 giorni)
Hi
I am currently using fsolve to find the angles of 3 inverse kinematics equations. I am having an issue where, even if I put in the 3 angles that are the approximate solution to solve for the position as my initial guess, it cannot solve. Getting the following error:
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the selected value of the function tolerance.
I have reduced TolFun but once it converges to a solution it's still not near the value I would expect. Are there any techniques or suggestions to help get fsolve to converge when you use the (approximate) solution as the initial guess?
Thanks Nick

Risposte (1)

John D'Errico
John D'Errico il 17 Mar 2016
1. Why do you assume that a solution exists? Do you know that it does? Being near an approximate solution does not mean a solution exists near where you started. (In fact, just recently I've seen several cases where this was in fact the answer.)
2. Why do you assume that a solution can be found, GIVEN that starting point? Poor starting values are one of the biggest reason for failure of an optimizer.
3. Why should cranking down on TolFun make it converge better? Converge, dammit! I want you find a solution! I really want a solution! TRY HARDER!!!!! Sorry, but cranking down on TolFun will not help one bit if the optimizer has terminated for the reason given.
4. Are you positive that you have implemented the equations properly? Sorry, but people make mistakes in writing code, and this does happen, a lot.
5. Is your system not amenable to solution by fsolve? For example, discontinuities, non-differentiable objectives, etc., all will cause failure.
  1 Commento
Nick S
Nick S il 18 Mar 2016
Hi John
1. A solution exists. I can solve for it using Excel, or using the Jacobian iteration method (I programmed that previously for this system). Even without a close initial guess the manual Jacobian inverse kinematics finds a solution. I can also use forward kinematics to verify that, with the answers solved from my manual Jacobian iteration, there is a solution with the desired position that matches my desired end position.
2. Well, given a starting point that is the correct answer such that it yields an initial position with less than 0.001 error, I would assume it would find the initial guess as a solution. But it doesn't.
3. I turned down TolFun to see if it would converge anywhere close to my solution. Just did it to see what would happen.
4. Yes, as if I move to a different value fsolve works (and the values were verified by my professor). Other values also work fine and agree with others.
5. It should be differentiable at all points, and has no problem (in general) solving using fsolve.
Also, the reason I am not just using the Jacobian method that I've already programmed is that I'm trying to loop fsolve to find the angles to start at an initial position and end at a final position. Figured it'd be easier to just write a function and use fsolve (which it was, except for this!).
And, just as a point of comparison, the results using my manual inverse kinematics (after only 1 iteration) to hit the point [0.3, 0.4, 0.3] are as follows:
Position with calculated angles =
0.300030018412460
0.399944680508643
0.299987485283343
Angles q1 q2 q3 to achieve position =
0.471631577975886
-0.402758340716481
1.085214604781822
Error in q1 =
1.000613748667704e-04
Error in q2 =
1.382987283926607e-04
Error in q3 =
4.171572218936159e-05
I can use those angles in fsolve and it still finds no solution.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by