lsqnonlin is only giving the initial point

2 visualizaciones (últimos 30 días)
Günef Bozkurt
Günef Bozkurt el 9 de Ag. de 2020
Comentada: Günef Bozkurt el 11 de Ag. de 2020
I'm trying to find location of a target node using nonlinear least squares algorithm. The answer it gives is off, it only gives the initial point, and I can't figure out why. I tried mutliple things and thats why if the parts of code looks messy. I'd appreciate any help
Heres my code:
syms x y z k p lo la
P = k-sqrt((k-lo).^2+(p-la).^2)
ref_umram = txsite('Name','UMRAM',...
'Latitude',39.873297, ...
'Longitude',32.745859, ...
'TransmitterFrequency', 2.5e9);
ref_ee = txsite('Name','EE',...
'Latitude',39.872124, ...
'Longitude',32.750538);
ref_mayfest = txsite('Name','Mayfest',...
'Latitude',39.869953, ...
'Longitude',32.753181);
ref_bilka = txsite('Name','Bilka',...
'Latitude',39.864596, ...
'Longitude',32.747785); %4 reference nodes
%reference_nodes={'ref_umram','ref_ee','ref_mayfest','ref_bilka'};
ref_bilka2 = rxsite('Name','Bilka2',...
'Latitude',39.864595, ...
'Longitude',32.747785);
target_lat = randi([39864596 39873297])/1000000
target_lon = randi([32745859 32753181])/1000000
target = rxsite('Name','target',...
'Latitude',target_lat, ...
'Longitude',target_lon);
pm = propagationModel('freespace');
n_pathloss = 2; %path loss exponent given for freespace
d0 = distance(ref_bilka2,ref_bilka); %short reference distance
rss0 = sigstrength(ref_bilka2,ref_bilka,pm); %reference rss
noise=randn(1,4); %gaussian zero mean random variable vector
rss_umram = sigstrength(target,ref_umram,pm);
d_umram= 10^((rss0-rss_umram-noise(1))/(10*n_pathloss))*d0;
rss_ee = sigstrength(target,ref_ee,pm);
d_ee= 10^((rss0-rss_ee-noise(2))/(10*n_pathloss))*d0;
rss_mayfest = sigstrength(target,ref_mayfest,pm);
d_mayfest= 10^((rss0-rss_mayfest-noise(3))/(10*n_pathloss))*d0;
rss_bilka = sigstrength(target,ref_bilka,pm);
d_bilka= 10^((rss0-rss_bilka-noise(4))/(10*n_pathloss))*d0; %distances to reference nodes calculated
global z
z = [d_umram d_ee d_mayfest d_bilka]
z
k=[x y];
kk=dpure(k)
% lb=[31 38];
% ub=[33 40];
x0=[32 39];
options=optimoptions("lsqnonlin",'MaxIterations',1500,'FunctionTolerance',0)
[x,resnorm,residual,exitflag,output] = lsqnonlin(@dpure,x0)
function P = dpure(x)
global z
la=[39.873297 39.872124 39.869953 39.864596];
lo=[32.745859 32.750538 32.753181 32.747785];%ref node locations
P = z-sqrt((x(1)-lo).^2+(x(2)-la).^2);
end
  2 comentarios
Matt J
Matt J el 9 de Ag. de 2020
Some of your code requires special Toolboxes to run. It would be easier for us if you would just attach a .mat file containing the data vector z, which would make all but the last 3 lines of your code unnecessary for us.
Günef Bozkurt
Günef Bozkurt el 9 de Ag. de 2020
thanks for your feedback. z normally changes each turn but heres a file with a sample.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 9 de Ag. de 2020
Editada: Matt J el 9 de Ag. de 2020
I don't know if the solution is what you were expecting, but this gives exitflag 1,
la=[39.873297 39.872124 39.869953 39.864596].';
lo=[32.745859 32.750538 32.753181 32.747785].';%ref node locations
z = 10^3*[0.317139933557511 0.213426852450956 0.554382676693071 1.090925354925889].';
M=diff([eye(4);1 0 0 0]);
A=M*lo;
B=M*la;
C=M*(lo.^2+la.^2-z.^2)/2;
x0=[A,B]\C; %The unconstrained solution, with no bounds
lb=[31 38];
ub=[33 40];
options=optimoptions('lsqnonlin','Display','iter');
[x,resnorm,residual,exitflag,output] = ...
lsqnonlin( @(x) z-sqrt( (x(1)-lo).^2+(x(2)-la).^2 ), x0,lb,ub,options)
as well as quite good convergence with respect to the first optimality measure:
Norm of First-order
Iteration Func-count f(x) step optimality
0 3 1.6386e+06 1.64e+03
1 6 1.63248e+06 1.41421 0.00759
2 9 1.63248e+06 0.00232396 3.37e-11
  10 comentarios
Matt J
Matt J el 9 de Ag. de 2020
Editada: Matt J el 10 de Ag. de 2020
Is it this part? Would you mind explaining maybe?
If you were to remove the bounds lb,ub the problem has a closed-form analytical solution, and this solution might be a good initial guess x0 for the constrained problem. This is because if you subtract any two of your equations from each other, you obtain a linear equation:
(x1^2-2*x1*la(k)+la(k)^2)+(x2^2-2*x1*lo(k)+lo(k)^2) = z(k)^2
(x1^2-2*x1*la(m)+la(m)^2)+(x2^2-2*x1*lo(m)+lo(m)^2) = z(m)^2
-
_______________________________________________________________________________
-2*(la(k)-la(m))*x1 -2*(lo(k)-lo(m))*x2 =(z(k)^2-la(k)^2-lo(k)^2) - (z(m)^2-la(m)^2-lo(m)^2)
The set of equations generated this way can be solved by basic linear algebra.
Günef Bozkurt
Günef Bozkurt el 11 de Ag. de 2020
thank you so much

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by