According to tips of solve
:
... the call [b,a] = solve(eqns,b,a) assigns the solutions for a assigned to a and the solutions for b assigned to b.
However you probably want to solve, b - [e1 e2 e3]' = 0
for only 3 variables (Let's say q1 q2 q3
), you can't solve it for 4 variables, that would be 3 equations and 4 variables which does't make sense.
Since I think that it is related to some mechanical system you may want to solve for only real values. You can either do this solve (eqn, 'Real', true)
or declare real values: syms a1 a2 ... real
.
However you still wouldn't get a pretty result, unless you use the 'IgnoreAnalyticConstraints'
option in this case:
syms q1 q2 q3 d1 d4 a1 a2 e1 e2 e3 real
b = [...
a2*cos(q1 + q2) + a1*cos(q1)
a2*sin(q1 + q2) + a1*sin(q1)
d1 + d4 + q3];
res = solve(b-[e1 e2 e3]', q1, q2, q3, 'IgnoreAnalyticConstraints', true);
Output: (simplified)
>> simplify(res.q1)
ans =
2*atan((2*a1*e2 + (- a1^4 + 2*a1^2*a2^2 + 2*a1^2*e1^2 + 2*a1^2*e2^2 - a2^4 + 2*a2^2*e1^2 + 2*a2^2*e2^2 - e1^4 - 2*e1^2*e2^2 - e2^4)^(1/2))/(a1^2 + 2*a1*e1 - a2^2 + e1^2 + e2^2))
2*atan((2*a1*e2 - (- a1^4 + 2*a1^2*a2^2 + 2*a1^2*e1^2 + 2*a1^2*e2^2 - a2^4 + 2*a2^2*e1^2 + 2*a2^2*e2^2 - e1^4 - 2*e1^2*e2^2 - e2^4)^(1/2))/(a1^2 + 2*a1*e1 - a2^2 + e1^2 + e2^2))
>> res.q2
ans =
-2*atan(((- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2)*(a1^2 + 2*a1*a2 + a2^2 - e1^2 - e2^2))^(1/2)/(- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2))
2*atan(((- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2)*(a1^2 + 2*a1*a2 + a2^2 - e1^2 - e2^2))^(1/2)/(- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2))
>> res.q3
ans =
e3 - d4 - d1
e3 - d4 - d1