Help with function putting a matrix into upper triangluar form.
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!