Question
I am trying to create an echelon function, however, I am having trouble debugging my error. It works for almost all matrices but for the following matrix it gives an incorrect result: A=[1 2 3 ; 1 2 4 ; 1 2 4] echelon(A) function x = echelon(A) [m,n]= (size(A)); % m= rows , %n= columns j=1; i=1; while( i It gives the following incorrect result: 1 2 3 0 0 1 0 0 1 Also for the following matrix: A=[1 2 3 ; 1 2 5] gives the following incorrect result: 1 2 3 0 0 2
Expert Answer
Neeta Dsouza
PhD Expert
Answered Aug 25, 2026
I haven't checked all of your code, but I assume this:
if ~all(A(k,:))==0 %check to see if row of zeros or not
was meant to be this instead:
if ~all(A(k,:)==0) %check to see if row of zeros or not
Also, you divide by A(i,j) before checking to see if it is 0.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related echelon Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →