Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.202823e-18.

조회 수: 1,340(최근 30일)
Rui Mauaie
Rui Mauaie 2018년 11월 13일
댓글: John D'Errico 2021년 10월 22일
hi guys I need a help I'm using LDA but when I run I got the message aforementioned
S1=cov(d1');
S2=cov(d2');
S3=cov(d3');
%% within-class scatter matrix
Sw=S1+S2+S3;
%% between -class scatter matrix
SB1=n1.* (mu1-mu)*(mu1-mu)';
SB2=n2.* (mu2-mu)*(mu2-mu)';
SB3=n3.* (mu3-mu)*(mu3-mu)';
SB=SB1+SB2+SB3;
%% Computing the LDA projection
W=inv(Sw)*SB;
%% getting the projection vectors
[V,D]=eig(W);

채택된 답변

Jan
Jan 2018년 11월 13일
The error message is clear. I guess it occurs for this line:
W=inv(Sw)*SB;
This means, that Sw is ill-conditioned, such that there is no inverse of it. This is equivalent to dividing by zero. There is no "help" for this case, but the inputs do not allow this operation.
By the way, use
W=Sw \ SB
instead of the explicit inversion for numerical reasons. See doc inv .
  댓글 수: 3
Bruno Luong
Bruno Luong 2018년 11월 13일
Sw\SB
is based on QR with column permutation, so if you system is ill-conditions, it let some of the components of the unknown W to be 0.
pinv(Sw)*SB
is based on SVD, so it forces the projection of the unknown W to the span of the degenerated singular vectors to be 0.
Generally SVD solution is "better", in the sense that is the smallest vector (in l2 norm) that meets the solution (or minimizes the residual l2 norm), therefore more stable with respect to noise.

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Tony Castillo
Tony Castillo 2020년 1월 16일
Hello Guys,
I received this warning in a model made in Simescape Power Systems of Simulink,
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.051867e-16.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.051867e-16.
May you help me to solve it ?
Thanks in advance.
  댓글 수: 2
Mojtaba Raheli
Mojtaba Raheli 2020년 9월 27일
How did you do it? I cannot adjust base power. please write the direction of base power setting.

댓글을 달려면 로그인하십시오.


Shaunak Bagade
Shaunak Bagade 2021년 10월 19일
이 답변에 1명의 참여자가 플래그를 지정함
clc;
clear;
close all;
A = [2 1 -5; 0 1 -2; 0 0 2];
[P, D] = eig(A);
disp('P Matrix');
P Matrix
disp(P);
1.0000 -0.7071 1.0000 0 0.7071 -0.0000 0 0 0.0000
disp('Diagonal form of A is');
Diagonal form of A is
disp(P\D*P);
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 6.344132e-17.
2.0000 -0.7071 0.0000 0 1.0000 0.0000 0 0 2.0000
  댓글 수: 9
John D'Errico
John D'Errico 2021년 10월 22일
@Shaunak Bagade - Since you seem not to want to follow my guidance, see my question, AND answer, here:
From now on, please learn to post a question as a question, rather than hijacking a separate only vaguely related question.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by