MATLAB: The while loop is breaking down, what is wrong

while loop

t4 = 95;
x0 = [60;45];
r1 = 10;
r2 = 6;
r3 = 8;
r4 = 10;
A = [r2*sind(x0(1)) r3*sind(x0(2)); -r2*cosd(x0(1)) -r3*cosd(x0(1))];
fx0 = [(r1+r4*cosd(t4)-r3*cosd(x0(2))-r2*cosd(x0(1))); (r4*sind(t4)-r3*sind(x0(2))-r2*sind(x0(1)))];
x = -A\fx0 + x0;
diff = x0-x;
while diff(1) < .0001
x0 = x;
A = [r2*sind(x0(1)) r3*sind(x0(2)); -r2*cosd(x0(1)) -r3*cosd(x0(1))];
fx0 = [(r1+r4*cosd(t4)-r3*cosd(x0(2))-r2*cosd(x0(1))); (r4*sind(t4)-r3*sind(x0(2))-r2*sind(x0(1)))];
x = -A\fx0 + x0
diff = x0-x
end
The loop I have is working until a certain point, until diff(1) = .0024, once it hits that though it will not go on. I have tried to increase the tolerance, but it doesn't work. I can't tell what is wrong.

Best Answer

If diff(1) = .0024, then the while loop condition is violated so, naturally, it will not go on.