is this code is right? this code is for trilateration it shows error.
1 view (last 30 days)
Show older comments
Darshan Patel
on 3 Jun 2016
Commented: Walter Roberson
on 3 Jun 2016
This code is shows error at line 22 and 29
warning is : matrix is singular to working precision.
is this code is right if not please give suggetions..
function [ x, y ] = two_tri(x1, x2, x3, y1, y2, y3, d1, d2, d3)
%2-D trilateration function
% Inputs: Readers 1-3 (x,y) and Distances to Tag
%
% x_n1 = (d1^2 - d2^2)-(x1^2 - x2^2)-(y1^2 - y2^2)*2*(y3 - y1)
% x_n2 = 2*(y2 - y1)*(d1^2 - d3^2) - (x1^2 - x3^2) - (y1^2 - y3^2)
% x_d = 2*(x2 - x1)*2*(y3 - y1) - 2*(y2 - y1)*2*(x3-x1)
% x = (x_n1 - x_n2)/x_d
% y = 2;
%
x_n11 = (d1^2 - d2^2) - (x1^2 - x2^2) - (y1^2 - y2^2);
x_n21 = (d1^2 - d3^2) - (x1^2 - x3^2) - (y1^2 - y3^2);
x_n12 = 2*(y2-y1);
x_n22 = 2*(y3-y1);
d11 = 2*(x2-x1);
d21 = 2*(x3-x1);
d12 = 2*(y2-y1);
d22 = 2*(y3-y1);
x_n = [x_n11, x_n12; x_n21, x_n22];
d = [d11, d12; d21, d22];
x = x_n/d;
x = det(x);
y_n11 = d11;
y_n21 = d21;
y_n12 = x_n11;
y_n22 = x_n21;
y_n = [y_n11, y_n12; y_n21, y_n22];
y = y_n/d;
y = det(y);
x11=[x1 x2 x3 x];
y11=[y1 y2 y3 y];
scatter(x11,y11);
disp(x11);
disp(y11);
end
0 Comments
Accepted Answer
Walter Roberson
on 3 Jun 2016
You never use the output of your det() calls, so you should get rid of them.
3 Comments
Walter Roberson
on 3 Jun 2016
You cannot run the code just by pressing an F key or clicking on the Run button. You need to go to the command line and use the routine in command form, passing in the data you need. For example,
x = rand(1,3); y = rand(1,3); d = rand(1,3);
[X, Y] = two_tri(x(1), x(2), x(3), y(1), y(2), y(3), d(1), d(2), d(3))
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!