Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solve 3 unknowns from 3 equations.

Subject: Solve 3 unknowns from 3 equations.

From: Peter

Date: 8 Oct, 2010 10:32:06

Message: 1 of 4

Hi everybody.
I have the following equations:

x = -cos(theta_1)*sin(theta_2)*a_3*sin(theta_3)+cos(theta_1)*cos(theta_2)*a_3*cos(theta_3)-cos(theta_1)*a_2*sin(theta_2)+a_1*cos(theta_1);

y = -sin(theta_1)*sin(theta_2)*a_3*sin(theta_3)+sin(theta_1)*cos(theta_2)*a_3*cos(theta_3)-sin(theta_1)*a_2*sin(theta_2)+a_1*sin(theta_1);

z = cos(theta_2)*a_3*sin(theta_3)+sin(theta_2)*a_3*cos(theta_3)+a_2*cos(theta_2)+d_1;

a_1, a_2, a_3 and d_1 are just some known coefficients.

x, y and z are my inputs, e.g. (x = 400, y = 0, z = 700).

Hence, we have 3 equations with 3 unknowns (theta_1, theta_2 and theta_3). How can I make MatLab solve theta_1, theta_2 and theta_3 numerically with x,y,z as my input?

Thank you very much.

Subject: Solve 3 unknowns from 3 equations.

From: Torsten Hennig

Date: 8 Oct, 2010 10:39:14

Message: 2 of 4

> Hi everybody.
> I have the following equations:
>
> x =
> -cos(theta_1)*sin(theta_2)*a_3*sin(theta_3)+cos(theta_
> 1)*cos(theta_2)*a_3*cos(theta_3)-cos(theta_1)*a_2*sin(
> theta_2)+a_1*cos(theta_1);
>
> y =
> -sin(theta_1)*sin(theta_2)*a_3*sin(theta_3)+sin(theta_
> 1)*cos(theta_2)*a_3*cos(theta_3)-sin(theta_1)*a_2*sin(
> theta_2)+a_1*sin(theta_1);
>
> z =
> cos(theta_2)*a_3*sin(theta_3)+sin(theta_2)*a_3*cos(the
> ta_3)+a_2*cos(theta_2)+d_1;
>
> a_1, a_2, a_3 and d_1 are just some known
> coefficients.
>
> x, y and z are my inputs, e.g. (x = 400, y = 0, z =
> 700).
>
> Hence, we have 3 equations with 3 unknowns (theta_1,
> theta_2 and theta_3). How can I make MatLab solve
> theta_1, theta_2 and theta_3 numerically with x,y,z
> as my input?
>
> Thank you very much.

You may try MATLAB's _fsolve_,
but the equations look quite complicated.

Best wishes
Torsten.

Subject: Solve 3 unknowns from 3 equations.

From: Nasser M. Abbasi

Date: 8 Oct, 2010 11:11:55

Message: 3 of 4

On 10/8/2010 3:32 AM, Peter wrote:
> Hi everybody.
> I have the following equations:

> Thank you very much.


Matlab symbolic could not do it

-----------------
EDU>> clear all
EDU>> x = 400; y = 0; z = 700;

syms theta_1 theta_2 theta_3 a_1 a_2 a_3 d_1

eq1=-cos(theta_1)*sin(theta_2)*a_3*sin(theta_3)+cos(theta_1)*cos(theta_2)*a_3*cos(theta_3)-cos(theta_1)*a_2*sin(theta_2)+a_1*cos(theta_1)-x;

eq2=-sin(theta_1)*sin(theta_2)*a_3*sin(theta_3)+sin(theta_1)*cos(theta_2)*a_3*cos(theta_3)-sin(theta_1)*a_2*sin(theta_2)+a_1*sin(theta_1)-y;

eq3=cos(theta_2)*a_3*sin(theta_3)+sin(theta_2)*a_3*cos(theta_3)+a_2*cos(theta_2)+d_1-z;

solve(eq1,eq2,eq3,theta_1,theta_2,theta_3)
Warning: Explicit solution could not be found.
 > In solve at 81

ans =

[ empty sym ]

---------------

Mathematica did it, but the answer it too large to post here.

