System of Equations Yields Complex Numbers Unnecessarily
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to solve a 3x3 systems of equations to find X, and Y coordinates, and the range from an observer. These should be real numbers, but for some reason they are outputted as a weird root (Below). When I use double( ) it yields that it is a complex number. How can I clean up this output?
syms RedXCalc RedYCalc RedRangeCalc
[RedXCalc, RedYCalc, RedRangeCalc]=solve(ReddistExp==sqrt( ((data_save(i-1,rxj)-RedXCalc)^2)+((data_save(i-1,ryj)-RedYCalc)^2)),...
RedXCalc==RedRangeCalc*sind(RedAngleObs),RedRangeCalc==sqrt(((BlueX-RedXCalc).^2)+(BlueY-RedYCalc).^2))
root(z^4 + (13169922781387370140211034197375*z^3)/2475880078570760549798248448 - (933094242449701722054817692661421202445777037571175903347362559*z^2)/24519928653854221733733552434404946937899825954937634816 - (3192977729811664412596503120376091121112430054796509685545157853*z)/11972621413014756705924586149611790497021399392059392 + 26246170355121000441473231481554113122634241496080573907813636553/23384026197294446691258957323460528314494920687616, z, 1)
0 comentarios
Respuestas (1)
John D'Errico
el 13 de Feb. de 2023
Editada: John D'Errico
el 13 de Feb. de 2023
It is not clear what that system of equations represents, since you have sines of angles in there. Regardless, a complex result typically means you have an inconsistency in your information. Or, possibly, you may have implemented an incorrect set of equations. I've not looked carefully at your code to try and figure out what those equations mean.
So I'll create an example, solve it, and show why a complex result can arise.
Two points in the plane:
XY1 = [1 3];
XY2 = [5 2];
So two points in the plane, represented by the (x,y) coordinates of those points. At each point, we will have a microhone with a clock, so we know when a noise is heard.
Now, suppose we have a single person, who fires off gun, and then we measure the amount of time before the sound is heard at each point. Given the speed of sound, this tells us the distance to each measurement station. Typically we might have multiple such stations set up to monitor. But we can use a technique like this to locate where the noise was originally generated.
I'll just pick two distances arbitrarily.
D1 = 4; % the distance to point 1
D2 = 3; % the distance to point 2
We can visualise this in terms of the intersections of circles. I'll show that later.
syms X Y % the (x,y) coordinates of the noise origin
E1 = (X - XY1(1))^2 + (Y - XY1(2))^2 == D1^2;
E2 = (X - XY2(1))^2 + (Y - XY2(2))^2 == D2^2;
[Xsol,Ysol] = solve(E1,E2,[X,Y]);
double(Xsol)
double(Ysol)
So in the very simple example I have given here, there are two possible solutions where the noise might have originated.
But, now suppose I change the distances that were reported?
D1 = 1;
D2 = 2;
[Xsol,Ysol] = solve((X - XY1(1))^2 + (Y - XY1(2))^2 == D1^2,(X - XY2(1))^2 + (Y - XY2(2))^2 == D2^2,[X,Y]);
double(Xsol)
double(Ysol)
And now the results are complex. Why is that?
Look carefully at the mathematics of what I did. Effectively, I am solving for the intersection of two circles, with different centers and different radii. Now let me plot the circles in the last problem.
t = linspace(0,2*pi);
plot(D1*cos(t)+XY1(1),D1*sin(t)+XY1(2),'-r',D2*cos(t)+XY2(1),D2*sin(t)+XY2(2),'-g')
legend('Circle 1','Circle 2')
axis equal
The complex solution with the second pair of distances tells me there is NO intersection of the pair of circles. The distances reported were too short for that to be possible.
That is the common explanation for what has happened when you try to solve such a problem, and you get a complex solution. It tells you that either you have formulated the equations improperly, OR your data is inconsistent. Since your question is too vague for me to know what the equations actually should represent, I won't try to untangle them.
0 comentarios
Ver también
Categorías
Más información sobre Equation Solving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!