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:
3 equation of cosine law

Subject: 3 equation of cosine law

From: DHAAH JOHARI

Date: 22 Mar, 2013 11:37:06

Message: 1 of 12

please help me..
anyone know how to solve this problem..
I have 3 simultaneous equation based on the cosine law..

x^2=y^2+233600-966.64*y*cos(z-65.56);
x^2=y^2+155600-788.92*y*cos(z-59.53);
x^2=y^2+97600-624.82*y*cos(z-50.19);

i know the answer for x=444.46, y=149.25
but when i do the the coding like this below, i didn't get the same answer..i got
 x=-449.15, y=-295.21 and z=61.28
 
syms xyz
solutions = solve('x^2 = y^2+233600-966.64*y*cos(z-65.56) ',' x^2 = y^2+155600-788.92*y*cos(z-59.53)','x^2 = y^2+97600-624.82*y*cos(z-50.19)')
[solutions.x solutions.y solutions.z]

Subject: 3 equation of cosine law

From: Torsten

Date: 22 Mar, 2013 11:59:07

Message: 2 of 12

"DHAAH JOHARI" wrote in message <kihfp2$dmt$1@newscl01ah.mathworks.com>...
> please help me..
> anyone know how to solve this problem..
> I have 3 simultaneous equation based on the cosine law..
>
> x^2=y^2+233600-966.64*y*cos(z-65.56);
> x^2=y^2+155600-788.92*y*cos(z-59.53);
> x^2=y^2+97600-624.82*y*cos(z-50.19);
>
> i know the answer for x=444.46, y=149.25
> but when i do the the coding like this below, i didn't get the same answer..i got
> x=-449.15, y=-295.21 and z=61.28
>
> syms xyz
> solutions = solve('x^2 = y^2+233600-966.64*y*cos(z-65.56) ',' x^2 = y^2+155600-788.92*y*cos(z-59.53)','x^2 = y^2+97600-624.82*y*cos(z-50.19)')
> [solutions.x solutions.y solutions.z]

I think you want to use "cosd" instead of "cos" in your equations.

Best wishes
Torsten.

Subject: 3 equation of cosine law

From: DHAAH JOHARI

Date: 23 Mar, 2013 11:39:07

Message: 3 of 12

> I think you want to use "cosd" instead of "cos" in your equations.
>
> Best wishes
> Torsten.

Thanks Torsten..thank you very much!
but I still didn't get the answers,..
It said error..i don't know how to fix it

syms xyz
solutions = solve('x^2 = y^2+233600-966.64*y*cosd(z-65.56) ',' x^2 = y^2+155600-788.92*y*cosd(z-59.53)','x^2 = y^2+97600-624.82*y*cosd(z-50.19)')
[solutions.x solutions.y solutions.z]

Subject: 3 equation of cosine law

From: Torsten

Date: 25 Mar, 2013 08:30:07

Message: 4 of 12

"DHAAH JOHARI" wrote in message <kik48r$k5a$1@newscl01ah.mathworks.com>...
> > I think you want to use "cosd" instead of "cos" in your equations.
> >
> > Best wishes
> > Torsten.
>
> Thanks Torsten..thank you very much!
> but I still didn't get the answers,..
> It said error..i don't know how to fix it
>
> syms xyz
> solutions = solve('x^2 = y^2+233600-966.64*y*cosd(z-65.56) ',' x^2 = y^2+155600-788.92*y*cosd(z-59.53)','x^2 = y^2+97600-624.82*y*cosd(z-50.19)')
> [solutions.x solutions.y solutions.z]

I think cosd does not accept symbolic arguments.
Convert 65.56°, 59.53° and 50.19° to radians and try again.
And define
syms x y z
instead of
syms xyz

Best wishes
Torsten.

Subject: 3 equation of cosine law

From: DHAAH JOHARI

Date: 27 Mar, 2013 18:45:06

Message: 5 of 12

