## Hi, I want to solve 12 equation in 12 unknown but is nonlinear equation for robotic arm ((??? Error using ==> solve>getEqns at 173 ))

Asked by Ahmed El Hussieny

### Ahmed El Hussieny (view profile)

on 29 Apr 2016
Latest activity Commented on by Manuel Fuelling

### Manuel Fuelling (view profile)

on 26 Mar 2018
??? Error using ==> solve>getEqns at 173
' s6*(c4*(s2*c1*s3 –c2*c1*c3) + s4*(s2*c1*c3 +c2*c1*s3)) + c6*(s5*(c4*(s2*c1*c3
+c2*c1*s3) - s4*(s2*c1*s3 c2*c1*c3)) -c5*s1)=1 ' is not a valid expression or equation.
Error in ==> solve at 84
[eqns,vars] = getEqns(varargin{:});
Any help you all can provide would be appreciated! Thanks!

Manuel Fuelling

### Manuel Fuelling (view profile)

on 26 Mar 2018
I have a similiar system of equations. Now with 12 unknown and 12 equations. I applied same as Ahmed El Hussieny. Still vpasolve doesnt calculate correctly. Is vpasolve the correct one to use?
syms x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12
F(1) = x1-x3 == 0;
F(2) = -x5+x6 == 0;
F(3) = x7+x9-4 == 0;
F(4) = x11+x12-4 == 0;
F(5) = sqrt((x1-x4)^2+(x2-x5)^2+(x3-x6)^2)-2 == 0;
F(6) = sqrt((x4-x7)^2+(x5-x8)^2+(x5-x9)^2)-2 == 0;
F(7) = sqrt((x7-x10)^2+(x8-x11)^2+(x9-x12)^2)-2 ==
F(8) = sqrt((x10-x1)^2+(x11-x2)^2+(x12-x3)^2)-2 == 0;
F(9)= ( (x4-x1)*(x10-x1)+(x5-x2)*(x11-x2)+(x6-x3)*(x12-x3) ) / ((sqrt((x4)-x1)^2+(x5-x2)^2+(x6-x3)^2)*sqrt((x10-x1)^2+(x10-x2)^2+(x12-x3)^2)) -cosd(90) == 0;
F(10)= ( (x1-x4)*(x7-x4)+(x2-x5)*(x8-x5)+(x3-x6)*(x9-x6) ) / ((sqrt((x1)-x4)^2+(x2-x5)^2+(x3-x6)^2)*sqrt((x7-x4)^2+(x8-x5)^2+(x9-x6)^2)) -cosd(90) == 0;
F(11)= ( (x4-x7)*(x12-x7)+(x5-x8)*(x11-x8)+(x6-x9)*(x12-x9) ) / ((sqrt((x4)-x7)^2+(x5-x8)^2+(x6-x9)^2)*sqrt((x10-x7)^2+(x11-x8)^2+(x12-x9)^2)) -cosd(90) == 0;
F(12)= ( (x7-x10)*(x1-x10)+(x8-x11)*(x2-x11)+(x9-x12)*(x3-x12) ) / ((sqrt((x7-x10)^2+(x8-x11)^2+(x9-x12)^2))*sqrt((x1-x10)^2+(x2-x11)^2+(x3-x12)^2)) -cosd(90) == 0;
[sol_x1,sol_x2,sol_x3,sol_x4,sol_x5,sol_x6,sol_x7,sol_x8,sol_x9,sol_x10,sol_x11,sol_x12]=vpasolve([F(1),F(2),F(3),F(4),F(5),F(6),F(7),F(8),F(9),F(10),F(11),F(12)],[x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12])

### Tags ### John D'Errico (view profile)

Answer by John D'Errico

### John D'Errico (view profile)

on 29 Apr 2016
Edited by John D'Errico

### John D'Errico (view profile)

on 29 Apr 2016

That it is nonlinear is not pertinent. Although solve will surely fail to produce a result. Try vpasolve.
The reason for your error is that you need to learn to use tools like solve and vpasolve. Instead of = in those expressions at the ends, you need to use the == operator, like this:
-c5*s1)=1
use
-c5*s1)==1
There is a difference.
Again though, even once you fix the above errors, solve will still surely fail to return any result. In fact, it will probably run forever. Then you will ask another question about why solve does not work here. So use vpasolve, to at least have a chance.

Ahmed El Hussieny

### Ahmed El Hussieny (view profile)

on 1 May 2016
Mr. Walter if you want to determine the actual angle you must know the sin , cos for this angle, after that, calculate inverse tan to know this angle in any quarter.
Ok, anyway i can describe sin(q1) by symbol s1 and cos(q1) by symbol c1, then for each angle we have 2 unknowns (( c1,s1,c2,s2,c4,s4.....etc)). In the primary equation i have 5 angels and one displacement i can extend 5 angles by the last method to 10 unknowns then total unknowns in 12 equations are 11 in number. Can Matlab solve 12 eq. in 11 unknowns ?!!!!!!
Thank you for caring
John D'Errico

