scipy minimization/optimization of simple function
<p>I'm having trouble optimizing a very simple function I'm using as a test case before moving on to something more complex. I've tried different optimization methods, giving the method a bound and even giving the exact solution as the initial guess.</p>

<p>Function I'm trying to optimize: <code>f(x) = 1 / x - x</code></p>

<p>Here is my code:</p>

<pre><code>import scipy
def testfun(x): return (1 / x - x) 

sol = scipy.optimize.minimize(testfun, 1).x
</code></pre>

<p>it returns large numbers (3.2 e+08) as the solution</p>

<p>Am I using the optimization function incorrectly?</p>

<p>As Victor mentioned, the optimization function is working correctly,</p>

<p>I was looking to solve <code>f(x) --&gt; 0</code> which requires a root finding method rather than an optimization routine.</p>

<p>for example: </p>

<p><code>scipy.optimize.root(testfun, 1)</code> or <code>scipy.optimize.Newton(testfun, 1)</code></p>

python optimization