0
下面寫的是三邊測量的代碼。例如在第二個節點的情況下,例如x(2)= 4和y(2)= 4,在由「ye」和「xe」表示的節點的估計位置(代碼的結尾)中引入非常小的誤差位置是xe(2)= 3.999999999999999,ye(2)= 3.999999999999999而不是4,4。類似地,第三個節點,即x(3)= 3,y(3)= 0,估計的位置是xe(3)= 3(這是可以的)和ye(3)= - 4.440892098500626e-16而不是零。請提出造成此錯誤的原因以及如何刪除它。最好的祝福。三邊測量代碼中的錯誤Matlab
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