Help with function putting a matrix into upper triangluar form.
Mostrar comentarios más antiguos
I have this function but it just is not doing what I want it to. When the function reaches to the end of the second for, it goes through that same for loop over again. How can I fix this? The Largest, swap and matCon are my own functions, they fins the row with the largest value, swap two rows and create a liner combination of the rows.
%%Converts a matrix to upper triangular form
function [upperMat]=upperTriangle(M)
rows=size(M,1);
cols=size(M,2);
for curRow=1:rows-1;
maxRow=Largest(M,curRow,curRow);
if maxRow>curRow;
M=swap(M,maxRow,curRow);
end
for workRow=curRow+1:rows
alpha=-M(workRow,curRow)/M(curRow,curRow);
M=matCon(M,curRow,workRow,alpha);
end
upperMat=M;
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!