You have two mistakes
1. while loop should work with a scalar condition, but as far as I know if you use a logical vector it will only enter the loop if all values are true:
while true
disp(rand(1));
end
while false
disp(rand(1));
end
while [true true]
disp(rand(1));
end
while [false true]
disp(rand(1));
end
while [true false]
disp(rand(1));
end
So when you declared x as a vector 1x50 you booby trapped your loop. just initialize x to the x_0 value
2. In your loop condition you checked if the value is smaller than the tolerance value instead of larger, so naturally it will never enter the loop unless by luck you started from zero:
while abs(f(x)) > epsilon T
4 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983018
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983018
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983030
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983030
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983072
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983072
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983078
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/583394-while-loop-isn-t-working#comment_983078
Sign in to comment.