clear, clc, close all f=@(x)x.^3-2*x.^2+1; a=-1;b=0;N=7; xx=linspace(a,b); fa=f(a); fb=f(b); for n=1:N figure(1) clf hold on plot(xx,f(xx)) plot([-1 0],[0,0],'k-') set(gca,'XTick',[],'YTick',[]) box on title('Biseccion','Fontsize',16,'Fontweight','b') plot([a a],[0 f(a)],'r-',... [b b],[0 f(b)],'r-',... [a b],[0 0],'r-',... 'linewidth',3) pause x=(a+b)/2; fx=f(x); if fx==0 return elseif fa*fx < 0 b=x; else a=x; end plot([x x],[0 f(x)],'b-','linewidth',3) text(x+0.01,0.1,['x_',num2str(n)],'Fontsize',16,'Fontweight','b') pause end