%To find the one real root of x^3+3*x+1=0, using Newton's method.
%Start with an initial guess x0=0.
x0=0
%update x0
x1=x0-(x0^3+3*x0+1)/(3*x0^2+3)
%update x1
x2=x1-(x1^3+3*x1+1)/(3*x1^2+3)
%update x2
x3=x2-(x2^3+3*x2+1)/(3*x2^2+3)
%update x3
x4=x3-(x3^3+3*x3+1)/(3*x3^2+3)
%Notice x2, x3, and x4 are the same. Newton's method
%has converged; the answer is x=-0.3222