Matrix problem, iterative matrix calculation

Hello my matrix problem?? I tried it in week. But no success!
Here is the matrix
A=[-1,-1,0,0,0;0,0,0,-1,0;0,1,-1,0,-1;0,0,1,0,0;1,0,0,1,1]
Every column has only one 1, one -1 and i have to add them with whole row. Then that column will be 0. It is the first step.. Result must be like that A matrix must be changed A=[-1,-1,0,0,0;0,0,0,-1,0;0,1,0,0,-1;0,0,0,0,0;1,0,0,1,1] 4th row added to the 3rd row. and 4th elements changed 0
Then that operation will be continued until all row changed 0. I think if i write iterate Code, it will be more easier. But failed, some help!
I couldn't write a CODE. How can i write CODE. Please tell me a CODE or structure...

1 comentario

David Sanchez
David Sanchez el 6 de Jun. de 2013
your explanation is not clear, could you please rewrite your question in a way it be clearer?

Iniciar sesión para comentar.

Respuestas (1)

Iain
Iain el 6 de Jun. de 2013
Editada: Iain el 6 de Jun. de 2013
I think you are asking how to make your entire matrix zero, by adding columns of data that already exist.
while any(A) & ~some error
for i = 1:size(A,2) % each column
col = A(:,i);
[plus indp] = max(col);
[nega indn] = min(col);
if ~(nega => 0 || plus =< 0 )
A(row_no,:) = A(indp,:) - A(indn,:)*plus/nega;
end
end
some error = some check for infinite loops etc.
end

4 comentarios

Light
Light el 6 de Jun. de 2013
Yeah u r right. I wanna make entire matrix zero. Sorry for my bad knowledge.. With that code following error message appeared. That code belong my matrix A? isn't it?
if ~(nega => 0 plus =< 0 ) | Error: The expression to the left of the equals sign is not a valid target for an assignment.
>=, and <= instead of => and =<, I always get them mixed up.
A=[-1,-1,0,0,0;0,0,0,-1,0;0,1,-1,0,-1;0,0,1,0,0;1,0,0,1,1];
while any(A) & ~ some error
for i = 1:size(A,2) % each column
col = A(:,i);
[plus indp] = max(col);
[nega indn] = min(col);
if ~(nega >= 0 || plus <= 0 )
A(row_no,:) = A(indp,:) - A(indn,:)*plus/nega;
end
end
some error = some check for infinite loops etc.
end
Undefined function or variable 'some'.
:-(
"some error" is psuedocode - you should use it to prevent infinite loops, or any other errors that might arise.
If your sole aim is to set that matrix equal to zero by the simplest means possible, you can simply:
A(:) = 0;

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Jun. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by