How to increase the accuracy of numerical results using mathematica

89 Views Asked by At

I'm solving nonlinear equations using Newton-type methods with very high accuracy using Mathematica. I found many research papers in which the numerical results are calculated with very high accuracy. e.g. To solve the equation $e^{−x}+\sin(x)−2=0$ with initial guess $x_0=−1.$ Many authors evaluated its functional value after some iterations up to $a*10^{−300}$, where $a$ is any real number, and even less than this. But with the same function and same initial guess, I could not get the functional value better than $a*10^{−16}$. Why? Is there any special coding to increase the accuracy of the result. Actually, I'm using the following Mathematica codes instead of using FindRoot, so that I can use the same technique to other methods of the Newton type.

f[x_]:=e^{-x}+\sin(x)-2;
x0=-1.;
Do[x1=x0-(f[x0]/f'[x0]);(* Newton method N *)
   x0=x1;
   Print[k," "," ",Abs[f[x0]]
     ],{k,8}]  

It gives following results:
1 0.7259613253822197 2 0.08810177540236008 3 0.0022194882771988667 4 1.5508534114694328*10^-6 5 7.593925488436071*10^-13 6 3.3306690738754696*10^-16 7 4.440892098500626*10^-16 8 3.3306690738754696*10^-16 As you can see after 6th iterations exponent of 10 doesnot improve.

1

There are 1 best solutions below

2
On

Trying to mimic with another CAS, what you are doing and hoping I use a correct Mathematica syntax ; what I did is

  prec=100;
  f[x_]:= Exp[-x] + Sin[x]-2;
  df[x_] = D[f[x],x];
  g[x_]:= x-f[x]/df[x];
  x0=-1;
  s[0] = x0;
  s[1] = N[g[x0], prec];
  s[i_] := g[s[i - 1]];
  data = Table[{i, N[s[i], 45], N[Log[10, Abs[f[s[i]]]]]}, {i, 0, 7}]

and obtained the following results

$$\left( \begin{array}{ccc} \text{i} & \text{s[i]} & \text{ N[Log[10, Abs[f[s[i]]]]]} \\ 0 & -1.00000000000000000000000000000000000000000000 & -0.90943 \\ 1 & -1.05656120963079878784044888191686086878641816 & -2.23708 \\ 2 & -1.05413177576810737317426556858570255395403143 & -4.95664 \\ 3 & -1.05412712410824168350388693106791890302826931 & -10.3931 \\ 4 & -1.05412712409121289976707252047224730736443764 & -21.2659 \\ 5 & -1.05412712409121289976684431094237661076530228 & -43.0116 \\ 6 & -1.05412712409121289976684431094237661076530224 & -86.5030 \\ 7 & -1.05412712409121289976684431094237661076530224 & \text{Indeterminate} \end{array} \right)$$