Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Solving vector equations with matlab

  1. Feb 24, 2005 #1
    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:

    [tex]\begin{array}{cccc}1 &5 &-3 &-4\\ -1 &-4 &1 &3\\ -2 &-7 &0 &h \end{array}[/tex]

    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. jcsd
  3. Feb 25, 2005 #2
    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
  4. Feb 25, 2005 #3

    cronxeh

    User Avatar
    Gold Member

    >> 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
  5. Feb 25, 2005 #4
    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
  6. Feb 25, 2005 #5

    cronxeh

    User Avatar
    Gold Member

    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)
     
  7. Feb 25, 2005 #6
    My bad, I thought "consistent" meant "has a unique solution".
     
  8. Feb 25, 2005 #7

    cronxeh

    User Avatar
    Gold Member

    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:

    [tex]\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)[/tex]
     
    Last edited: Oct 8, 2005
  9. Feb 25, 2005 #8
    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:

    [tex]\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}[/tex]

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

    and [itex]x_3[/itex] 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?
     
  10. Feb 25, 2005 #9

    cronxeh

    User Avatar
    Gold Member

    >> rref();

    Will give you reduced matrix b, usually in Identity-augment form.
     
  11. Feb 25, 2005 #10
    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:
     
  12. Feb 25, 2005 #11

    cronxeh

    User Avatar
    Gold Member

    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
     
  13. Feb 25, 2005 #12
    I don't understand what that's doing, and it seems to be coming up with the wrong answer.
     
  14. Feb 25, 2005 #13
    OK, maybe I see what it's doing, but I don't see how to get anything useful out of it.
    If you start with the matrix
    [tex]\begin{array}{cccc}1 &5 &-3 &-4\\ -1 &-4 &1 &3\\ -2 &-7 &0 &1 \end{array}[/tex]

    it reduces in a few steps to
    [tex]\begin{array}{cccc}1 &0 &7 &1\\ 0 &1 &-2 &-1\\ 0 &0 &0 &-4 \end{array}[/tex]

    You can then continue by dividing the last line by -4 and use the resulting 1 to eliminate the entries at (1,4) and (2,4) you would get what Matlab is showing as the "answer". But what kind of answer is that? What useful information (if any) can I get out of that?

    (But that's only if you start off with h = 1. Is it just arbitrarily replacing h with 1?)
     
    Last edited: Feb 25, 2005
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Solving vector equations with matlab
Loading...