x = 0.5;  % initial estimate
xerr = x;  % initial error value
q = 0.3; r = 0.9; s = 12.;
while 1
    fx = 1./((x-q)^2+0.01) + 1./((x-r)^2+0.04)-s;
    fpx = 2*(q-x)/((x-q)^2+0.01)^2 + 2*(r-x)/((x-r)^2+0.04)^2;
    xnew = x - fx/fpx;
    xerr = xnew - x;
    if abs(xerr) < 1.e-7 ; break ; end
    x = xnew;
end
disp(x)

