I wrote a code which finds roots using the bisection method but the problem is its just showing up my answer as zero so if you are willing to help me I am very happy.
first_function = @ (x) cos(x)-2*x;x_upper = 4;x_lower = -5;x_mid = (x_lower + x_upper)/2;i=0;while abs(x_mid) > 10^-8 if (first_function(x_mid))*(first_function(x_lower))<0 x_lower=x_mid; else x_upper = x_mid; end x_mid = (x_lower + x_upper)/2; i=i+1;endfprintf('The root is %g and the number of iteration is %g\n ', x_mid,i)
Best Answer