Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:02:47+00:00 2026-06-15T07:02:47+00:00

Scipy version 0.10.0 Consider the following: >>> import math >>> from scipy.optimize import fsolve

  • 0

Scipy version 0.10.0

Consider the following:

>>> import math
>>> from scipy.optimize import fsolve
>>> import numpy as np
>>> def p(s, l, k, q):
    p = q * np.maximum(s - k, 0.0)
    return (p + math.copysign(l, -q)) * math.fabs(q) * 100.0

>>> x0 = fsolve(p, np.arange(33.86, 50.86, 1.0), args=(1.42, 41.0, -1.0), xtol=1e-06, maxfev=500)
Warning (from warnings module):
  File "C:\Python27\lib\site-packages\scipy\optimize\minpack.py", line 152
    warnings.warn(msg, RuntimeWarning)
RuntimeWarning: The iteration is not making good progress, as measured by the 
   improvement from the last ten iterations.
>>> print x0
[ -4.87169392e+05  -4.87168392e+05  -4.87167392e+05  -4.87166392e+05
  -4.87165392e+05  -4.87164392e+05  -4.87163392e+05  -4.87162392e+05
   4.24200000e+01   4.24200000e+01   4.24200000e+01   4.24200000e+01
   4.24200000e+01   4.24200000e+01   4.24200000e+01   4.24200000e+01
   4.24200000e+01]

First question is how one might suppress the warning message that’s being returned?

Second, why might this error be generated in the first place (other than the obvious, that the iteration is not making good progress 🙂 )?

Finally, the root of this function is 42.42 (which is found). Why is fzero returning -4.87e+05 as well?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:02:48+00:00Added an answer on June 15, 2026 at 7:02 am

    Doing this might make you miss something important, but, to silence the warning message you could use warnings.filterwarnings:

    import warnings
    warnings.filterwarnings('ignore', 'The iteration is not making good progress')
    import math
    from scipy.optimize import fsolve
    import numpy as np
    def p(s, l, k, q):
        p = q * np.maximum(s - k, 0.0)
        return (p + math.copysign(l, -q)) * math.fabs(q) * 100.0
    
    x0 = fsolve(p, np.arange(33.86, 50.86, 1.0),
                args=(1.42, 41.0, -1.0), xtol=1e-06, maxfev=500)
    print(x0)
    

    In fact, p(x0, 1.42, 41.0, -1) is not close to zero, so fsolve is correctly warning you that it failed to find a solution.


    PS. When you say

    fsolve(p, np.arange(33.86, 50.86, 1.0),...)
    

    you are telling fsolve that your initial guess for s is the numpy array np.arange(33.86, 50.86, 1.0). The whole array is being passed in to p at once.

    Notice that np.arange(33.86, 50.86, 1.0) has length 17 and so does x0. That is because fsolve thinks it is looking for an array of length 17 that solves p.

    I think perhaps you meant s to be a float? In that case, you can only pass in one float value for your initial guess:

    fsolve(p, 41.0, args = (1.42, 41.0, -1.0), xtol=1e-06, maxfev=500)
    

    For example,

    import math
    import scipy.optimize as optimize
    import numpy as np
    
    def p(s, l, k, q):
        p = q * np.maximum(s - k, 0.0)
        return (p + math.copysign(l, -q)) * math.fabs(q) * 100.0
    
    args = (1.42, 41.0, -1.0)
    result = optimize.fsolve(p, 41.0, args=args, xtol=1e-06, maxfev=500)
    print(result)
    

    yields

    [ 42.42]
    

    fsolve does a decent job of zeroing-in on the root if the initial guess is >= 41.0 (the value of k) but fails when the initial guess is < 41.0.

    My guess is that this is due to np.maximum not changing for many guesses for s. So fsolve does not know whether to increase or decrease s and is apt to guess wrong and move s farther and farther from the root.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the latest version of numpy/scipy. The following script does not work: import
When I try to import the scipy module (version 0.11.0b1) in the Python interpreter
EDIT: after reading this http://projects.scipy.org/numpy/ticket/1322 it seems that the NumPy version I am using
Scipy and Numpy have between them three different functions for finding eigenvectors for a
Can MlPy / SciPy be used on GAE? I believe I have imported NumPy
When using scipy.optimize 's fmin I'm getting an error I don't understand: ValueError: setting
I'm using scipy.linalg to solve a matrix equation A*x = b The following code
What does the smode of scipy.optimize 'Positive directional derivative for linesearch' mean? for example
I have installed numpy1.3,scipy 0.7.1,matplotlib 0.99.1.1 and python 2.5 when I import pylab I
I'm trying to use the ndimage library from scipy, but its apparently missing. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.