function [delD delw]=cidDw(cr,di,D,w)  

A=zeros(2,2);

rp=cr-D/2;
tanh1=tanh(rp*w);
sech2=sech(rp*w).^2;

dipD=w.*sech2/4;
dipw=-rp/2.*sech2;
dipDD=w^2/4*tanh1.*sech2;
dipww=rp.^2.*tanh1.*sech2;
dipDw=sech2.*(1-2*w*rp.*tanh1)/4;

chiD=di.*dipD;
chiw=di.*dipw;
chiDD=dipD.^2+di.*dipDD;
chiww=dipw.^2+di.*dipww;
chiDw=dipD.*dipw+di.*dipDw;

b=[sum(chiD(:)) sum(chiw(:))];
A(1,1)=sum(chiDD(:));
A(1,2)=sum(chiDw(:));
A(2,1)=A(1,2);
A(2,2)=sum(chiww(:));
delDw=-b*pinv(A);
delD=delDw(1);
delw=delDw(2);
