Solving vector equations with matlab

In summary, you can use Matlab to find the value of h for which it's consistent, provided that the coefficient matrix is square. However, even if the matrix is square, there is still an infinite number of solutions, as x_3 is a free variable.
  • #1
gnome
1,041
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?
 
Physics news on Phys.org
  • #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:
  • #3
>> 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:
  • #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:
  • #5
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 isn't invertible, det of coefficient matrix = 0)
 
  • #6
My bad, I thought "consistent" meant "has a unique solution".
 
  • #7
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 haven't graphed h against all variables but it should be pretty interesting to analyse it. I don't 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:
  • #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?
 
  • #9
>> rref();

Will give you reduced matrix b, usually in Identity-augment form.
 
  • #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.
 
  • #11
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
I don't understand what that's doing, and it seems to be coming up with the wrong answer.
 
  • #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:

FAQ: Solving vector equations with matlab

1. How do I solve a vector equation using Matlab?

To solve a vector equation using Matlab, you will need to use the solve function. This function takes in the equation in the form of lhs = rhs, where lhs and rhs are the left and right hand sides of the equation, respectively. Matlab will then solve for the unknown variables in the equation and return the solutions in a vector.

2. What is the syntax for solving a vector equation in Matlab?

The syntax for solving a vector equation in Matlab is as follows: syms x y z (to declare the unknown variables), eqn = lhs == rhs (to define the equation), and sol = solve(eqn) (to solve the equation and store the solutions in a vector called sol).

3. Can Matlab solve systems of vector equations?

Yes, Matlab can solve systems of vector equations. You will need to define each equation in the system using the == operator, and then use the solve function to solve for the unknown variables. The solutions will be returned in a vector containing the values for all the unknown variables.

4. How accurate are the solutions obtained from solving vector equations with Matlab?

The accuracy of the solutions obtained from solving vector equations with Matlab depends on the accuracy of the input equations and the numerical methods used by Matlab to solve them. In general, Matlab produces accurate solutions, but it is always important to verify the results and make sure they make sense in the context of the problem being solved.

5. Are there any other functions in Matlab that can be used to solve vector equations?

Yes, there are other functions in Matlab that can be used to solve vector equations, such as fsolve and vpasolve. These functions use different numerical methods and may be better suited for certain types of equations or systems of equations. It is always a good idea to explore different options to find the most accurate and efficient solution for your specific problem.

Similar threads

Replies
5
Views
2K
Replies
5
Views
761
Replies
3
Views
4K
Replies
1
Views
1K
Replies
5
Views
2K
Replies
2
Views
1K
Replies
6
Views
1K
Back
Top