peenin--
peenin--

Reputation: 1

How to solve this complicated non-linear function?

The code is giving the same output as my guess value in fsolve function

import numpy as np
import math
from scipy.optimize import fsolve
def f(y):

    a11 = 17.20
    iv_y = np.sqrt(pi)*np.sqrt(y)*np.exp(y)*math.erfc(np.sqrt(y))
    b11 = 86.02
    dr = 1-(0.92*iv_y)
    g = -(y*a11)/dr - (b11*iv_y)/dr - 50
    return g
pe = fsolve(f,10)
print(pe)

Any reason why it is giving the same output as my guess value 10?

Upvotes: 0

Views: 122

Answers (1)

Didymus Prime
Didymus Prime

Reputation: 86

The fsolve function is printing the warning: "RuntimeWarning: The iteration is not making good progress, as measured by the improvement from the last ten iterations." This means that fsolve cannot find a solution.

We can see why it cannot find a solution if we look at a plot of your function" enter image description here

You can see that the function is negative and monotonically decreasing. It is not defined for negative arguments. So essentially, you are asking fsolve to find a solution that doesn't exist; the function despairs at this hopeless task and just returns the original guess.

Upvotes: 1

Related Questions