How can I make the algorithm finish the iterations with the specified tolerance?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all, I am trying to use fsolve for a problem I need to solve.
fsolve usually get very close to the solution but not close enough.
The following message is shown:
"fsolve stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 1000 (the selected value)."
I tried to use much larger number of iteration, but it did not change anything. I am getting a value that is very close to the exact solution, but not close enough.
This is the code of the function:
function [ f_eq ] = system_eq( theta, b )
f_eq = [ (3*cos(theta(1))*(3555*cos(theta(2) + theta(3)) - 3297*sin(theta(2) + theta(3) + theta(4)) + 2500*cos(theta(2))))/50 - b(1);
(3*sin(theta(1))*(3555*cos(theta(2) + theta(3)) - 3297*sin(theta(2) + theta(3) + theta(4)) + 2500*cos(theta(2))))/50 - b(2);
(9891*cos(theta(2) + theta(3) + theta(4)))/50 + (2133*sin(theta(2) + theta(3)))/10 + 150*sin(theta(2)) + 746/25 - b(3);
theta(4) + b(4)];
end
This is how I call the functin:
x0=[0 0 0 0];
b = [150 200 40 0];
tmp = 1.57*(580*580-b(1)*b(1)-b(2)*b(2)-b(3)*b(3)) / (580*580);
b(4) = tmp;
f = @(x0) system_eq(x0, b);
options = optimoptions('fsolve','Display','iter','FunValCheck','on', 'MaxFunEvals',1000, 'TolX', 0.0001);
jointangles = fsolve(f, x0, options)
How can I make the algorithm finish the iterations with the specified tolerance.
Thank you in advance,
Martin
0 commentaires
Réponses (1)
SK
le 30 Sep 2014
Modifié(e) : SK
le 30 Sep 2014
Just as you have added the tag, "iterative solutions oscilate around the exact solution" yourself, this may be what is happening. Did you step through the debugger to check if that is indeed the case?
Having said that, did you notice that if you divide equation (2) by equation (1), you get:
tan( theta(1) ) = b(2)/b(1)
So unless there is a typo in your post, you can already calculate theta(1) manually. In fact after that you could probably solve the equations by hand.
In addition, why bother adding the last equation (eq # 4), when you already know that theta(4) = -b(4) ? You really have two equations in two unknowns that will probably boil down to two algebraic equations in cos(theta(2)) and cos(theta(3)).
0 commentaires
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!