function x=vweg2(v1,g,tmin,tmax,nmax,erc)
% vweg2: vector solution of n equations in n unknowns using Wegstein's method
% function x=vweg2(v1,g,tmin,tmax,nmax,erc)
% Vector solution of n equations in n unknowns using the Wegstein method
%	of finding roots
% Use VWEG1 to do each Wegstein step
% Argument    Gives
%    g     a character vector naming a function that tells how to 
%          find a better value for the unknown 
%          vector x given an approximate set: v1.
%          The vector must be called x in g.
%    v1    the initial guess for x.
%   tmin   min allowed change in a step. 
%   tmax   max allowed change in a step.
%   nmax   max iterations allowed.
%   erc    desired error.
% Typical (default) values are: nmax=10, erc=.001, 
%   tmax=5 and tmin=-10
% You may give the function 2, 4 or 6 arguments.
% If you give it only two, the default values are used 
%   for the rest.
% If you give it 4, the default values for nmax and erc 
%   will be used.
% Example: >> vweg2(zeros(1,7),'g312(x)',-10,5,10,0.001)
% revised help by TYLC

if nargin<=4
   nmax=10;
   erc=.001;
   if nargin<=2
      tmin=-10;
      tmax=5;
   end
end
x=v1;
v2=eval(g);
for k=1:nmax
   x=vweg1(v1,v2,g,tmin,tmax);
   if max(abs(x-v2))<erc
      return
   end
   v1=v2;
   v2=x;
end
disp('vweg2 did not converge')
prntmx('v1 and v2',[v1;v2],10,4)