"Torsten" wrote in message <kip1uf$5ot$1@newscl01ah.mathworks.com>...
> "DHAAH JOHARI" wrote in message <kik48r$k5a$1@newscl01ah.mathworks.com>...
> > > I think you want to use "cosd" instead of "cos" in your equations.
> > >
> > > Best wishes
> > > Torsten.
> >
> > Thanks Torsten..thank you very much!
> > but I still didn't get the answers,..
> > It said error..i don't know how to fix it
> >
> > syms xyz
> > solutions = solve('x^2 = y^2+233600-966.64*y*cosd(z-65.56) ',' x^2 = y^2+155600-788.92*y*cosd(z-59.53)','x^2 = y^2+97600-624.82*y*cosd(z-50.19)')
> > [solutions.x solutions.y solutions.z]
>
> I think cosd does not accept symbolic arguments.
> Convert 65.56°, 59.53° and 50.19° to radians and try again.
> And define
> syms x y z
> instead of
> syms xyz
>
> Best wishes
> Torsten.

Thanks again Torsten..
i have converting the 65.56°, 59.53° and 50.19° to radians and define syms x y z..but i still didn't get the answers..
is it right if i wrote like this..so sorry to have bothered you

syms x y z
solutions = solve('x^2 = y^2+233600-966.64*y*cos(z-1.14) ',' x^2 = y^2+155600-788.92*y*cos(z-1.04)','x^2 = y^2+97600-624.82*y*cos(z-0.88)')
[solutions.x solutions.y solutions.z]

Subject: 3 equation of cosine law

From: Roger Stafford

Date: 28 Mar, 2013 07:32:16

Message: 6 of 12

"DHAAH JOHARI" wrote in message <kihfp2$dmt$1@newscl01ah.mathworks.com>...
> I have 3 simultaneous equation based on the cosine law..
> x^2=y^2+233600-966.64*y*cos(z-65.56);
> x^2=y^2+155600-788.92*y*cos(z-59.53);
> x^2=y^2+97600-624.82*y*cos(z-50.19);
>
> i know the answer for x=444.46, y=149.25
> .........
- - - - - - - - -
  Assuming the three angles 65.56, 59.53, and 50.19 are measured in degrees, this problem can be solved for x, y, and z without using the 'solve' function.

  Your equations are of the form

 x^2 = y^2 + a^2 - 2*a*y*cos(z-d)
 x^2 = y^2 + b^2 - 2*b*y*cos(z-e)
 x^2 = y^2 + c^2 - 2*c*y*cos(z-f)

where a^2 = 233600, b^2 = 155600, c^2 = 97600, d = 65.56*pi/180, e = 59.53*pi/180, and f = 50.19*pi/180 with the latter three angles measured in radians. This can be expressed as

 x^2-y^2 = a^2-2*a*y*cos(z-d) = b^2-2*b*y*cos(z-e) = c^2-2*c*y*cos(z-f)

 2*y*(a*cos(z-d)-b*cos(z-e)) = a^2-b^2
 2*y*(b*cos(z-e)-c*cos(z-f)) = b^2-c^2

 2*y = (a^2-b^2)/(a*cos(z-d)-b*cos(z-e)) = (b^2-c^2)/(b*cos(z-e)-c*cos(z-f))

 (a^2-b^2)*(b*cos(z-e)-c*cos(z-f))-(b^2-c^2)*(a*cos(z-d)-b*cos(z-e)) = 0

 a*(b^2-c^2)*cos(z-d)+b*(c^2-a^2)*cos(z-e)+c*(a^2-b^2)*cos(z-f) = 0

 a*(b^2-c^2)*(cos(z)*cos(d)+sin(z)*sin(d)) +
 b*(c^2-a^2)*(cos(z)*cos(e)+sin(z)*sin(e)) +
 c*(a^2-b^2)*(cos(z)*cos(f)+sin(z)*sin(f)) = 0

Letting

 A = a*(b^2-c^2)*cos(d)+b*(c^2-a^2)*cos(e)+c*(a^2-b^2)*cos(f)
 B = a*(b^2-c^2)*sin(d)+b*(c^2-a^2)*sin(e)+c*(a^2-b^2)*sin(f)

