Question

I know it has to be a stupid error,but I really can't solve a system of this type:

b =

 a2*cos(q1 + q2) + a1*cos(q1)
 a2*sin(q1 + q2) + a1*sin(q1)
                 d1 + d4 + q3

>> solve(b,[q1,q2,q3,q4])
Warning: The solutions are parametrized by the symbols:
z1 = C_

> In solve at 190 

ans = 

    a1: [1x1 sym]
    d1: [1x1 sym]
    d4: [1x1 sym]
    q1: [1x1 sym]
    q2: [1x1 sym]
    q3: [1x1 sym]
    q4: [1x1 sym]

basically I want my program to see a1,d1,d4 as parameters and q1,q2,q3,q4 as variables. that's why I call solve(b,[q1,q2,q3,q4]) in this form,but it tries to solve even in the symbolic values that I haven't put into the vector.

Ty in advice for your help.

Était-ce utile?

La solution

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

Autres conseils

As written, you're currently trying to solve two sets of equations. The first is the three b equations equal to zero. The second is the vector [q1,q2,q3,q4] equal to zero. Because your first equation is not a function of a vector but rather of only the components of this vector, solve sees the second argument as an equation rather than variable to solve for. To solve for the desired variables, simply list them as per the documentation:

s = solve(b,q1,q2,q3,q4)

or

[q1,q2,q3,q4] = solve(b,q1,q2,q3,q4)

Now you will obtain non-zero solutions. However, you'll still get a warning as you obviously have three equations and are trying to solve for four unknowns and there are possibly an infinite number of solutions over the real numbers. In fact q4 isn't used in these equations at all.

The correct syntax is:

 b=[a2*cos(q1 + q2) + a1*cos(q1)==0;
    a2*sin(q1 + q2) + a1*sin(q1)==0;
    d1 + d4 + q3==0]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top