### John D'Errico (view profile)

on 1 May 2016
In general, unless some of the equations are redundant, then no, you cannot solve 12 equations in 11 unknowns to find a unique solution. This is not a MATLAB issue, but just a fact of mathematics.
Walter Roberson

### Walter Roberson (view profile)

on 1 May 2016
sin(q1) and cos(q1) are not independent: they are related by the sum of their squares being 1, so knowing sin(q1) tells you +/- cos(q1). You need to add these 5 more constraint equations, which gets you to 17 equations in 11 unknowns, which is something you are not going to solve unless some of the equations are redundant. ### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 29 Apr 2016

In your code, remove all the quotes that make the equations strings, and change the "=" to "==". For example,
f0 = s6*(c4*(s2*c1*s3 c2*c1*c3) + s4*(s2*c1*c3 +c2*c1*s3)) + c6*(s5*(c4*(s2*c1*c3 +c2*c1*s3) - s4*(s2*c1*s3 c2*c1*c3)) -c5*s1) == 1;

Ahmed El Hussieny

### Ahmed El Hussieny (view profile)

on 30 Apr 2016
Thank you Mr. Walter for replying
l already change my code as you say
syms q1 q2 d3 q4 q5 q6
f(1)= cos(q1)*(cos(q2)*(cos(q4)*cos(q5)* cos(q6)- sin(q4)*sin(q6))- sin(q2)*sin(q5)*cos(q6))-sin(q1)*(sin(q4)*cos(q5)*cos(q6)+ cos(q4)*sin(q6))==0 ;
f(2)= sin(q1)*(cos(q2)*(cos(q4)*cos(q5)* cos(q6)- sin(q4)*sin(q6))+ cos(q2)*sin(q5)*cos(q6))-sin(q1)*(sin(q4)*cos(q5)*cos(q6)+ cos(q4)*sin(q6))==0 ;
f(3)= - sin(q2)*(cos(q4)*cos(q5)*cos(q6)- sin(q4) * sin(q6))- cos(q2)*sin(q5)*cos(q6)-1==0 ;
f(4)= cos(q1)*(-cos(q2)*(cos(q4)*cos(q5)* cos(q6)+ sin(q4)*sin(q6))+ sin(q2)*sin(q5)*cos(q6))-sin(q1)*(-sin(q4)*cos(q5)*sin(q6)+ cos(q4)*cos(q6))==0 ;
f(5)= sin(q1)*(-cos(q2)*(cos(q4)*cos(q5)* cos(q6)+ sin(q4)*sin(q6))+ sin(q2)*sin(q5)*cos(q6))+ cos(q1)*(-sin(q4)*cos(q5)*sin(q6)+ cos(q4)*cos(q6))==0 ;
f(6)= sin(q2)*(cos(q4)*cos(q5)*sin(q6) + sin(q4)*cos(q6))+cos(q2)*sin(q5)*sin(q6) == 0 ;
f(7)= cos(q1)*(cos(q2)*cos(q4)*sin(q5) + sin(q2)*cos(q5))- sin(q1)*sin(q4)*sin(q5) == 0 ;
f(8)= sin(q1)*(cos(q2)*cos(q4)*sin(q5) + sin(q2)*cos(q5))+ cos(q1)*sin(q4)*sin(q5) - 1==0 ;
f(9)= - sin(q2)*cos(q4)*sin(q5)+cos(q2)*cos(q5)==0;
f(10)= cos(q1)*sin(q2)*d3- sin(q1)*0.154 + 0.263*(cos(q1)*cos(q2)*cos(q4)*sin(q5)+ cos(q1)*cos(q5)*sin(q2)- sin(q1)*sin(q4)*sin(q5))+0.154==0;
f(11)= sin(q1)*sin(q2)*d3+ cos(q1)*0.154 + 0.263*(cos(q1)*sin(q4)*sin(q5)+ cos(q2)*cos(q4)*sin(q1)*sin(q5)+ cos(q5)* sin(q1)*sin(q2))-0.753==0 ;
f(12)= cos(q2)*d3 + 0.263*(cos(q2)*cos(q5)- cos(q4)*sin(q2)*sin(q5)) == 0 ;
[sol_q1,sol_q2,sol_d3,sol_q4,sol_q5,sol_q6]= vpasolve([f(1),f(2),f(3),f(4),f(5),f(6),f(7),f(8),f(9),f(10),f(11),f(12)],[q1, q2, d3, q4, q5, q6])
I tray to solve equation by vpasolve but is give me error , please check in code
thank you very much
Walter Roberson

### Walter Roberson (view profile)

on 30 Apr 2016
As I indicated above, you are trying to solve 12 equations in 6 unknowns. That isn't going to work unless you do not need all 12 equations.