f=inline('x.^3-2*x-1/2','x')
a=-1; b=1;
c= (a+b)/2;
it=c;
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b));
b=c;
c= (a+b)/2; 
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b))
a=c;
c=(a+b)/2;
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b))
b=c;
c=(a+b)/2;
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b))
a=c;
c=(a+b)/2;
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b))
a=c;
c=(a+b)/2;
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b))
a=c;
c=(a+b)/2;
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b))
a=c;
c=(a+b)/2;
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b))
printf('%5.2f\n',it)

a=-1; b=1;
for i=1:10
	c= (a+b)/2;
	it=c;
	printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',...
	f(a), f(c), f(b));
	if f(a)*f(c)<0 
		b=c;
	else
		a=c;
	end;
end;
c
%====================================================================
df=inline('a-f(a)*(b-a)/(f(b)-f(a))','a','b');
a=-1; b=1;
c=df(a,b);
it=(c);
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b));

a=c;
c=df(a,b);
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b));

b=c;
c=df(a,b);
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b));

a=c;
c=df(a,b);
it=[it,c];
printf('f(a)=%5.2f, \t f(c)=%5.2f, \t f(b)=%5.2f\n',f(a), f(c), f(b));


printf('%0.5f\n',it);
%======================================================================

a=-1; b=1;
it=[];
for i=1:10
	c=df(a,b);
	it=[it,c];
	a=b;
	b=c;
	if abs(f(b)-f(a))<1e-3, break,  end;	
end; 	
it
printf('i=%d c=%0.5f\n',i,c);


a=-1; b=1;
it=[];
for i=1:5
        c=df(a,b);
	it=[it,c];
	if f(a)*f(c)<0
		b=c;
	else 
		a=c;
        end;
end;

it
