f=inline('1-1/3*x^2','x');
df=inline('-2/3*x','x');
x0=0.2;
eps=1e-8;
for i=1:100
	x1=f(x0);
	if abs(x1-x0)<eps, break, end;
	x0=x1;
end;
printf('iter=%0.d, x=%0.8f, df(x)=%0.8f\n\n',i,x0,df(x0));

f=inline('1-x^2','x');
df=inline('-2*x','x');
x0=0.5;
eps=1e-8;
for i=1:10
        x1=f(x0);
        if abs(x1-x0)<eps, break, end;
        x0=x1;
	printf('x%0d=%0.8f, f(x)=%0.8f\n',i,x0,f(x0));
end;


x0=0.2; x1=0.6; eps=1e-8;
for i=1:10
	x2=x1-(f(x1)-x1)*(x1-x0)/(f(x1)-x1-f(x0)+x0);
	if abs(x1-x2)<eps, break; end;
	x0=x1; x1=x2; 
end;
printf('iter=%0d, x=%0.8f, df(x)=%0.8f\n\n',i,x2,df(x2))

f=inline('x^3-2*x+1/2','x');
df=inline('3*x^2-2','x');
x0=-0.5; eps=1e-8;
for i=1:10
        x1=x0-f(x0)/df(x0);
        if abs(x1-x0)<eps, break; end;
        x0=x1;
end;
printf('iter=%0.d, x=%0.8f\n\n',i,x1)



f=inline('[x^2+y^2-4;1/3*(x-1)^2-1/2-y]','x','y');
df=inline('[2*x,2*y;2/3*(x-1),-1]','x','y');
x0=[-1;0]; eps=1e-8;
for i=1:100
       x1=x0-df(x0(1),x0(2))\f(x0(1),x0(2));
       if abs(x1-x0)<eps, break, end;
       x0=x1;
       printf('x=%0.8f,y=%0.8f\n',x1);
end;

x0=[2;0]; eps=1e-8;
for i=1:100
       x1=x0-df(x0(1),x0(2))\f(x0(1),x0(2));
       if abs(x1-x0)<eps, break, end;
       x0=x1;
       printf('x=%0.8f,y=%0.8f\n',x1);
end;

