warning: Matrix is singular

5 views (last 30 days)
Dimitris Georgis
Dimitris Georgis on 21 May 2015
Commented: Dimitris Georgis on 21 May 2015
Hi,
When i run the code, i get this warning
Matrix is singular, close to singular or badly scaled. Results may be inaccurate.
RCOND = NaN.
and the rest matrices v,var have inf values.
The matrix where i take this warning is 9x9. I attach part of the code to see better where is my fault.
for i=1:num_exp,
distance_hat=distance.*10.^(0.05*sqrt(sigma)*randn(1,N));
m = 2.3026*log10(distance_hat);
var = exp(4*m)*(exp(8*sigma.^2)-exp(4*sigma.^2));
v = var(1,1)+var(1,2:N);
S = eye(N-1).*diag(v) + ~eye(N-1).*var(1,1)
S12 = inv(S)
sol = loc(x,distance_hat,S12);
weighted = loc(x,distance_hat,S12);
end
what should i change to not take this warning?
  3 Comments
Dimitris Georgis
Dimitris Georgis on 21 May 2015
I use "i" for experiment loop and find the average error. So the rest command to end the for loop are:
error(i)=sqrt((sol(1)-u(1))^2+(sol(2)-u(2))^2);
Jan
Jan on 21 May 2015
Do not overwrite the important function "error" by a variable.

Sign in to comment.

Accepted Answer

Jan
Jan on 21 May 2015
I guess that the line, which causes the error, is:
S12 = inv(S)
(Please post the complete error message - most of all it is inefficient to let the readers guess, where the error appears.) Then the message means, that there is no inverse of S. Because we do not know, why you create S in the shown way, there is no chance to suggest an improvement.
  1 Comment
Dimitris Georgis
Dimitris Georgis on 21 May 2015
The complete error message is: "In least_squares_loc (line 15) In run_loc (line 31) Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN."
I have attach the code to run it, and check.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra 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!