function r=pderesid(time,u);
%PDERESID Residual for nonlinear solver

%       M. Dorobantu 1-17-95.
%       Copyright (c) 1994-95 The MathWorks, Inc.
%       $Revision: 1.6.1.1 $  $Date: 1995/08/25 15:34:43 $

global pdenonb pdenonp pdenone pdenont pdenonc pdenona pdenonf pdenonn
global  pdenonK pdenonF
  u=full(u);
  [cc,aa,ff]=pdetxpd(pdenonp,pdenont,u(1:pdenonn),pdenonc,pdenona,pdenonf);
  [K,M,F,Q,G,H,R]=assempde(pdenonb,pdenonp,pdenone,pdenont,cc,aa,ff,u(1:pdenonn));
  pdenonK=K+M+Q;pdenonF=F+G;
  if any(any(H))
    if size(u,1)<(size(pdenonK,2)+size(H,1))
      if isieee
        u=[u;H'\(pdenonF-pdenonK*u)];
      else
        u=[u;pdebs(H',(pdenonF-pdenonK*u))];
      end
    end
    pdenonK=[pdenonK H';H zeros(size(H,1))];
    pdenonF=[pdenonF;R];
  end
  r=pdenonK*u-pdenonF;
end;
