下面写的是三边测量的代码。在由“ye”和“xe”(代码结尾)表示的节点的估计位置中引入了一个非常小的误差,例如在第二个节点的情况下,即 x(2)=4 和 y(2)=4位置是 xe(2)=3.999999999999999 和 ye(2)=3.999999999999999 而不是 4,4。类似地,第三个节点即 x(3)=3, y(3)=0 估计的位置是 xe(3)=3(没关系)和 ye(3)=-4.440892098500626e-16 而不是零。请提出导致此错误的原因以及如何删除它。此致。
x = [1,4,3]; % X coordinates of the three nodes to be localized
y = [4,4,0]; % X coordinates of the three nodes to be localized
% X and Y coordinates of the three antennas(a, b and c) that will be used
% to localize the three nodes mentioned above
xa=2; ya=3;
xb=1; yb=2;
xc=3; yc=2;
for i=1:3
% Find distances from user to all 3 transmitters:
da = sqrt((x(i)-xa)^2+(y(i)-ya)^2);
db = sqrt((x(i)-xb)^2+(y(i)-yb)^2);
dc = sqrt((x(i)-xc)^2+(y(i)-yc)^2);
va = ((db*db-dc*dc) - (xb*xb-xc*xc) - (yb*yb-yc*yc)) / 2;
vb = ((db*db-da*da) - (xb*xb-xa*xa) - (yb*yb-ya*ya)) / 2;
temp1 = vb*(xc-xb) - va*(xa-xb);
temp2 = (ya-yb)*(xc-xb) - (yc-yb)*(xa-xb);
% Estimated user position:
ye(i) = temp1 / temp2;
xe(i) = (va - y(i)*(yc-yb)) / (xc-xb);
end