                                                                     
                                                                     
                                                                     
                                             
function m = corners(A,b,c)
## function c = corners (A,b,c) is a function which given a matrix A and
## vectors b and c calculates all the corner points of the constraints of the
## associated LP: Ax \leq b, x\geq 0, and output the corresponding objective function
## value.

[m,n] = size(A);

if m != length(b) 
	error("The sizes of the given inputs A and b does not mathc. \n")
endif
if n != length(c) 
	error("The sizes of the given inputs A and c does not mathc. \n")
endif

fprintf("The corner points are given by: \n")
cornershelpfunction([A eye(m)],[b zeros(1,n)],c,eye(m+n),1);

endfunction

function v = cornershelpfunction(At,bex,c,T,counter)

[me,ne] = size(At);
if me == ne 
  temp = At \ (bex');

  for i=1:length(c)
    fprintf("x%d = %f\t",i,temp(i));
  endfor

  for i=1:me -length(c)
    fprintf("s%d = %f\t",i,temp(length(c)+i));
  endfor

  fprintf("z = %f \n",(c)*temp(1:length(c)));
else
  for j = counter:me+1
    An = [At;T(j,:)];
    cornershelpfunction(An,bex,c,T,j+1);
  endfor
endif



function v = cornershelpfunction(At,bex,c,T,counter)
v=0;
[me,ne] = size(At);
if me == ne 
  temp = At \ (bex');

  for i=1:length(c)
    fprintf("x%d = %f\t",i,temp(i));
  endfor

  for i=1:me -length(c)
    fprintf("s%d = %f\t",i,temp(length(c)+i));
  endfor

  fprintf("z = %f \n",(c)*temp(1:length(c)));
else
  for j = counter:me+1
    An = [At;T(j,:)];
    cornershelpfunction(An,bex,c,T,j+1);
  endfor
endif

endfunction