the equation becomes

 A*cos(z)+B*sin(z) = 0

  This last equation can be solved using 'atan2' and the full matlab code would then be:

 a = sqrt(233600);
 b = sqrt(155600);
 c = sqrt(97600);
 d = 65.56*pi/180;
 e = 59.53*pi/180;
 f = 50.19*pi/180;
 A = a*(b^2-c^2)*cos(d)+b*(c^2-a^2)*cos(e)+c*(a^2-b^2)*cos(f);
 B = a*(b^2-c^2)*sin(d)+b*(c^2-a^2)*sin(e)+c*(a^2-b^2)*sin(f);
 z = atan2(-A,B);
 y = 1/2*(a^2-b^2)/(a*cos(z-d)-b*cos(z-e));
 x = sqrt(y^2+a^2-2*a*y*cos(z-d));

  This solution turns out to be very, very different from the one you quoted in your post with z being very near pi radians (almost 180 degrees.) Are you sure of the values you have given here?

Roger Stafford

Subject: 3 equation of cosine law

From: Torsten

Date: 28 Mar, 2013 07:44:14

Message: 7 of 12

"DHAAH JOHARI" wrote in message <kiveni$nan$1@newscl01ah.mathworks.com>...
> "Torsten" wrote in message <kip1uf$5ot$1@newscl01ah.mathworks.com>...
> > "DHAAH JOHARI" wrote in message <kik48r$k5a$1@newscl01ah.mathworks.com>...
> > > > I think you want to use "cosd" instead of "cos" in your equations.
> > > >
> > > > Best wishes
> > > > Torsten.
> > >
> > > Thanks Torsten..thank you very much!
> > > but I still didn't get the answers,..
> > > It said error..i don't know how to fix it
> > >
> > > syms xyz
> > > solutions = solve('x^2 = y^2+233600-966.64*y*cosd(z-65.56) ',' x^2 = y^2+155600-788.92*y*cosd(z-59.53)','x^2 = y^2+97600-624.82*y*cosd(z-50.19)')
> > > [solutions.x solutions.y solutions.z]
> >
> > I think cosd does not accept symbolic arguments.
> > Convert 65.56°, 59.53° and 50.19° to radians and try again.
> > And define
> > syms x y z
> > instead of
> > syms xyz
> >
> > Best wishes
> > Torsten.
>
> Thanks again Torsten..
> i have converting the 65.56°, 59.53° and 50.19° to radians and define syms x y z..but i still didn't get the answers..
> is it right if i wrote like this..so sorry to have bothered you
>
> syms x y z
> solutions = solve('x^2 = y^2+233600-966.64*y*cos(z-1.14) ',' x^2 = y^2+155600-788.92*y*cos(z-1.04)','x^2 = y^2+97600-624.82*y*cos(z-0.88)')
> [solutions.x solutions.y solutions.z]

What do you get if you execute
syms x y z
solutions = solve(x^2 == y^2+233600-966.64*y*cos(z-1.14), x^2 == y^2+155600-788.92*y*cos(z-1.04), x^2 == y^2+97600-624.82*y*cos(z-0.88))
[solutions.x solutions.y solutions.z]
and why is this solution not the solution you expect ?

If I insert
x=444.46, y=149.25
into the equation and solve each equation seperately for z, I _don't_ get the same z-values (for the first equation, I get z=2.29, for the second 2.78 and for the third z=3.44)
So I don't understand why you think that
 x=444.46, y=149.25
is a solution.

Best wishes
Torsten.

Subject: 3 equations of cosine law

From: DHAAH JOHARI

Date: 29 Mar, 2013 10:17:12

Message: 8 of 12

Thank you so much Roger Stafford & Torsten..
I'm very thankful to both of you..
Actually the values (x=444.46, y=149.25) are given by my supervisor..and i don't know this values are right or wrong as the answers for the simultaneous equations..
Thanks again;)

