How to get numbers as answers? Values show NaN
My function file my_rref.m is as follows:
function my_rref(A)
[m,n]=size(A);
for i=1:m-1
for j=i+1:m
if abs(A(j,i))>abs(A(i,i))
t=A(j,:);
A(j,:)=A(i,:);
A(i,:)=t;
end
end
end
for i=1:m-1
for j=i+1:m
x=A(j,i)/A(j,j);
for k=i:m+1
A(j,k)=A(j,k)-x*A(i,k);
end
end
end
for j=m:-1:2
for i=j-1:-1:1
A(i,:)=A(i,:)-A(j,:)*(A(i,j)/A(j,j));
end
end
for i=1:m
A(i,:)=A(i,:)/A(i,i);
end
disp('Rref of A is')
A
In the command prompt, when I define an example matrix A and I enter my_rref(A), the resulting matrix shows A= (matrix consisting of NaNs). How can I fix this to show the values of the Gauss-Jordan elimination product?
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.
Because you chose bad variable names, you didn’t see what was causing the error. Look at how i goes with m — they’re rows. And j goes with n — they’re columns. But when you come to index the array, you swap the rows and columns:
A(j,:)=A(i,:);
See how j is the first index, which should be the rows? But you associated j and n with columns, meaning they should come in the second place, not the first index place. This code is closer but it’s still messed up because of the other problem : no comments. So because of that I can’t figure out what you intend, but at least with proper variable names you should be able to figure it out. So dump your code and start repairing this:
function my_rref(A)
[rows, columns]=size(A);
for col=1:columns-1
for row=col+1:rows
if abs(A(row,col))>abs(A(col,col))
t=A(row,:);
A(row,:)=A(col,:);
A(col,:)=t;
end
end
end
SEE COMPLETE ANSWER CLICK THE LINK