# Solving vector equations with matlab

1. Feb 24, 2005

### gnome

I'm just starting (way overdue really) to learn how to use matlab.

Suppose you have a system of linear equations for which this is the augmented matrix:

$$\begin{array}{cccc}1 &5 &-3 &-4\\ -1 &-4 &1 &3\\ -2 &-7 &0 &h \end{array}$$

how would you find (using Matlab) the value(s) of h for which it's consistent?

Obviously this example is trivial to solve by hand, but suppose it were a much bigger matrix. Is there a way to set up a matrix with variables for one or several elements and solve for those variables? Or, just do a row reduction while keeping the variables in place so you would then be able to determine the consistent values by inspection? Or some other way?

2. Feb 25, 2005

### Muzza

Surely it's just a matter of getting Matlab to calculate the determinant of the coefficient matrix, and then checking for what values of the parameter it's equal to 0.

Last edited: Feb 25, 2005
3. Feb 25, 2005

### cronxeh

>> syms h
>> rref([1 5 -3 -4; -1 -4 1 3; -2 -7 0 h])

ans =

[ 1, 0, 7, 0]
[ 0, 1, -2, 0]
[ 0, 0, 0, 1]

h= 1 ?

Finding determinant for this matrix would require the matrix to be square.. which is kinda a bummer, since it isnt.

Last edited: Feb 25, 2005
4. Feb 25, 2005

### Muzza

But the coefficient matrix is just

1 5 -3
-1 -4 1
-2 -7 0,

(excuse the lack of LaTeX), which has a determinant of 0, so it's not invertible. Thus your system is never consistent, no matter what the value of "h" is. And that's another thing, whatever is in the last column of the augmented matrix must be totally irrelevant to the consistency of the system, right (unless I have my terminology mixed up)?

Last edited: Feb 25, 2005
5. Feb 25, 2005

### cronxeh

If det of coefficient matrix is not equal to 0, the system is uniquely determined. But it will still be constistant even if its undertermined (infinity number of solutions, laying on same line, A isnt invertible, det of coefficient matrix = 0)

6. Feb 25, 2005

### Muzza

My bad, I thought "consistent" meant "has a unique solution".

7. Feb 25, 2005

### cronxeh

Carefully scrutinizing this problem on paper, I've reached these results:

a=-7c+1
b=(-2a-5)/7
c=(1-a)/7

h= 14c + 2a + 3

I havent graphed h against all variables but it should be pretty interesting to analyse it. I dont have all the necessary multivariable calculus math to analyse such a system though.

But here are a few solutions:
a=-6, b=1, c=1, h=5
a=-5/2, b=0, c=1/2, h=5
a=-17/2, b=12/7, c=1, h=0

I guess the matrix should then be:

$$\left(\begin{array}{abck} 1 & 0 & 0 & -7c+1\\ 0 & 1 & 0 & (-2a-5)/7 \\ 0 & 0 & 1 & (h-2a-3)/14 \end{array}\right)$$

Last edited: Oct 8, 2005
8. Feb 25, 2005

### gnome

Thanks, everyone, but I'm really puzzled by these responses. First of all, this was not an actual problem I was trying to solve; just a simple example that I thought would clarify my question.

Supposing that this particular one represented the matrix equation Ax = b, to solve it on paper I would (following the method described in my textbook) row-reduce it like this:

$$\begin{array}{cccc}1 &5 &-3 &-4\\ -1 &-4 &1 &3\\ -2 &-7 &0 &h \\ \\ 1 &5 &-3 &-4\\ 0 &1 &-2 &-1\\ 0 &3 &-6 &h-8 \\ \\ 1 &5 &-3 &-4\\ 0 &1 &-2 &-1\\ 0 &0 &0 &h-5 \end{array}$$

and I conclude that h = 5 is required to have a consistent system.
Now, if h = 5,
$$b = \left [ \begin{array}{c} -4\\ 3 \\ 5 \end{array} \right ]$$

and $x_3$ is a free variable so there will be an infinite number of solutions, right?

But all that is beside the point (unless what I just did is somehow wrong; if so please correct me).

My question is, suppose I'm dealing with Ax = b where part of b is unknown and A is a 400 x 100 matrix and x and b are each 100 x 1 so I don't feel up to doing the row reduction on paper, and the coefficient matrix is not square, so as far as I know there's no determinant test that will tell me anything about Ax = b.

Is there any way to solve such a thing with Matlab?

9. Feb 25, 2005

### cronxeh

>> rref();

Will give you reduced matrix b, usually in Identity-augment form.

10. Feb 25, 2005

### gnome

Finally we get to the crux of the matter.

It accepts only actual numbers in the matrix. I can't find any way to enter a variable as an element of a matrix.
:yuck:

11. Feb 25, 2005

### cronxeh

Refer to my first post please

>> syms h
>> rref([a11 a12 a13; a21 a22 a23; a31 a32 h])

Use syms to create a variable
e.g.: syms x

12. Feb 25, 2005

### gnome

I don't understand what that's doing, and it seems to be coming up with the wrong answer.

13. Feb 25, 2005

### gnome

OK, maybe I see what it's doing, but I don't see how to get anything useful out of it.
$$\begin{array}{cccc}1 &5 &-3 &-4\\ -1 &-4 &1 &3\\ -2 &-7 &0 &1 \end{array}$$
$$\begin{array}{cccc}1 &0 &7 &1\\ 0 &1 &-2 &-1\\ 0 &0 &0 &-4 \end{array}$$