Hi Akhil,
To find out the values x,y and w such that value of f and g becomes equal, you can break the loop once the desired condition is hit. This can be done by adding a "if" block inside the for loop as shown below:
for i = 1:numel(a)
r1 = reg1(i);
r2 = reg2(i);
f = (((sqrt((x(r1)-a(i)) + (y(r1)-b(i))))./(sqrt((x(r2)-a(i)) + (y(r2)-b(i))))) );
g=w(r1)*w(r2);
if f == g % if block, to check if f and g are equal
%storing the optimal values of x, y and w corresponding to "r1" and
%"r2"
xOptim1 = x(r1);
xOptim2 = x(r2);
yOptim1 = y(r1);
yOptim2 = y(r2);
wOptim1 = w(r1);
wOptim2 = w(r2);
break; %break out of the loop with the stored values.
end
end
Hope this helps!