Represent parameters as other parameters

HI, is there a way in matlab to find t1,t2,d3 represnted by x,y and z
as an example:
3 equations:
1. -cos(t1)*(h2 - d3*cos(t2)) = x
2. h1 + d3*sin(t2) = y
3. sin(t1)*(h2 - d3*cos(t2)) = z
i want to represent t1,t2, and d3 by x,y and z (h1 and h2 are constants)
is there any function that can do that?
Thank You.
by the way the analytic answer is :
t1 = atan2(x/sqrt(x^2+z^2),z/sqrt(x^2+z^2))
t2 = atan((x+h2*sin(t1))/(y-h1))
d3 = (sin(t1)*h2-z)/sin(t2)

2 Comments

syms t1 t2 t3 h1 h2 d3 x y z
e1=-cos(t1)*(h2 - d3*cos(t2)) == x;
e2=h1 + d3*sin(t2) == y;
e3=sin(t1)*(h2 - d3*cos(t2)) == z;
[x,y,z]=solve(e1,e2,e3,x,y,z) %?
Hi ravi, thanks but i think you ment:
syms t1 t2 t3 h1 h2 d3 x y z
e1=-cos(t1)*(h2 - d3*cos(t2)) == x;
e2=h1 + d3*sin(t2) == y;
e3=sin(t1)*(h2 - d3*cos(t2)) == z;
[t1,t2,d3]=solve(e1,e2,e3,t1,t2,d3) %% i change this line
[t1,t2,d3]=solve(e1,e2,e3,t1,t2,d3) because i wanted to find the analytic solution,
but when i input this in matlab it write:
Warning: Unable to find explicit solution. For options, see help.
> In solve (line 317)
do you know how can i fix it?
thank you.

Sign in to comment.

Answers (1)

Stephan
Stephan on 30 Jan 2019
Edited: Stephan on 30 Jan 2019
Hi,
you can use isolate function:
syms t1 t2 d3 h1 h2 x y z
eq1 = -cos(t1)*(h2 - d3*cos(t2)) == x;
eq2 = h1 + d3*sin(t2) == y;
eq3 = sin(t1)*(h2 - d3*cos(t2)) == z;
eq1 = isolate(eq1, t1)
eq2 = isolate(eq2, d3)
eq3 = isolate(eq3, t2)
Best regards
Stephan

4 Comments

That fails of course, since isolate leaves the other variables in there. So the isolate on t1 leaves t2 in the equation.
eq1 = isolate(eq1, t1)
eq1 =
t1 == pi + acos(x/(h2 - d3*cos(t2)))
In the as correct provided solutions of the questioner, it is the same:
"...by the way the analytic answer is :
t1 = atan2(x/sqrt(x^2+z^2),z/sqrt(x^2+z^2))
t2 = atan((x+h2*sin(t1))/(y-h1))
d3 = (sin(t1)*h2-z)/sin(t2)
..."
So this maybe not a problem?
Hi stephan, the problem with your answer is what John said.
Because your using only one equation to solve for t1 when you need e1 and e3 to solve,
the division of e3 by e1 and than taking the inverse of tan t1 is the solution,
this problem is from a test of robotics and im trying to make a matlab function that solvs it,
the hard problem is the multiple solutions and the simplification of the equations, thats why matlab doesn't solve's it, matlab doesn't know it need to do the division and inverse, i still don't know how to solve it. thanks anyway.
yes, that appears to be a little to hard for symbolic calculations in Matlab. Sure you could read in the documentation and try to get what you want by working for hours, but this is not what is expected. Anyway, there is more than solve command. In your case the "more" is not enough...
But if you know a way to tackle the problem, consider:
syms t1 t2 d3 h1 h2 x y z
eq1 = -cos(t1)*(h2 - d3*cos(t2)) == x;
eq2 = h1 + d3*sin(t2) == y;
eq3 = sin(t1)*(h2 - d3*cos(t2)) == z;
eq1 = isolate(eq1, t1);
eq2 = isolate(eq2, d3);
eq3 = isolate(eq3, t1);
eq4 = eq3/eq1
eq4 = subs(eq4,d3,rhs(eq2))
eq4 = isolate(eq4,t2)
which is a solution to t2 that would help more i guess.

Sign in to comment.

Asked:

on 30 Jan 2019

Edited:

on 30 Jan 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!