필터 지우기
필터 지우기

Error: Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.

조회 수: 2 (최근 30일)
I am getting this error after implemnting my BCs:
clc; clear all;
N=30;
% compute the chebyshev differentiation matrix and x-grid
Ly =3;
eta_ygl = 2/Ly; etagl = -cos(pi*(0:N)/N)'; ygl = (etagl+1)/eta_ygl;
%ygl = -cos(pi*(0:N)/N)'; %Gauss-Lobatto Points
VGL = cos(acos(ygl(:))*(0:N));%C0 operator from thesis
dVGL = diag(1./sqrt(1-ygl.^2))*sin(acos(ygl)*(0:N))*diag(0:N);
dVGL(1,:) = (-1).^(1:N+1).*(0:N).^2;
dVGL(N+1,:) = (0:N).^2;
% Differentiation Matrices for Gauss & GaussLobatto
Dgl = dVGL/VGL;
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.696637e-34.
D = Dgl;
x=ygl;
% compute the derivatives at x (i.e. at the chebyshev grid points)
A=D*eta_ygl;
R = 2*x.*exp(x.^2 - 1);
% boundary condition
A(end,:) = 0;
A(end,end) = 1;
R(end) = exp(8); %u(Ly)
%LHS
A(1,:) = 0;
A(1,1) = 1;
R(1) = exp(-1); %u(0)
% solve
u = A\R;
plot(x,u,'--rs',x,exp(x.^2-1))
legend('Chebyshev','Exact')
The output is okay as shown in the plot, however I am not sure why I get the error and if there's a way to fix this? if I change the BCs I can get rid of the error but then the solution isn't right. Thanks!

답변 (2개)

Walter Roberson
Walter Roberson 2023년 10월 4일
% Differentiation Matrices for Gauss & GaussLobatto
Dgl = dVGL/VGL;
In MATLAB the / operator is mrdivide, / and is approximately equivalent to dVGL * pinv(VGL) -- which attempts to find linear models relating combinations of columns.
You probably want the ./ operator rdivide, ./
Or perhaps you should be looking at gradient
If you really do mean matrix division... you have the problem that rank(VGL) is only 8 for a 31 x 31 matrix...
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 10월 4일
If you proceed at higher precision then the actual rank of VGL is only 3.
Q = @(v) sym(v);
N=30;
% compute the chebyshev differentiation matrix and x-grid
Ly = Q(3);
eta_ygl = Q(2)/Ly;
etagl = -cospi(Q(0:N)/N)';
ygl = (etagl+1)/eta_ygl;
VGL = cos(acos(ygl(:))*(0:N));%C0 operator from thesis
dVGL = diag(1./sqrt(1-ygl.^2))*sin(acos(ygl)*(0:N))*diag(0:N);
dVGL(1,:) = (-Q(1)).^(1:N+1).*(0:N).^2;
dVGL(N+1,:) = Q(0:N).^2;
% Differentiation Matrices for Gauss & GaussLobatto
rank(VGL)
ans = 3
%Dgl = dVGL/VGL;

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


Bruno Luong
Bruno Luong 2023년 10월 4일
편집: Bruno Luong 2023년 10월 4일
N=30;
% compute the chebyshev differentiation matrix and x-grid
Ly =3;
eta_ygl = 2/Ly; etagl = -cos(pi*(0:N)/N)'; ygl = (etagl+1)/eta_ygl;
%ygl = -cos(pi*(0:N)/N)'; %Gauss-Lobatto Points
VGL = cos(acos(ygl(:))*(0:N));%C0 operator from thesis
I don't know what the "thesis" is about but I notice with the parameter you set (Ly=3) it is odd that you compute acos of ygl that goes up to 3 and not in the domain [-1,1]; so acos function returns a complex value. Then the imaginary part get large when you multiply by N. Then cos of the complex value behaves like cosh or more or less like an exponential function exp. You matrix VGL has huge dynamic range, and become totally ill-condition because pof this huge dynamic range. The warning about
Dgl = dVGL/VGL
is due to that. I guess your Gauss Labato somehow still working but as MATLAB warning warn 'The result is innacurate".
I guess the setup of Ly=3 is wrong or the way you use it is wrong.
Usually the Gauss Labato points coordinates are derived for [0,1] interval then scale it with mesh size. The mesh size should not be used i argument.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by