how to solve the below non linear algebraic equation using matlab

How do we solve these two equations?
1.5 cos60 + 4.0 cos(x3) - 3.5 cos(x4) - 3.0 = 0
1.5 sin60 + 4.0 sin(x3) - 3.5 sin(x4) = 0
Since these are nonlinear algebraic equations, they can be solved numerically by iterative methods such as Newton-Raphson

Answers (2)

save this function myeq
function f=myeq(x)
f=[1.5*cos(60) + 4.0*cos(x(1)) - 3.5* cos(x(2)) - 3.0
1.5 *sin(60) + 4.0*sin(x(1)) - 3.5*sin(x(2))]
then call it
sol=fsolve(@myeq,[0;0])
You can perhaps get more insight into the solution of your equations if you proceed along lines such as the following. For convenience in notation rewrite the equations as
a*cos(u) = b*cos(v) + c
a*sin(u) = b*sin(v) + d
where u = x3, v = x4, a = 4, b = 3.5, c = 3-1.5*cos60, d = -1.5*sin60. Now square both sides of both equations and add them to obtain
a^2*cos(u)^2+a^2*sin(u)^2 = (b*cos(v)+c)^2+(b*sin(v)+d)^2
a^2 = b^2+2*b*(c*cos(v)+d*sin(v))+c^2+d^2
c*cos(v)+d*sin(v) = (a^2-b^2-c^2-d^2)/(2*b)
Now divide both sides by sqrt(c^2+d^2)
(c/sqrt(c^2+d^2))*cos(v)+(d/sqrt(c^2+d^2))*sin(v) =
(a^2-b^2-c^2-d^2)/(2*b*sqrt(c^2+d^2))
Use atan2 to get
t = atan2(d,c)
which will satisfy c = sqrt(c^2+d^2)*cos(t), d = sqrt(c^2+d^2)*sin(t) so that we get
cos(t)*cos(v)+sin(t)*sin(v) = cos(v-t) =
(a^2-b^2-c^2-d^2)/(2*b*sqrt(c^2+d^2))
v = t + acos((a^2-b^2-c^2-d^2)/(2*b*sqrt(c^2+d^2)))
This will have two solutions within the interval from -pi to +pi. Then to get u from v do
u = atan2((b*sin(v)+d)/a,(b*cos(v)+c)/a)
In other words it all reduces to the two matlab lines:
v = atan2(d,c) + acos((a^2-b^2-c^2-d^2)/(2*b*sqrt(c^2+d^2)));
u = atan2((b*sin(v)+d)/a,(b*cos(v)+c)/a);
except that you have to allow acos to have two solutions, one the negative of the other.
Much more satisfying in my opinion than a mindless solution from 'fsolve' where you may not be informed that there are infinitely many solutions (though of course more mental effort.)
Roger Stafford

2 Comments

hi i tried the last equation i.e.
v = atan2(d,c) + acos((a^2-b^2-c^2-d^2)/(2*b*sqrt(c^2+d^2)))
u = atan2((b*sin(v)+d)/a,(b*cos(v)+c)/a)
and used another equation to just check the error and i am getting some values which should be 0 or near to 0 .
e1=a*cos(u) - b*cos(v) - c
e2=a*sin(u)- b*sin(v) - d
I assumed by sin60 and cos60 you meant the sine and cosine of 60 degrees. I used those formulas I gave you with these values and arrived at
e1 = 0
e2 = 2.2204e-16
For the other pair with the acos result sign reversed I got
e1 = -4.4409e-16
e2 = -4.4409e-16
That's about as close to zero as you are going to get on a machine with 53-bit significands.
Roger Stafford

Sign in to comment.

Categories

Asked:

on 25 Dec 2012

Community Treasure Hunt

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

Start Hunting!