Ex 2.1

clear
x = -3:0.1:1;
y = x.^3 + 3*x.^2 - 3;
plot(x,y);

x0 = [-2.5,-1.5,1];
tol = 1e-3;
err = 1;

disp('      a1      a2      a3      korr1       korr2       korr3');
while err > tol
    x1 = x0 - (x0.^3 + 3*x0.^2 - 3)./(3*x0.^2 + 6*x0);
    err = abs(x1 - x0);
    disp([x1,err]);
    x0 = x1;
end
      a1      a2      a3      korr1       korr2       korr3
   -2.5333   -1.3333    0.8889    0.0333    0.1667    0.1111

   -2.5321   -1.3472    0.8795    0.0012    0.0139    0.0094

   -2.5321   -1.3473    0.8794    0.0000    0.0001    0.0001