I have a function that I want to solve using newton's method. The problem is that the convergence depends on the initial guess. I want to write an if statement. If the function converges then to store the variable, but if didn't converge I want to change the initial statement. The initial statements will be a priori stored in a list.
for i in range(len(initial_guess)):
t_end = newton(self.ray_param_eq, initial_guess[i],
fprime=self.ray_param_eq_prime,
fprime2=self.ray_param_eq_second_prime,
args=(self.c, self.k, ray.z_0, ray.y_0, ray.theta, self.A, self.B),
maxiter=100, tol=1.48e-5, disp=False)
if t_end is not None: break
if t_end is None: continue
initil_guess = the list with the initial guess variables
The code above didn't raise an error, but I do not know if it works or not.