Home > Software design >  Converges and diverges of Newton's method
Converges and diverges of Newton's method

Time:10-08

I need to find a root of arctan(x-e) using Newton method and prove that exists such "a" for which if |x-e|<a method converges and if |x-e|>a method diverges,then derive the equation to find this "a" and solve it.I wrote a programm,but don't understand how to find this "a".

#include <stdio.h>
#include <math.h>
double f(double x) ;
double fd(double x) ;
double newton(double x,double eps);
#define e 2.71828182845904523
int main() 
{
   double x,eps=1.e-16 ;
   printf("%le",newton(x,eps)) ;
   
    return 0;
}


double f(double x)
{
   double z ;
   z=atan(x-e);
   return z ; 
}

double fd(double x)
{
   double z ;
   z=1/((x-e)*(x-e) 1);
   return z ; 
}



double newton(double x,double eps)
{
  double x1 ;   
  
  while(1)
  {
    x1=x-f(x)/fd(x) ;
    if(fabs(x1-x)<eps) return x1 ; 
    x=x1 ;
  }
  
  return x1 ; 
}

CodePudding user response:

double x in C mean just avance the stack on the memory. If you don't fill it with 0's it will just take the value memory under x.

One amelioration : double x = 0 or to the value you want. It will fill the 8 words (1 word = 8 bits) to 0x00000000 in stead of some random data like 0x2409caf42 or idk what ever there is

CodePudding user response:

f(x)/df(x) minimize a function. But if you minimize the derivative you find a root f in facte.

df(x)/ddf(x).

  • if you use f(x)/df(x), the most simple way is Gradient descent : x -= 0.001*f(x)/df(x)

CodePudding user response:

double x,eps=1.e-16 ;
printf("%le",newton(x,eps)) ;

You didn't initialize x in main.

double fd(double x)
{
   return 1/((x-e)*(x-e) 1);
}

Would be better.

#include <math.h> Imports the constant M_E, so you do not need to define "e".

  • Related