function pk=Dogleg(radius_k,df,Bk,Hk,Xk)

[V,D]=eig(Bk);

if (D(1,1)<=0 || D(2,2)<=0 || D(3,3)<=0 || D(4,4)<=0)
    alpha=-1.5*min([D(1,1),D(2,2),D(3,3),D(4,4)]);
    
    Bk=Bk+alpha*eye(length(df));
end


pt2=Xk(1,1);
pt3=Xk(2,1);
pr2=Xk(3,1);
pr3=Xk(4,1);


gk=eval(df);

Pb=-inv(Bk)*gk;

Pu=-gk.'*gk/(gk.'*Bk*gk)*gk;


if norm(Pb)<radius_k
    pk=Pb;
else if Pu>=radius_k
        tau=solve_tau(Pb,Pu,radius_k);
        pk=tau*Pu;
    else tau=solve_tau(Pb,Pu,radius_k);
        pk=Pu+(tau-1)*(Pb-Pu);
    end
end
        
        
        
        
        
        