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

1,329 ビュー (過去 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