![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhisL11iHdH7IVwHUukv2SZUcjSob4Y2JYoE-slojQFvoFrXE44tgOQdAg2noA3kN6dXOBlkvq6HaqFxjYwGn5smOY5kgKc-Ulke5gTvjwNC68DLGxFm7xC-IXhdjBQUwIerGY6ETqx0oI/s200/fntpackcover.png)
Directly mathematica program code is given here.
Clear["`*"]; f[x_] := 1 - x Exp[x]; Plot[f[x],{x,-5,5}]; x0 = Input["Enter x0"]; tol = Input["Enter tolerance"]; n = Input["Enter total iteration"]; a = x0; g[x_] := Exp[-x]; Do[ If[Abs[g'[x0]]>1, {Print["The method is divergence"] Exit[]}]; x0 = g[a]; Print[i, PaddedForm[N[x0],{10,6}]]; If[Abs[a-x0]<tol, {Print["The solution is: ", N[x0]], Exit[]}]; a = x0; ,{i,1,n}]; Print["Maximum iteration failed"];
When you run it by mathematica, you will find the following graphics.
Graphically the root is near 0.5. So we will input
x0 = 1
tol = 0.001
n = 25
The result will be displayed then.