Loren on the Art of MATLAB

Turn ideas into MATLAB


Loren on the Art of MATLAB has been archived and will not be updated.

How to Check for Existence of Solution to Matrix Equations

There was a great question on the newsgroup this past week asking how to determine if a system of equations had a solution. The poster wasn't (at least yet) concerned with what the solution was.


First Solution

The first recommendation was to use det, the determinant. While this is pedagogically correct for some cases, it is insufficient since it doesn't correctly account for non-singular systems which do have solutions. John D'Errico followed up with some examples and some smart math.

Use rank

John points out that using det would not give the correct answer for this problem.

A = ones(2);
b = [2;2];

Does a solution exist for A*x = b? It does despite the singularity of A. det(A) is zero of course.

ans =

Yet the answer is just x = [1;1]. Find it using pinv.

ans =

Using rank, check to see if the rank([A,b]) == rank(A)

rank([A,b]) == rank(A)
ans =

If the result is true, then a solution exists.

Let's try it for a problem that has no solution.

c = [1;2];
rank([A,c]) == rank(A)
ans =

Did You Know...?

I had a previous post about collinearity in which we tried a bunch of solutions, and the superior solution again was rank vs. det. Did you know that some singular systems had valid solutions? Have you had similar instances where what the textbooks sometimes recommend isn't ideal for the full spectrum of possible conditions. Post your thoughts here.

Published with MATLAB® 7.9

  • print


コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。