%Demonstration of Newton--Raphson algorithm 
x0=1; COL=[]; 
for k=1:1:4 
    COL=[COL x0];
    y=[]; z=[];
    for x=-4:0.1:4; 
        y=[y f(x)];
        z=[z f(x0)+(x-x0)*f1(x0)+(f2(x0)*((x-x0)^2)/2)];
    end
    x=-4:0.1:4; 
    figure(1)
    subplot(2,2,k)
    plot(x,y,'b')
    hold on 
    plot(x,z,'r')
    plot(x0,f(x0),'*')
    xnext=x0-(f1(x0)/f2(x0)); 
    x0=xnext;
end
figure 
stem(COL)
