%Now we will do with MATLAB what we did by hand
clear all;
close all;
f=@(x) x^3-2*x+2;
g=@(x) 3*x^2-2;
fplot(@(x) x^3-2*x+2,[-3,3])
%Since in this case we know the actual derivative, we will use it
N=-2; %we start Newton's method from here
%We decide to stop Newton's method after 10 iterations
c=1; %we use it to count the iterations
while c<=10
    N=N-f(N)/g(N);
    c=c+1;
end
disp('The approximation of the zero we got is:')
N
disp('If we plug it into the function we get:')
f(N)