-1

I have a 3x3 matrix, for example A=[3,2,4;2,0,2;4,2,3], and I'm trying to solve the following linear system in the form A*[a;b;c] = [8*a;8*b;8*c]:

3 2 4   a   8a
2 0 2 * b = 8b
4 2 3   c   8c

Ok, so I have:

3a + 2b + 4c = 8a
2a +      2c = 8b
4a + 2b + 3c = 8c

It's underdetermined, and an answer would be [2;1;2] In fact, if I use an online linear solver like this one‎, it will give me an answer like this:

{ a = r1, b = r1/2, c = r1 }

Still, I can't find a way to do that in Matlab. If I define B as B=[8*a;8*b;8*c] and try A\B, i get:

 2*b - 4*a + 4*c
 2*a - 7*b + 2*c
 4*a + 2*b - 4*c

And if I define B as [8;8;8], I get:

2
-3
2

While I expected:

2
1
2

Or something like the answer from the online solver form above. What am I doing wrong? Thanks in advance!

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • This question does NOT belong on SO, having nothing to do with programming. It does belong on a basic math site, where they would explain that the problem is not underdetermined, but is rank deficient. A homogeneous, deficient 3x3 linear system of equations. As such, there are infinitely many solutions, ONE of which is the zero solution. Note that 8 is an eigenvalue of the original matrix. –  Jul 16 '13 at 00:26
  • Hello @woodchips ! Maybe I expressed myself badly, but it is, at least as I see it, a programming problem. A very basic one, I admit, but I tried reading lots of material, and couldn't get an answer. In fact it is an rank deficient problem, my bad on that, but I actually understand the math part. I just can't use Matlab to reach the same result I get from solving it by hand or with the website I mentioned (http://wims.unice.fr/wims/en_tool~linear~linsolver.en.html), and would like some help to know why. I need it to show a vector v1=[a;b;c] for which A*v1 = 8*v1. An answer would be [2;1;2].Tks – user2529509 Jul 16 '13 at 00:48
  • If you do understand the mathematics, then a start would lie in the command "help eig", or perhaps "help null". I think you understand only the very basic idea of a system of equations, so you do NOT actually understand the mathematics because of how you tried to solve it. As such this is not programming, but a question of mathematics. –  Jul 16 '13 at 01:00
  • Again, using pen and paper, I got the answer, and it is the same in the aforementioned website. As I know that in Matlab I proceeded in a wrong way, provided it didn't generate a solution in the expected form, and I thought someone here would help me find a way to do a similar procedure in Matlab of finding a vector v1=[a;b;c] for A*v1=8*v1, different from [0;0;0], as was [2;1;2], for example. I also am aware that I probably couldn't express my doubt well, but it was the best I could do. Still, thanks anyway, and I'll try to get help somewhere else. – user2529509 Jul 16 '13 at 01:15

1 Answers1

1

Oh well, even though this is NOT a programming problem, I'll answer it.

The question is to solve the linear system

Ax = 8x

where the 3x3 matrix A is given, and x is a 3x1 unknown vector.

A = [3 2 4;2 0 2;4 2 3];
[v,d] = eig(A)
v =
   -0.4941   -0.5580    0.6667
   -0.4720    0.8161    0.3333
    0.7301    0.1500    0.6667

d =
   -1.0000         0         0
         0   -1.0000         0
         0         0    8.0000

Here we see that the third eigenvalue is 8, so there is indeed a non-degenerate solution to the problem. It is of the form

k*v(:,3)

since v(:,3) is the corresponding eigenvector.

format rat
v(:,3)
ans =

       2/3     
       1/3     
       2/3     

Clearly this results in the solution given by the asker.

I'll note that this all works ONLY because the problem was posed in the form A*x=lambda*x, so a classical eigenvalue problem. Again, if you appreciate the mathematics behind the solution, then we can solve the problem using null:

null(A - 8*eye(3))
ans =
       2/3     
       1/3     
       2/3     

Of course, we could have used the symbolic toolbox.

sol = solve('3*a + 2*b + 4*c = 8*a','2*a + 2*c = 8*b','4*a + 2*b + 3*c = 8*c');

sol.a
ans =
z

sol.b
ans =
z/2

sol.c
ans =
z

Suppose instead that the problem was a completely general one? Thus, still a homogeneous linear system, but not an obvious eigenvalue problem? As an example, I'll try to solve the arbitrary linear problem

A*[a;b;c] = [a;2*b;3*c]

See that this is NOT written in the form of an eigenvalue problem. There are actually several ways we might decide to solve it. The unknowns are on BOTH sides of the equality. So just move them all to the left hand side. Semi-mathematically, we might do this as

B = A - diag([1 2 3])
B =
       2              2              4       
       2             -2              2       
       4              2              0       

We now try to solve the linear system

Bx = B*[a;b;c] = [0;0;0]

Do solutions to this exist? This time, they do not exist, beyond the trivial, degenerate solution, because B has full rank.

rank(B)
ans =
       3       

A full rank, homogeneous linear system has only the degenerate (zero) solution. Null tells us this too.

null(B)
ans =
   Empty matrix: 3-by-0

The symbolic toolbox solution reflects that fact.

sol = solve('3*a + 2*b + 4*c = a','2*a + 2*c = 2*b','4*a + 2*b + 3*c = 3*c')

sol.a
ans =
0

sol.b
ans =
0

sol.c
ans =
0

Until you appreciate the mathematics of the linear systems involved, this really is NOT a programming problem, and then it is essentially one command to solve the problem, so still not really much of a programming problem.

  • I really appreciate your comprehension, @woodchips! I'm sorry if that went beyond SO's scope, since at that site it provided an answer as expected by simply putting the matrix, I honestly thought that it was only a matter of Matlab sintax that I couldn't figure out; I was thinking that there was some way to automatically provide an answer like that at Matlab. Still, I thank you for explaining alternatives to that! – user2529509 Jul 16 '13 at 01:51