Phil
Phil

Reputation: 304

How to solve an inconsistent system?

I'm new on MATLAB and I want to use it to solve an Ax = b system. I did this on paper and know I want to know if it's right. The problem is that it is an inconsistent system.

A=sym([3/sqrt(29) 3/sqrt(29) -1 0 0 0; 
1 -1 0 0 0 0; 
4/sqrt(29) 4/sqrt(29) 0 0 0 0; 
0 0 1 9/sqrt(101) 0 0; 
0 0 0 2/sqrt(101) -1/sqrt(5) 1/sqrt(5);
0 0 0 4/sqrt(101) 2/sqrt(5) 2/sqrt(5)])

c=sym([0 0 -a 0 0 -a])

When I tried finding the solution with:

A/c

I get:

Warning: The system is inconsistent. Solution does not exist. 

I found many themes about that on the Internet, but there was no solution. Does this mean that means MATLAB can't handle it or is there a way to get a solution?

Upvotes: 1

Views: 3490

Answers (1)

rayryeng
rayryeng

Reputation: 104555

The system is unfortunately not being solved properly. You need to use the ldivide (\) operator, not rdivide (/). Doing A/c is equivalent to A*c^{-1} and that's not what you want. To solve for the solution to the system, you must do A^{-1}*c or equivalently A\c. Also, in order to ensure that you get a proper solution, c needs to be a column vector, not a row vector. I'm also assuming that a is a constant which isn't declared in the current code.

Therefore:

syms a; %// Added

A=sym([3/sqrt(29) 3/sqrt(29) -1 0 0 0; 
1 -1 0 0 0 0; 
4/sqrt(29) 4/sqrt(29) 0 0 0 0; 
0 0 1 9/sqrt(101) 0 0; 
0 0 0 2/sqrt(101) -1/sqrt(5) 1/sqrt(5);
0 0 0 4/sqrt(101) 2/sqrt(5) 2/sqrt(5)]);

c=sym([0 0 -a 0 0 -a]).'; %// Change

out = A\c;

I get:

out =

   -(29^(1/2)*a)/8
   -(29^(1/2)*a)/8
          -(3*a)/4
  (101^(1/2)*a)/12
    -(5^(1/2)*a)/4
 -(5*5^(1/2)*a)/12

Upvotes: 5

Related Questions