function d1 = pivot(d0,in,out)
% Perform a pivot of a given dictionary d0, yielding d1,
% by putting x_j (j-th non-basic variable in d0) into the basis
% and removing x_i (i-th basic variable in d0).
% Inputs:
% d0: a matrix (m+1)*(n+1)
% in: local index, 1 <= in <= n, of entering variable
% out: local index, 1 <= out <= m, of leaving variable
% Outputs:
% d1: new dictionary, matrix (m+1)*(n+1).
%
% Author: Michael Floater
% e-mail: michaelf@math.uio.no
% Created: 03 February 2020, using Matlab R2019b
% Modified: 05 March 2020.
% Copyright 2020

r = out+1;
s = in+1;
d1      = d0 - d0(:,s) * d0(r,:) / d0(r,s);
d1(:,s) = d0(:,s) / d0(r,s);
d1(r,:) = - d0(r,:) / d0(r,s);
d1(r,s) = 1 / d0(r,s);

