MATLAB: I want to keep calculating better values of root iteratively until either the max number of iteration is used or the error is less than the tolerance and then display the values using the switch statement.i think somethin is wrong in the while loop

k=1;
e=-1*((x(k+1)-x(k))/x(k+1))*100;
while e > tol && k==x_max;
e=-1*((x(k+1)-x(k))/x(k+1))*100;
k=k+1;
end
switch e
case e< tol
disp('Success!The result is %.4f',e)
case e<0
disp('The number was negative.')
otherwise
disp('Maximum number of iteration used.')
end

Best Answer

k_max = 100; % sample value, maximum number of iterations
:
while e > tol & k <= k_max
:
Related Question