Then tried some specific values for a_1 a_2 a_3 d_1, still matlab did
not solve it:

----------------------
EDU>> clear all

x = 400; y = 0; z = 700;
a_1=1; a_2=2; a_3=4; d_1=5;

syms theta_1 theta_2 theta_3

eq1=-cos(theta_1)*sin(theta_2)*a_3*sin(theta_3)+cos(theta_1)*cos(theta_2)*a_3*cos(theta_3)-cos(theta_1)*a_2*sin(theta_2)+a_1*cos(theta_1)-x;

eq2=-sin(theta_1)*sin(theta_2)*a_3*sin(theta_3)+sin(theta_1)*cos(theta_2)*a_3*cos(theta_3)-sin(theta_1)*a_2*sin(theta_2)+a_1*sin(theta_1)-y;

eq3=cos(theta_2)*a_3*sin(theta_3)+sin(theta_2)*a_3*cos(theta_3)+a_2*cos(theta_2)+d_1-z;

solve(eq1,eq2,eq3,theta_1,theta_2,theta_3)
Warning: Explicit solution could not be found.
---------------------------

But Mathematica can with the above values (symbolic, not numeric): (6
different solutions)

{{theta3 -> ArcCos[-((5*I*Sqrt[1833055721])/4)], theta2 ->
-ArcCos[(5*(89268719 - 1197*I*Sqrt[1833055721]))/2568904], theta1 -> 0},
etc... 5 more solutions....

---------------------
Try matlab numerical solution?

--Nasser

Subject: Solve 3 unknowns from 3 equations.

From: Roger Stafford

Date: 8 Oct, 2010 19:00:05

Message: 4 of 4

"Peter " <paraplykongen@hotmail.com> wrote in message <i8mrv6$qrq$1@fred.mathworks.com>...
> Hi everybody.
> I have the following equations:
>
> x = -cos(theta_1)*sin(theta_2)*a_3*sin(theta_3)+cos(theta_1)*cos(theta_2)*a_3*cos(theta_3)-cos(theta_1)*a_2*sin(theta_2)+a_1*cos(theta_1);
>
> y = -sin(theta_1)*sin(theta_2)*a_3*sin(theta_3)+sin(theta_1)*cos(theta_2)*a_3*cos(theta_3)-sin(theta_1)*a_2*sin(theta_2)+a_1*sin(theta_1);
>
> z = cos(theta_2)*a_3*sin(theta_3)+sin(theta_2)*a_3*cos(theta_3)+a_2*cos(theta_2)+d_1;
>
> a_1, a_2, a_3 and d_1 are just some known coefficients.
>
> x, y and z are my inputs, e.g. (x = 400, y = 0, z = 700).
>
> Hence, we have 3 equations with 3 unknowns (theta_1, theta_2 and theta_3). How can I make MatLab solve theta_1, theta_2 and theta_3 numerically with x,y,z as my input?
>
> Thank you very much.
- - - - - - - -
  There is an analytic solution to your problem. To shorten the equations, substitute a, b, c, d for a_1, a_2, a_3, and d_1, respectively, and p, q, and r for theta_1, theta_2, and theta_3, respectively. Then your equations can be expressed in equivalent form as:

x = c*cos(p)*cos(q+r)-b*cos(p)*sin(q)+a*cos(p);
y = c*sin(p)*cos(q+r)-b*sin(p)*sin(q)+a*sin(p);
z = c*sin(q+r)+b*cos(q)+d;

or

x = (+c*cos(q+r)-b*sin(q)+a)*cos(p);
y = (+c*cos(q+r)-b*sin(q)+a)*sin(p);
z-d = c*sin(q+r)+b*cos(q);

From this we can obtain

c*cos(q+r)-b*sin(q) = (+or-)sqrt(x^2+y^2)-a
c*sin(q+r)+b*cos(q) = z-d

The quantities on the right side are all known. By an odd coincidence these equations are equivalent to a pair of equations which was solved Sept. 25 by Bruno and myself in the thread:

 http://www.mathworks.com/matlabcentral/newsreader/view_thread/292359

to which I refer you. From the values of q and r solved from this you can then easily obtain p from the x and y equations using the atan2 function.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us