0

I am trying to solve a system of three equations with three unknown variables.

A1=((x+y)/2)+((x-y)/2*cos(2*phi))+(z*sin(2*phi))/2
A2=(x+y)/2-((x-y)/2)*cos(2*phi)-(z*sin(2*phi))/2
A3/2=(-(x-y)/2)*sin(2*phi)+(z*cos(2*phi))/2

where A1, A2, A3, and phi are known and x,y, and z are unknown. I got the result but its not correct because when I checked with isequal it give me 0

This is the code

clear;
clc;
A1=50;
A2=37.5;
A3=125.6;
phi=-17.9;
syms x y z
eqn1 = (x+y)/2+(((x-y)/2)*cosd(2*phi))+(z*sind(2*phi))/2== A1;
eqn2 = (x+y)/2+(((x-y)/2)*cosd(2*phi))-(z*sind(2*phi))/2== A2;
eqn3 = ((-(x-y))/2*sind(2*phi))+((z/2)*cosd(2*phi))== A3/2;

[X, Y, Z] = solve(eqn1, eqn2, eqn3);
X = double(X);
Y = double(Y);
Z = double(Z);

AB=(X+Y)/2+(((X-Y)/2)*cosd(2*phi))+(Z*sind(2*phi))/2;
AC=(X+Y)/2+(((X-Y)/2)*cosd(2*phi))-(Z*sind(2*phi))/2;
AD=((-(X-Y)/2)*sind(2*phi))+((Z/2)*cosd(2*phi));

Z1=isequal(AB,A1);
Z2=isequal(AC,A2);
Z3=isequal(AD,A3/2);
user6052232
  • 169
  • 1
  • 10
  • Perhaps [this can help you](http://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab) – il_raffa Feb 11 '17 at 16:16
  • @ il_raffa . Thank you. I do not understand why it is working for some phi angle but not for another. Like if I use phi=28. I will get the answer correctly – user6052232 Feb 11 '17 at 16:20
  • 1
    The solutions you get are _equal_ as two floating point number can be. `AB-A1` = -7.105427357601002e-15. – il_raffa Feb 11 '17 at 16:31
  • @ il_raffa. Thank you. However, if I want to reduce answer like to five digits in order to get the isequal correctly, what should I do? – user6052232 Feb 11 '17 at 16:38
  • 3
    I suggest to keep the results as they are calculatd by MatLab and, in case you want to _compare_ them against other values, to evalaute the difference and check that difference wrt a threshold you can properly define (e. g. 1.0e-5): `if(abs(A1-AB) <= 1.0e-5),disp('A1 and AB are equal');else disp('A1 and AB are NOT equal');end` – il_raffa Feb 11 '17 at 17:02
  • After all this time you should look into manually solving the system. You just have to unmake rotations by 45°, 2*phi and again 45°. That is, compute sum and difference of the first two equations, eliminate the trigonometric functions from the coefficients using trigonometric identities and compute `x,y` from `x+y,x-y`. – Lutz Lehmann Feb 11 '17 at 17:11
  • @ LutzL, Thank you. I agree with you if I have only one set of A1, A2, A3, and phi.However, if fact I have 500 sets. So, I still need to use the program. I just gave an example here for my solution. – user6052232 Feb 11 '17 at 17:24

0 Answers0