How to find which equation that have "Warning: Solution does not exist because the system is inconsistent"

10 次查看(过去 30 天)
I have big matrix and want to solve it with "\".
Ax=B so I use
[A,B]=equationsToMatrix(k,q)
x=A\B
but the matrix cannot be solved, the solution of x = Inf
How to know which one equation that makes x dont have solutions?

回答(1 个)

Walter Roberson
Walter Roberson 2022-12-4
If you get inf on output, there are few possibilities:
  • that there are infinite entries in the matrix (but these would typically lead to NaN)
  • that the matrix has a quite high condition number, leading to overflows in the calculation (NaN might well show up as well). This can include the case where the matrix is singular algebraically but the determinant is not exact zero due to floating point round-off
Example:
format long g
M = imag(hilbert(magic(5))) / 1e5
M = 5×5
1.0e+00 * -8.25829152282704e-05 7.13012616304923e-05 0.000102078097002245 -7.53174899482168e-05 -1.54789534562498e-05 7.85666869105459e-05 0.000102078097002245 -8.25829152282704e-05 -4.62557888280024e-05 -5.18060798565179e-05 7.13012616304923e-05 -5.18060798565179e-05 -3.89903635479488e-05 -5.18060798565179e-05 7.13012616304923e-05 -5.18060798565179e-05 -4.62557888280024e-05 -8.25829152282704e-05 0.000102078097002245 7.85666869105459e-05 -1.54789534562498e-05 -7.53174899482168e-05 0.000102078097002245 7.13012616304922e-05 -8.25829152282704e-05
rank(M)
ans =
4
cond(M)
ans =
3.42148903474857e+16
M\(1:5).'
Warning: Matrix is singular to working precision.
ans = 5×1
NaN NaN Inf Inf Inf
If you do not have actual infinite entries then there isn't "one equation" that makes it "not have a solution". Consider for example
[1 2 3
2 4 6
3 5 9]
ans = 3×3
1 2 3 2 4 6 3 5 9
Which "one equation" makes this not have an answer? You might at first say that it is the [2 4 6] because that is a constant multiple times an earlier row, but you could just as well say that the problem is the [1 2 3] for being a constant multiple of [2 4 6] .
When you use EquationsToMatrix() then you are working with systems of symbolic equations that are probably not inherently ordered. In such cases it could not be considered to be the "fault" of the second matrix that the system is not consistent; if you had happened to enter the equations in a different order then it would have been a different row "at fault".
It is fair to ask which rows are linearly dependent on earlier rows, understanding that does not mean that such rows are "wrong" (could be the other rows fault). I am not sure what a robust solution for that is, but it looks to me as if you can proceed to
[P,r] = rref(M.');
dependent_rows = setdiff(1:size(M,1), r)
dependent_rows =
5
This particular example happens to indicate that the last row is the first dependent row, but if you do something like
N = 20;
A = rand(N);
RRR = randperm(N,3)
RRR = 1×3
6 3 18
A(RRR(1),:) = A(RRR(2),:) * 5 - A(RRR(3),:) * 19;
[P,r] = rref(A.');
dependent_rows = setdiff(1:N, r)
dependent_rows =
18
dependent_rows == max(RRR)
ans = logical
1
We were successful in identifying a dependent row. We constructed row 6 as dependent on row 3 and 18, but mathematically that is equivalent to saying that row 18 is dependent on rows 3 and 6 -- which further emphasizes my point earlier that you have to be careful about which equation you blame.
  7 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by