Phillip Brandel
Phillip Brandel

Reputation: 95

MatLab: using solve() to obtain the solution set of a system of linear equations, rather than a particular solution

I am working through some elementary linear algebra exercises and I want to obtain the solution set to the following system of linear equations using MatLab's solve() function, from the symbolic toolbox add-on:

2x      + z + w = 5
     y      - w = -1
3x      - z - w = 0
4x + y + 2z + w = 9

This system, when converted to reduced row-echelon form, retains a free variable, meaning there are infinitely many solutions, but when I use solve(), it simply returns a particular solution to the equation:

syms x y z w h i j k
eq1 = 2*x + z + w == 5;
eq2 = y - w == -1;
eq3 = 3*x - z - w == 0;
eq4 = 4*x + y + 2*z + w == 9;
solve([eq1,eq2,eq3,eq4])

returns

struct with fields:
    w: 3
    x: 1
    y: 2
    z: 0

This is a solution, but not the only solution. I would like to be able to (a) obtain the full solution set using solve(), and (b) not have to check whether the system has infinitely-many solutions outside of using solve(). (Currently, I am also setting up an augmented coefficient matrix, A, and using rref(A) to see whether there are any free variables). Are these goals possible or should I perhaps be using another function?

Edit: the problem seems to occur when the number of unknown variables is equal to the number of equations. When the number of unknowns exceeds the number of equations solve() returns a parameterized solution. I guess MatLab is assuming that when unknowns = equations that there is a unique solution, but of course this isn't always the case. Still do not know how to fix this.

Upvotes: 0

Views: 125

Answers (1)

John Bofarull Guix
John Bofarull Guix

Reputation: 820

For

A=[2 0 1 1;0 1 0 -1;3 0 -1 -1;4 1 2 1]; 
B=[5;-1;0;9];

just by trying

det(A)
rank(A)
v1=A\B
v2=mldivide(A,B)

One gets to any of the following, which are equivalent:

  • A is singular.

  • One cannot use A as orthogonal base dimension 4.

  • At least one of the vectors building A is proportional to the remaining 3.

The following don't work either

v3=linsolve(A,B)
dA=decomposition(A)
[L,U]=lu(A)
v5=U\(L\B)

or

[C,R]=qr(A,B,0)
v6=R\C

However one gets the smallest solution, there is an infinte amount of solutions, by approximating A :

v4=pinv(A)*B

v3 =
 1.0000
  0.3333
  1.6666
  1.3333

the eigenvalues are

veig=eig(A)
veig =
  3.7913
 -0.7913
  0.0000 + 0.000000062241112i
  0.0000 - 0.000000062241112i

For this particular A the symbolic toolbox may not be the best choice.

Upvotes: 0

Related Questions