%% Function pivot( M, r, c) 
%%
%% By: Michael K. Pellegrino
%%
%% input: M = any KxN matrix, r = pivot row, c = pivot column
%% output: ret = the pivoted matrix
%%

function [ret] = pivot( M, r, c )
  format rat;
  [nrow,ncol]=size( M );
  if(( r > nrow ) || (c > ncol))
    disp( "[error] dimension out of range" );
    return;
  endif

  %% Flatten out the Pivot row First
  M(r,:)=M(r,:)/M(r,c);

  for i=1:nrow
    if( i != r )
      M(i,:)=M(i,:)-M(i,c)*M(r,:);
    endif
  endfor
  ret=M;
endfunction