Subject: 3 equations of cosine law

From: Steven_Lord

Date: 29 Mar, 2013 13:53:36

Message: 9 of 12



"DHAAH JOHARI" <dhaah186@yahoo.com> wrote in message
news:kj3pn8$3n2$1@newscl01ah.mathworks.com...
> Thank you so much Roger Stafford & Torsten..
> I'm very thankful to both of you..
> Actually the values (x=444.46, y=149.25) are given by my supervisor..and i
> don't know this values are right or wrong as the answers for the
> simultaneous equations..

There's an easy way to find out: do those values satisfy the equations? If
they don't, then one of the following is true:

1) The equations are incorrect.
2) The answers are incorrect.
3) Both the equations and the answers are incorrect.

Then it's up to you and your supervisor to figure out which of those three
possibilities is correct.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: 3 equations of cosine law

From: DHAAH JOHARI

Date: 29 Mar, 2013 17:41:05

Message: 10 of 12

 > There's an easy way to find out: do those values satisfy the equations? If
> they don't, then one of the following is true:
>
> 1) The equations are incorrect.
> 2) The answers are incorrect.
> 3) Both the equations and the answers are incorrect.
>
> Then it's up to you and your supervisor to figure out which of those three
> possibilities is correct.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Thank you Mr Steve Lord..;)

Subject: 3 equation of cosine law

From: DHAAH JOHARI

Date: 2 Apr, 2013 18:10:06

Message: 11 of 12

My equations are incorrect, need to add 30 and 90 degrees for equations 2 and 3.but, the answers are still the same as x=444.46, y=149.25.

 x^2=y^2+233600-966.64*y*cos(z-65.56) ...........................(1)
 x^2=y^2+155600-788.92*y*cos((z+30)-59.53) ............................(2)
 x^2=y^2+97600-624.82*y*cos((z+90)-50.19) ..............................(3)
or
x^2 = y^2+233600-966.64*y*cos(z-1.1442);
x^2 = y^2+155600-788.92*y*cos((z+0.5236)-1.039);
x^2 = y^2+97600-624.82*y*cos((z+1.5708)-0.876);

When i use the same step as previously, i got the answers are almost close (x=-454.1389 y=-142.0924 z=62.0516) , but have negative sign..is it can be acceptable?
 
step 1:
syms x y z
solutions = solve('x^2 = y^2+233600-966.64*y*cos(z-1.144) ',' x^2 = y^2+155600-788.92*y*cos((z+0.5236)-1.039)','x^2 = y^2+97600-624.82*y*cos((z+1.57)-0.876)')
[solutions.x solutions.y solutions.z]
double(ans)

x=-454.1389 y=-142.0924 z=62.0516

step2 from Mr Stafford..
i like this calculations. and the answers are also close. but am i correct trying to fix just as below..

x^2 = y^2 + a^2 - 2*a*y*cos(z-d)
 x^2 = y^2 + b^2 - 2*b*y*cos((z+30)-e)
 x^2 = y^2 + c^2 - 2*c*y*cos((z+90)-f)

