def test_NewtonRoot(self): fun = lambda x, return_g=True: np.sin(x) if not return_g else ( np.sin(x), sdiag( np.cos(x) ) ) x = np.array([np.pi-0.3, np.pi+0.1, 0]) xopt = Optimization.NewtonRoot(comments=False).root(fun,x) x_true = np.array([np.pi,np.pi,0]) print('Newton Root Finding') print('xopt: ', xopt) print('x_true: ', x_true) self.assertTrue(np.linalg.norm(xopt-x_true,2) < TOL, True)
def rootFinder(self): """Root-finding Algorithm""" if getattr(self, '_rootFinder', None) is None: self._rootFinder = Optimization.NewtonRoot( doLS=self.doNewton, maxIter=self.maxIterRootFinder, tol=self.tolRootFinder, Solver=self.Solver) return self._rootFinder
def root_finder(self): """Root-finding Algorithm""" if getattr(self, '_root_finder', None) is None: self._root_finder = Optimization.NewtonRoot( doLS=self.do_newton, maxIter=self.root_finder_max_iter, tol=self.root_finder_tol, Solver=self.Solver ) return self._root_finder