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

210 ビュー (過去 30 日間)
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 日
編集済み: 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.

サインインしてコメントする。

その他の回答 (3 件)

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 件のコメント
Marcel Johannesmann
Marcel Johannesmann 2020 年 7 月 25 日
編集済み: Marcel Johannesmann 2020 年 7 月 26 日
I have encountered a similar warning. I could narrow it down to the Load flow settings of the power gui block. The warning most likely occurs because your Base Power is too high so that your rated values (in pu) in the admittance matrix are getting too small. Adjusting the base power fixed this issue for me. Hope this helps.
Mojtaba Raheli
Mojtaba Raheli 2020 年 9 月 27 日
編集済み: 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 日
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 日
編集済み: John D'Errico 2021 年 10 月 22 日
@Shaunak Bagade - what did you not get? I will not answer your question, not UNTIL you bother to post this as a question. Nor should anyone else. So while your question is of technical interest, posting it as an answer to a different question is a problem, because that means nobody else will ever be able to find your question, and nobody else will be able to learn from the answer. Effectively, if you are interested in learning the answer to this problem, then you should be interested enough to learn to use the site properly.
Note that as quasi-moderators, we should have the capability to move this into a question by the OP. But that is beyond our abilities.
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.

サインインしてコメントする。


Tugcan
Tugcan 2024 年 1 月 5 日
Hello guys i had a same error with different matlabs code. I tried this \ method but still i have this error. I get this error at values 80 120 and 320 for N. Best Regards.
Enter T:
1
Enter N:
80
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.765040e-19. > In question4s (line 18)
error =
1.8689e+13
function mixedboundary()
T=input("Enter T: ");
N=input("Enter N: ");
h=T/N;
A=zeros(N+1,N+1);
F=zeros(N+1,1);
A(1,1)=1;
A(N+1,1:3)=[-3, 4, -1];
F(1,1)=1;
F(N+1,1)=6*h;
for i=2:N
t(i)=(i-1)*h;
A(i,i-1)=1/(h^2)-5/(h);
A(i,i)=-2/(h^2)-3/(2*h);
A(i,i+1)=1/(h^2)-5/(h);
F(i,1)=14*exp(2*t(i))-3*exp(4*t(i));
end
Y=inv(A)*F;
exact=zeros(N+1,1);
for i=1:N+1
t(i)=(i-1)*h;
exact(i,1)=exp(2*t(i));
end
error=max(abs(exact-Y))
end
  4 件のコメント
Torsten
Torsten 2024 年 1 月 5 日
編集済み: Torsten 2024 年 1 月 5 日
The code has nothing to do with your assignment.
The method used in the code is suited for boundary value problems - thus problems where conditions on the solution are imposed at both ends of the interval of integration (in your case: t = 0 and t = T). In the assignment, both conditions are imposed at t = 0.
Further, you are told to first reduce the 2nd order differential equation to a system of two first order differential equations and then solve the system by a Runge-Kutta-method. Both does not happen in the code.
Tugcan
Tugcan 2024 年 1 月 6 日
I see. I have reduced formst but i dont know how to evolve it to Runge-Kutta-Method but thank you for attention

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStochastic Differential Equation (SDE) Models についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by