Return if No Solution

조회 수: 11 (최근 30일)
Allison Bushman
Allison Bushman 2019년 9월 13일
댓글: Walter Roberson 2019년 9월 13일
I am asked to solve the equation: Ax = B for two randomly generated matrices. Furthermore, I am instructed that the script should return if no solution is found.
Here is my code:
n=100;
A=randn(n);
B=randn(n);
x = A\B;
I believe I know how to solve the equation, but don't know how to return if no solution is found. Is there a different way that I should be writing this? If not, how to I return if no solution is found?
  댓글 수: 1
the cyclist
the cyclist 2019년 9월 13일
Can you be more specific as to what you mean by "no solution"?
Do you mean if
x = A\B;
returns an error message, or something else?

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 9월 13일
You can test rank(A) . If it is < n then no solution is possible.
However, there are full rank matrices for which the matrix is too ill-conditioned for an inverse to be calculated. You can example cond() or rcond() and make a decision as to whether the matrix is too badly conditioned to proceed on.

추가 답변 (1개)

David Hill
David Hill 2019년 9월 13일
If A will always be a square matrix, then if the det(A)==0 then return (no solution).
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 9월 13일
det()==0 is not as good a test as rank() because det() is more prone to round-off error.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by