Why is my own echelon function printing incorrect matrix

Technical Source
2 min readMar 17, 2023

--

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

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet