Solving system of three non linear equations??

4 vues (au cours des 30 derniers jours)
Yungjun Kim
Yungjun Kim le 21 Nov 2018
Réponse apportée : Alex Sha le 17 Août 2019
I'm trying to solve forward/direct kinematics of a linear delta manipulator and found three equations (which I think should work). There are three variables, where u is roll, v is pitch, and z is the vertical location of the end plate. The manipulator is unique in that it does not move in x or y and has no rotation in the z or vertical axis.
The equations I found are pretty complex, but I assumed that matlab could easily solve as the system is just three unknowns with three equations despite having little experience with matlab. I've tried using solve(eqns) with IgnoreAnalyticConstraints and Real as true, as well as fsolve(), but both are giving me error saying that the system could not be solved; the solve() gives me (unable to find explicit solutions) and fsolve() gives me either wrong values or says it couldn't solve beause of local singularity.
There are some (more like once or twice) cases though, when I am getting the correct answers with fsolve, but that is when I put the initial values x0 really close to the answer I need, which is not what I need since I am doing this for forward kinematics. I am guessing that there should be some method of doing something with fsolve but I am too bad with Matlab to figure out how..
When I'm using solve(), I always get an error (unable to find explicit solution) when computing all three equations at once, but get a correct answer when I replace the two unknowns into one equation and solve that one, which means that my equations aren't wrong.
In addition, there are some constraints to the solutions that I couldn't put into the functions as I didn't know how. It would be great if you could help me with integrating the constraints into how the solution is computed:
  1. z is always greater than 0
  2. u and v are less than 45 and greater than -45 deg.
  3. z u v are all real.
%system of equation that i used in solve()
%the parameters are l and b and d1d2d3 are inputs
eqn1= z== d1+l*(1-((b-b*((-sqrt(3)*sin(u)*sin(v)/4)+(cos(u)/4)+(3*cos(v)/4))^2)/(l^2)))^(1/2)+b*(1-((-sqrt(3)*sin(u)*sin(v)/4)+(cos(u)/4)+(3*cos(v)/4))^2)^(1/2);
eqn2= z==d2+l*(1-((b-b*cos(u))^2)/(l^2))^(1/2)+b*sin(u);
eqn3= z== d3+l*(1-((b-b*((sqrt(3)*sin(u)*sin(v)/4)+(cos(u)/4)+(3*cos(v)/4))^2)/(l^2)))^(1/2)+b*(1-((sqrt(3)*sin(u)*sin(v)/4)+(cos(u)/4)+(3*cos(v)/4))^2)^(1/2);
%function used for fsolve()
%the values below, 93=d1,d2,d3, should give a result of z or x(1)=200 and u or x(2)=0 and v or x(3)=0, but fsolve cannot solve them
function F= root2d(x)
F(1)= -x(1)+ 93+107*(1-((45-45*(-sqrt(3)*sin(x(2))*sin(x(3))/4+(cos(x(2))/4)+(3*cos(x(3))/4))^2)/(107^2)))^(1/2)+45*(1-(-sqrt(3)*sin(x(2))*sin(x(3))/4+(cos(x(2))/4)+(3*cos(x(3))/4))^2)^(1/2);
F(2)= -x(1)+93+107*(1-((45-45*cos(x(2)))^2)/(107^2))^(1/2)+45*sin(x(2));
F(3)= -x(1)+93+107*(1-((45-45*((sqrt(3)*sin(x(2))*sin(x(3))/4)+(cos(x(2))/4)+(3*cos(x(3))/4))^2)/(107^2)))^(1/2)+45*(1-((sqrt(3)*sin(x(2))*sin(x(3))/4)+(cos(x(2))/4)+(3*cos(x(3))/4))^2)^(1/2);

Réponses (2)

John D'Errico
John D'Errico le 21 Nov 2018
Fsolve is a nonlinear optimization tool. It NEEDS startinng values. Good starting values are often important if your system is nonlinear. Provide crap for starting values, and you should expect to get - CRAP as a result. Sorry, but this is just a basic tenet of nonlinear optimization tools.
Think of any optimizer along the lines of putting a blind man on the face of the earth, and telling him to walk down hill until he cannot go further, with only his cane to guide him. It you dump him in the Himalayas, do you really expect him to be able to find the deep spot in the Marianas trench? (A root finder is little different in this respect from a minimization tool.) I do hope you gave your friend at least a snorkel.
So basically, if you gave decent starting values, then great, you got an answer, and the one you wanted. Why should that be a surprise? This is not an issue of being "too bad with MATLAB", but an issue of not understanding basic optimization.
As far as the use of solve, it is hard to know exactly what you did, because while you do give the equations, you never bothered to tell use the values of those unknown parameters, nor do you explain what you mean by "when I replace the two unknowns into one equation and solve that one". The fact is, it is possible that you may be doing something mathematically invalid. How can we really guess? Did you arbitrarily pick two of the unknowns, substituting values, and then try to solve for the third? That is what it sounds like you did, but it does not actually solve all three equations simultaneously.

Alex Sha
Alex Sha le 17 Août 2019
There are multi-solutions:
No. x1 x2 x3
1 200 -1.99488627715356E-26 7.80083304370558E-9
2 200.000000001348 6.28318530721954 -6.28318530714537
3 200.000000201226 -6.28318530121732 6.28318531234339
4 199.999999960268 18.8495559203615 -6.28318530819842
5 199.999999984405 -18.8495559220008 -37.699111843478
6 199.999999858752 37.6991118388924 -18.8495559251631
7 200.000000004195 -6.2831853070553 -18.8495559214315
8 199.999999993827 43.9822971500742 18.8495559213797
9 199.999999992651 25.1327412285006 -25.132741228907

Catégories

En savoir plus sur Systems of Nonlinear Equations 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!

Translated by