(* Computing the "exact value" of the solution of sin(x)+x=1 ; you have to run this part to initialize the variable exactvalue used later for comparison. BE PATIENT, OBTAINING exactvalue MAY TAKE A WHILE! *) p=N[1,10000]; f[x_] := Sin[x]+x-1; For[i=1, i<=20, i++, { p=p-f[p]/f'[p], }] exactvalue=p; Print[N[exactvalue,50]] (* Newton's method for computing the solution of sin(x)+x=1 *) p=N[1,10000]; f[x_] := Sin[x]+x-1; For[i=1, i<=13, i++, { p=p-f[p]/f'[p], error = Abs[p - exactvalue], Print[i," ",Log[1.0*error]] } ] (* Secant method for computing the solution of sin(x)+x=1 *) p0=N[0,10000]; p1 = N[1,10000]; f[x_] := Sin[x]+x-1; For[i=1, i<=16, i++, {p=p1-f[p1]*(p1-p0)/(f[p1]-f[p0]), error = Abs[p - exactvalue], Print[i," ",Log[1.0*error]], p0 = p1, p1 = p } ] (* Fixed point iteration for computing the solution of sin(x)+x=1 *) p=N[1,10000]; g[x_] := 1-Sin[x]; For[i=1, i<=50, i++, {p=g[p], error = Abs[p - exactvalue], Print[i," ",Log[1.0*error]] } ] (* Aitken's extrapolation for iterative solution of sin(x)+x=1 *) p=N[1,10000]; g[x_] := 1-Sin[x]; p1 = g[p]; p2=g[p1]; For[i=1, i<=50, i++, {pa=p-(p1-p)^2/(p2-2*p1+p), error=Abs[pa-exactvalue], Print[i," ",Log[1.0*error]], p=p1, p1=p2, p2=g[p1], } ] (* Steffensen's method for iterative solution of sin(x)+x=1 *) p=N[1,10000]; g[x_] := 1-Sin[x]; For[i=1, i<=12, i++, {p1 = g[p]; p2=g[p1]; pa=p-(p1-p)^2/(p2-2*p1+p), error=Abs[pa-exactvalue], Print[i," ",Log[1.0*error]], p=pa; } ]