Fsolve always returns grade / grade

I am using the scipy optimize.fsolve function for the first time to find the roots of the equation. The problem is that any number that I use as a guess / score value is what I return as my answer (in about 8 decimal places). When using full_output = True, I get exitflag equal to โ€œ1โ€, which should mean that โ€œSolution convergesโ€, which, as far as I know, should mean that the output is really the root of the equation.

I know that there are a finite number of different roots (which are separated from each other), because when I draw an equation, I see them. Also, fsolve fail (gives an exitflags error) when I enter the start point in a range that should return undefined values โ€‹โ€‹(division by zero, the square root of a negative value). But in addition, it always returns the starting point as the root.

I tested fsolve with a very simple equation and it worked fine, so I know that I import everything I need and must use fsolve correctly. I also tried to combine with some input arguments, but I do not understand them very well and nothing has changed).

Below is the corresponding code (E is the only variable, everything else has a nonzero value):

def func(E):
    s = sqrt(c_sqr * (1 - E / V_0))
    f = s / tan(s) + sqrt(c_sqr - s**2)
    return f

guess = 3
fsolve(func, guess)

"3" " ", 2.8 4.7.

- , ( fsolve)?

+5
2

, , . -, , ; , . , fsolve. :

>>> V_0 = 100
>>> c_sqr = 3e8 ** 2
>>> guess = 5
>>> fsolve(func, guess)
array([ 5.00000079])

5. 5 . :

>>> func(5.00000079)
2114979.3239706755

:

>>> func(5.0000008)
6821403.0196130127
>>> func(5.0000006)
-96874198.203683496

, , - . , . , tan , .

+6

- ? :

#!/usr/bin/python
from scipy.optimize import fsolve

def func(E):
#    s = sqrt(c_sqr * (1 - E / V_0))
#    f = s / tan(s) + sqrt(c_sqr - s**2)
    f = E**2 -3.
    return f

guess = 9

sol=fsolve(func, guess)
print sol, func(sol)

, .

, , --- c_str V_0? , , , args fsolve, :

#!/usr/bin/python
from scipy.optimize import fsolve
from numpy import sqrt

def func(E,V_0):
    #s = sqrt(c_sqr * (1 - E / V_0))
    #f = s / tan(s) + sqrt(c_sqr - s**2)
    f = E**2 -V_0
    return f

VV=4.
guess = 9
sol=fsolve(func, guess, args=(VV))

print sol, func(sol,VV) 
+1

All Articles