find rows of Zeros in matrix

12 visualizzazioni (ultimi 30 giorni)
Jennifer Samson
Jennifer Samson il 8 Ott 2018
Hi! I am wondering how to determine, in code, that there is a full row of zeros in a matrix? I am doing a Gauss Elimination and I need to return an error code if a row of zeros appears in my matrix after the first step.
  2 Commenti
madhan ravi
madhan ravi il 8 Ott 2018
an example?
Jennifer Samson
Jennifer Samson il 8 Ott 2018
well in Gauss Elimination the first step I have going is to convert my first matrix into an upper diagonal matrix, and the next step is to back calculate and solve for my x vector, but it there is a full row of zeros there are no unique solutions
example
[1 2 3] [4 5 6] [7 8 9]
[1;2;3]
transforms to [1 2 3 1] [4 5 6 2] [7 8 9 3]
transforms to
[1 2 3 1] [0 -3 -6 -2] [0 0 0 0]
and this matrix results in a non real answer when it is back calculated, I need a code that identifies the row of zeros and then returns an error message instead of continuing to the nest step.

Accedi per commentare.

Risposte (1)

John D'Errico
John D'Errico il 8 Ott 2018
Time to learn MATLAB. How do you find that something is zero?
A == 0
That returns 1 where an element of A is zero. EXACTLY zero.
Next, you want to know if an entire row of the matrix is zero. What tool will tell you that? What does the all function do? So how about this?
all(A == 0,2)
That returns true for any row that is entirely zero.
How do you find which row is zero? I suppose you could use find.
So, will that work? Almost surely, certainly, positively, NOT. Why not? Because the elements you are testing will not be EXACTLY zero. So you need to learn why that happens. For example, surely this is zero:
.3 -.2 -.1
ans =
-2.77555756156289e-17
Or, not. I hope you have had some discussions about floating point arithmetic by now.
The fix is usually to test if the absolute value of the elements are less than some tolerance, NOT for exact equality with zero.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by