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

%       M. Dorobantu 1-17-95.
%       Copyright (c) 1994-98 by The MathWorks, Inc.
%       $Revision: 1.6 $  $Date: 1997/11/25 17:06:20 $

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;