where a^2 = 233600, b^2 = 155600, c^2 = 97600, d = 65.56*pi/180, e = 59.53*pi/180, and f = 50.19*pi/180

 x^2-y^2 = a^2-2*a*y*cos(z-d) = b^2-2*b*y*cos((z+30)-e) = c^2-2*c*y*cos((z+90)-f)

 2*y*(a*cos(z-d)-b*cos(z-e)) = a^2-b^2
 2*y*(b*cos((z+30)-e)-c*cos((z+90)-f)) = b^2-c^2

 2*y = (a^2-b^2)/(a*cos(z-d)-b*cos((z+30)-e)) = (b^2-c^2)/(b*cos((z+30)-e)-c*cos((z+90)-f)

 (a^2-b^2)*(b*cos((z+30)-e)-c*cos((z+90)-f))-(b^2-c^2)*(a*cos(z-d)-b*cos((z+30)-e)) = 0

 a*(b^2-c^2)*cos(z-d)+b*(c^2-a^2)*cos((z+30)-e)+c*(a^2-b^2)*cos((z+90)-f) = 0

 a*(b^2-c^2)*(cos(z)*cos(d)+sin(z)*sin(d)) +
 b*(c^2-a^2)*(cos(z+30)*cos(e)+sin(z+30)*sin(e)) +
 c*(a^2-b^2)*(cos(z+90)*cos(f)+sin(z+90)*sin(f)) = 0

 A = a*(b^2-c^2)*cos(d)+b*(c^2-a^2)*cos(e)+c*(a^2-b^2)*cos(f)
 B = a*(b^2-c^2)*sin(d)+b*(c^2-a^2)*sin(e)+c*(a^2-b^2)*sin(f)

the last equations become:

A*cos(z)+B*sin(z) = 0 -------------------(1)
Acos(z+30)+Bsin(z+30)=0 ------------------(2)
Acos(z+90)+Bsin(z+90)=0 ------------------(3)

 a = sqrt(233600);
 b = sqrt(155600);
 c = sqrt(97600);
 d = 65.56*pi/180;
 e = 59.53*pi/180;
 f = 50.19*pi/180;
 A = a*(b^2-c^2)*cos(d)+b*(c^2-a^2)*cos(e)+c*(a^2-b^2)*cos(f);
 B = a*(b^2-c^2)*sin(d)+b*(c^2-a^2)*sin(e)+c*(a^2-b^2)*sin(f);
 z = atan2(-A,B);
 y = 1/2*(a^2-b^2)/(a*cos(z-d)-b*cos((z+0.5236)-e));
 x = sqrt(y^2+a^2-2*a*y*cos(z-d));

x =644.4203, y =271.3401 and z =3.1396

Subject: 3 equation of cosine law

From: Roger Stafford

Date: 2 Apr, 2013 22:34:13

Message: 12 of 12

"DHAAH JOHARI" <dhaah186@yahoo.com> wrote in message <kjf6tu$dc4$1@newscl01ah.mathworks.com>...
> My equations are incorrect, need to add 30 and 90 degrees for equations 2 and 3.but, the answers are still the same as x=444.46, y=149.25.
>
> x^2=y^2+233600-966.64*y*cos(z-65.56) ...........................(1)
> x^2=y^2+155600-788.92*y*cos((z+30)-59.53) ............................(2)
> x^2=y^2+97600-624.82*y*cos((z+90)-50.19) ..............................(3)
> ..........
- - - - - - - - - -
  For your revised equations I think it would be easier to simply modify the definitions of e and f in my analysis.

 format long
 a = sqrt(233600);
 b = sqrt(155600);
 c = sqrt(97600);
 d = 65.56*pi/180;
 e = (59.53-30)*pi/180; % <-- Changed
 f = (50.19-90)*pi/180; % <-- Changed
 A = a*(b^2-c^2)*cos(d)+b*(c^2-a^2)*cos(e)+c*(a^2-b^2)*cos(f);
 B = a*(b^2-c^2)*sin(d)+b*(c^2-a^2)*sin(e)+c*(a^2-b^2)*sin(f);
 z = atan2(-A,B);
 y = 1/2*(a^2-b^2)/(a*cos(z-d)-b*cos(z-e));
 x = sqrt(y^2+a^2-2*a*y*cos(z-d));

When matlab computes this it gets the following:

 x = 454.0788771639416
 y = 142.0272229520070
 z = 2.36109416729929 (radians)
 z*180/pi = 135.2807308192048 (degrees)

  These do satisfy the revised equations to an accuracy of about 16 significant digits. Perhaps the differences of these from the results you expect is due to your use of slightly differing values for a, b, and c. That is, for example, in your equation

 x^2 = y^2+233600-966.64*y*cos(z-65.56)

the square root of 233600 is not exactly 966.64/2 as it should be for an accurate observance of the cosine law.

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