hello everyone, kindly help me to how to join all points with line.. here is my code.
function bisectionfunc=@(n) 40*n^1.5-875*n+35000;maxit=50;es=0.0001;xl=50;xu=100;test = func(xl)*func(xu);if test>0,error('no sign change'),endmp = linspace(xl,xu);fp = 40*mp.^1.5-875*mp+35000;iter = 0; xr = xl; ea = 100;fprintf('at iteration %2i\nxl = %2i\nxu = %2i\n ', 0, xl,xu)fprintf(' iteration xl xu xr f(x) ea')while (1)% plot(iter,ea,'-*');axis ([0 20 -5 16])
xrold = xr;xr = (xl + xu)/2;hold onplot(iter,ea,'r.-','markersize',20); axis([0 20 -5 40])iter = iter + 1;if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;endtest = func(xl)*func(xr);if test < 0xu = xr;elseif test > 0xl = xr;elseea = 0;endif ea <= es | iter >= maxit,break,end fprintf('\n%10i %14.4f %10.4f %10.3f %10.3f %9.3f', iter,xl,xu,xr,func(xr),ea)end fprintf('\n\nRoot is %7.3f after %2i iterations. \n\n', xr, iter)root = xr; fx = func(xr);fprintf('\nerror is = %17f\ntrue root=%17.4f\niteretions taken= %10.4f\n F(n)=%20.4f\n',ea,xr,iter,func(xr));end
Best Answer