1

I'm trying to solve a system of nonlinear equations using scipy.optimize.root()

One of the equations contains a power like x[5]**epsilon, where epsilon is a parameter. For epsilon=1 I manage to find the roots, but for any different epsilon around 1, I cannot. I get NaN somewhere along the process, which I presume comes from the solver trying out negative values and getting NaN for that.

Is there any way to furthermore restrict the solver, as in telling him x[5] >= 0 or similar? I know that scipy's minimization tools can use these boundaries, but I fail to find anything like that in the documentation for root.

FooBar
  • 15,724
  • 19
  • 82
  • 171
  • A fast workaround is something like `if x[5]<0: return ones_like(x)*inf`. See my answer [here](http://stackoverflow.com/questions/23659698/tell-scipy-optimize-minimize-to-fail/23659957#23659957) – gg349 Aug 21 '14 at 14:19

1 Answers1

1

Instead of x[5]**epsilon, replace it with np.exp(x[5])**epsilon in your target function. Then x[5] can be any value between -inf and +inf and np.exp(x[5]) will always be positive.

Stay away from abs(x[5]) or similar other transformations that might make the derivative non-continuous.

CT Zhu
  • 52,648
  • 17
  • 120
  • 133