www.pudn.com > AM_EPR.zip > Newton.m, change:2005-10-19,size:1818b


function [z,iter]=Newton(d,sgn,phigrad,dev2phi,invphigrad,beta,alpha) 
h1=funH(d(1),d,sgn,phigrad,beta,alpha); 
h2=funH(d(2),d,sgn,phigrad,beta,alpha); 
h3=funH(d(3),d,sgn,phigrad,beta,alpha); 
h4=funH(d(4),d,sgn,phigrad,beta,alpha); 
if h1==0 
    z=d(1); 
    return; 
elseif h2==0 
    z=d(2); 
    return; 
elseif h3==0 
    z=d(3); 
    return; 
elseif h4==0 
    z=d(4); 
    return; 
end 
if h1>0 
    z=d(1)-feval(invphigrad,h1/(4*beta),alpha); 
elseif h1*h2<0 
    d12=(d(1)+d(2))/2; 
    h12=funH(d12,d,sgn,phigrad,beta,alpha); 
    if h12<0 
        z=d(2)-feval(invphigrad,h2/(4*beta),alpha); 
    elseif h12>0 
        z=d(1)+feval(invphigrad,-h1/(4*beta),alpha); 
    else 
        z=d12; 
        return; 
    end 
elseif h2*h3<0 
    d23=(d(2)+d(3))/2; 
    h23=funH(d23,d,sgn,phigrad,beta,alpha); 
    if h23<0 
        z=d(3)-feval(invphigrad,h3/(4*beta),alpha); 
    elseif h23>0 
        z=d(2)+feval(invphigrad,-h2/(4*beta),alpha); 
    else 
        z=d23; 
        return; 
    end 
elseif h3*h4<0 
    d34=(d(3)+d(4))/2; 
    h34=funH(d34,d,sgn,phigrad,beta,alpha); 
     if h34<0 
        z=d(4)-feval(invphigrad,h4/(4*beta),alpha); 
    elseif h34>0 
        z=d(3)+feval(invphigrad,-h3/(4*beta),alpha); 
    else 
        z=d34; 
        return; 
    end 
elseif h4<0 
    z=d(4)+feval(invphigrad,-h4/(4*beta),alpha); 
end     
 
iter=0; 
grad=funH(z,d,sgn,phigrad,beta,alpha); 
diff=1; 
 
while diff>5e-4 & abs(grad)>5e-4 & iter<500 
    zz=z-grad/devH(z,d,beta,dev2phi,alpha); 
    grad=funH(zz,d,sgn,phigrad,beta,alpha); 
    diff=abs(zz-z)/abs(z); 
    z=zz; 
    iter=iter+1; 
end 
 
%options=optimset('LargeScale','off','gradobj','on','display','off','linesearchtype','cubicpoly'); 
%[z,f,e,output]=fminunc(@fun,z,options,d1,d2,d3,d4,sgn,beta,phi,phigrad,alpha); 
%k=output.iterations;