[Tutor] Python execution timer/proficiency testing (Dino Bektešević)

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Aug 28 02:38:15 CEST 2013


On 27 August 2013 15:05, Dino Bektešević <ljetibo at gmail.com> wrote:
> Thank you both I did not know it quits(!) but since my further code
> never reported an error I assume it returned something similar to
> initial guess?
> I will add a test of the returned variable ier and try to find another
> initial guess or handle it somehow else.
> Under 'Narrow-field astrometry' are the equations I'm solving and
> here's the code snippet:
>
>
> row_guess = ( mudiff*fd['f'] - fd['c']*nudiff )/det
> col_guess = ( fd['b']*nudiff - mudiff*fd['e'] )/det
>
> row=zeros(mu.size,dtype='f8')
> col=zeros(mu.size,dtype='f8')
> for i in xrange(mu.size):
>     self._tmp_color=color[i]
>
>     self._tmp_munu=array([mu[i],nu[i]])
>
>     rowcol_guess=array([row_guess[i], col_guess[i]])
>
>     rowcol = scipy.optimize.fsolve(self._pix2munu_for_fit, rowcol_guess)

Eryksun guessed that fsolve was the source of the message. If the line
above emits the warning you mentioned then the output most likely is
not a solution to the equations. As Eryksun said it could be that your
initial guess isn't good or it could be that there is no solution.
Another possibility is that you're just not working with a very
well-behaved function: there are solutions but the solver wouldn't
find them no matter how good your initial guess. In any case while it
continues to emit that warning message you cannot trust the results it
returns.

Try passing full_output=True to get more information e.g.:

x, infodict, ier, msg = scipy.optimize.fsolve(..., full_output=True)

Then have a look at the infodict, ier and msg variables to see if they
tell you more about what happened:
http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html


Oscar


More information about the Tutor mailing list