Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING MATLAB HINT Submit your m-file and a diary that shows how you tested the c

ID: 3210048 • Letter: U

Question

USING MATLAB

HINT

Submit your m-file and a diary that shows how you tested the code. Create a function csolve.m with input a matrix A and no output. The function should display the rank and the pivot and free variables of A. Test it using the matrix below. 5554 6 10 23-5 9 12 69-8 21 3 -57 Your display should be precisely the following: >> csolve(A) The rank of the coefficient matrix is 4 Pivot variables: 1 2 4 5 Free variables: 3 Tip: Use the for structure to display pivot and free variables

Explanation / Answer

%%% Matlab fuction %%%%

function csolve(A)
[m n]=size(A);
free=1:n;
R=rref(A);
for i=1:m
for j=1:n
if ( R(i,j)==1)
pivot(i)= j;
break;
end
end
end
r=rank(A);
for k=1:n
for l=1:length(pivot)
temp=0;
if(free(k)==pivot(l))
temp=1;
break;
end
end
if temp==0
fr=free(k);
end
  
end
fprintf('rank of Matrix = %d ',r);
fprintf(' pivot variable : %d ');disp(pivot);
fprintf(' Free variable : %d ',fr);


end

%%% test programme

A=[5 5 5 4 6;1 0 2 3 -5;9 12 6 9 -8;2 1 3 -5 7];
csolve(A)

OUTPUT

rank of Matrix = 4
pivot variable : 1 2 4 5

Free variable : 3