pythonnumpyscipyscipy-optimizenonlinear-functions

Solving single non-linear equation involving sum of numpy array with fsolve


I'm trying to solve the following equation:

enter image description here

This non-linear equation comes from summing "k" other equations. Every variable is known here, except m_dot_ev^(T), so this is what I'm trying to find. I sent every term to the LHS in order to have "0" in the RHS and am currently solving via:


def non_linear_function(y):
   return sum(X_k_infty_array + (X_k_infty_array - X_k_s_array)/(np.exp(-y/(4*np.pi*rho*R_0*D_k_array))-1)) - 1

m_dot = fsolve(non_linear_function,suitable_RHS_guess)


Notice that the variable that we want has become "y" inside the function. I already have a suitable RHS_guess (essentially, the paper which published this equation proposed a more simplified version and showed that the simplified version yields results similar to this complex version. Alternatively, since I compute this result on an iterative manner, I can always use as a guess the converged m_dot obtained from fsolve for the previous iteration in time).

My questions here are: Is there a better way to feed this equation into fsolve? Is fsolve the best tool at all to solve this problem? The method I described above works for a great part of my simulation, but I currently am facing a RuntimeWarning saying no progress is being made on the iterations of fsolve at a time where nothing critical is happening , so I'm wondering if there's a better way to go about doing this. Thank you very much for your time.


Solution

  • I think your approach is good for using fsolve. But fsolve is more sophisticated, meant to be used for multivariable functions.

    You could try it with root_scalar, it let's you to choose the solution method.

    If you some information e.g. if Xoo > Xs for all k then the is split in two for y < 0 and for y > 0, and it has at most one root. In this case you could use a more predictable method as the bisection method, or some of its improved versions Brent's method or Ridder's method