Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. bool newton(FuncPointer f, double* x, double* Df){
  2.     double y[2];
  3.     while(true){
  4.         f(x, y, Df);
  5.         if(fabs(y[0]) > 1e-14 || fabs(y[1]) > 1e-14){
  6.             double g = (Df[0]*Df[4]) - (Df[1] * Df[3]);
  7.             double new_x1 = (-Df[4] / g * y[0]) + (Df[1] / g * y[1]);
  8.             double new_x2 = (Df[3] / g * y[0]) + (-Df[0] /g * y[1]);
  9.             x[0] = x[0] + new_x1;
  10.             x[1] = x[1] + new_x2;
  11.             if(fabs(y[0] - y[1]) > 10)
  12.                 return false;
  13.         }
  14.         else
  15.             return true;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement