function [D,beta]=FrDelete(D,beta,num,ic);
% FrDelete  deletes the requested vector from a given frame 
%
% It appropriately modifies the corresponding  duals "beta", the updating 
% depends on whether the vector "num" belongs to the remaining frame or not
%  
% Usage: [D,beta]=nfrdelete(D,beta,num);
% Usage: [D,beta]=nfrdelete(D,beta,num,ic);
%
% Inputs:
%   D    frame
%   beta dual frame
%   num  index of  the vector to be eliminated  
%   ic = 1 if linearly independent  (linearly dependent otherwise)
%  
% Outputs:
%   D    reduced  frame  
%   beta updated  dual frame (for the reduced D)
% 
% References:
%  L. Rebollo-Neira, ``Constructive updating/downdating of oblique projectors: a generalization of the Gram-Schmidt process'', Journal of Physics A: Mathematical and Theoretical,
%Vol(40), 6381-6394 (2007).
%
% See http://www.ncrg.aston.ac.uk/Projects/HNLApprox/ for more details
  
name='FrDelete';  
[N,k]=size(D);
% simple tests of input data
if  any([N,k]~=size(beta))
  error('%s: Bad size of input matrices',name);
end
if (num<1) | (num>k)
  fprintf('%s: Required index %d is out of range (%d atoms)\n',name,num,k);
  return;
end  

tol=1e-7;%tolerance for independence
b=beta(:,num);
al=D(:,num);
beta(:,num)=[];
detest=1-D(:,num)'*b;
%
ic=1;
if abs(detest)>tol ic=0;end %works fine eliminating the 
%vector num from the frame
D(:,num)=[];
%updating if the vector is independent
if ic == 1 
 nor=b'*b;
 beta=beta-b*(b'*beta)/nor;
 fprintf('\n deleted atom %d was independent. \n',num );
%eliminating the atom from the frame
else 
  beta=beta+b*(al'*beta)/detest;
  fprintf('\n deleted atom %d was dependent. \n',num );
end 

%Laura REBOLLO-NEIRA  (2008) 
