solve returns empty set

11 Ansichten (letzte 30 Tage)
hamad alduaij
hamad alduaij am 13 Mär. 2016
Kommentiert: Walter Roberson am 13 Mär. 2016
Hello there is this weird thing going on where solve command gives me empty set to everything I put when I run my program ----
% EE 589 project
%Range estimation
%Ri=[(x-xi)^2+(y-yi)^2)^1/2
%ri=ri-r1
%s=x^2+y^2
%ki=xi^2+yi^2
%d=cti=ru+ei
c=3*10^8 ; %speed of light
T0= input('Enter your TOA vector ');
n=size(T0,1);
sigma=-1;
while( sigma <0)
sigma= input('Enter variance of noise ');
end
e=sigma*randn(n,1); %%defining noise
T=T0+e; %%Adding noise to data
Q=var(e)*eye(n); %%Defining covariance matrix
xi=input('Enter x coordinates of sensors');
yi=input('Enter y coordinates of sensors');
while(size(xi,1) ~=n | size(yi,1) ~=n)
xi=input('Enter x coordinates of sensors');
yi=input('Enter y coordinates of sensors');
end
M=transpose([xi yi]);
d=c*T;
syms S;
k=xi.^2+yi.^2;
b=S*ones(n,1)+k-d.^2;
LS=inv(M*transpose(M))*M*b;
[x,y]=deal(LS(1),LS(2));
syms Initialvalue;
Initialvalue = solve(S==x^2+y^2);
initialvalue=double(Initialvalue);
roots=initialvalue;
case1=0; if (roots(1)<0 && (roots(2)>0&&imag(roots(2))==0))
s=roots(2);
case1=1;
end
if (roots(2)<0 && (roots(1)>0&&imag(roots(1))==0))
s=roots(1)
case1=1;
end
case2=0;
if (case1~=1)
if((imag(roots(1))~=0))
s=abs(real(roots(1)));
case2=1;
end
if(case2~=1)
%case3 both negative comparing for minimum J
stest1=abs(real(roots(1)));
stest2=abs(real(roots(2)));
[xtest1,ytest1]=deal(subs(LS(1),stest1),subs(LS(2),stest1));
[xtest1,ytest1]=deal(double(xtest1),double(ytest1));
rtest1=((ones(n,1)*xtest1-xi).^2+(ones(n,1)*ytest1-yi).^2).^.5;
Jtest1=transpose(T-rtest1/c)*inv(Q)*(T-rtest1/c);
[xtest2,ytest2]=deal(subs(LS(1),stest2),subs(LS(2),stest2));
[xtest2,ytest2]=deal(double(xtest2),double(ytest2));
rtest2=((ones(n,1)*xtest2-xi).^2+(ones(n,1)*ytest2-yi).^2).^.5;
Jtest2=transpose(T-rtest2/c)*inv(Q)*(T-rtest2/c);
if(Jtest1<=Jtest2)
s=stest1;
end
if(Jtest1>=Jtest2)
s=stest2;
end
end
end
[x,y]=deal(subs(LS(1),s),subs(LS(2),s));%assigning LS output to x,y
[x,y]=deal(double(x),double(y));
ri=((ones(n,1)*x-xi).^2+(ones(n,1)*y-yi).^2).^.5;%distance from x to sensors
for(h =1:5000)
for( i= 1:n)
g(i,1)=(x-xi(i))/(ri(i)*(ri(i)+d(i)));
h(i,1)=(y-yi(i))/(ri(i)*(ri(i)+d(i)));
end
A(1,1)=2*sum(g.*xi);
A(1,2)=2*sum(g.*yi);
A(2,1)=2*sum(h.*xi);
A(2,2)=2*sum(h.*yi);
B(1,1)=sum(g.*(ones*s+k-d));
B(2,1)=sum(h.*(ones*s+k-d));
solve=inv(A)*B;
[x,y]=deal(solve(1),solve(2));
end
---- if I run this it works and I get the result I want but if i try to run it again it won't work, and the solve command stops working and gives empty set even if i try to solve for like syms s solve(s==1) it will be empty set but only if i run my program
  2 Kommentare
hamad alduaij
hamad alduaij am 13 Mär. 2016
Bearbeitet: Walter Roberson am 13 Mär. 2016
never mind I figured it out the problem was this somehow
solve=inv(A)*B;
[x,y]=deal(solve(1),solve(2));
I changed solve to solution and it worked out
Walter Roberson
Walter Roberson am 13 Mär. 2016
You should avoid using inv(A) .
solution = A\B;

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by