MATLAB: Error running the code in while command in bisection method

bisection methodMATLAB

umerfunction='x.^3';
x_lower=0;
x_upper=1;
x_mid=(x_lower+x_upper)/2;
i=0;
while(abs(umerfunction(x_mid))>0.0001)
fx=umerfunction(x_mid);
X=[i,fx,x_upper,x_lower];
disp X;
if(umerfunction(x_mid)*umerfunction(x_upper))<0
x_lower=x_mid;
else x_upper=x_mid;
end
ERROR:
Array indices must be positive integers or logical values.
Error in bisection (line 7)
while(abs(umerfunction(x_mid))>0.0001)
how to solve that issue? i m very frustated now regarding solving this.Thanks and honours in advance

Best Answer

umerfunction=@(x)x.^3;
Note: Also your loop is infinite loop since each time the condition will be satisfied either you need to add a break or change the condition.