I am new to python and am trying to change some matlab code as drill. One of the functions involves involving the root or the minimum absolute value, if there is no root, then any function of it. I can do this right, but I want to see some error checking that scipy.optimize.fsolve actually finds a solution, in particular, fsolve gives a parameter ier which is just a success flag and i want to read it I am
My code is as follows:
Reduce nppy as scipy.optimize import fsolve as import, mu = -8 sigma = 4 mun = -2 ARL0 = 2000 hmin = 0.5 Hmx = 100 f = lambda h: (np.xp (-2 * mun * (h / sigma +1.166)) - 1 + 2 * mun * (h / sigma + 1.166)) / (2 * Mun ** 2) - RRL If F (HM) * F (Hmx) and LT; 0: opth, ier = fsolve (f, hmax) print ier print opth [0] and: f = lambda h: np.abs ((np.exp (-2 * mun * (h / sigma + 1.166)) - 1 + 2 * mun * (h / sigma + 1.166)) / (2 * mun ** 2) -RAR0) opth = minimize (f, hmax, bounds = ((hmin, hmax), print opth.success print opth .x [0]
"and" bit works fine, this solution and a true / false impression is if the block is not found if it has got one: When it runs:
in line 14, in the
Opth, ier = fsolve (f, hmax) ValueError: 1 / /> It is assuming that this is just a syntax error, but I can not find an example using fsolve to do that. Can anyone tell me in the right direction?
You have to add the argument full_output = true
and actually see the 4 return value, so you can see them all Unpack.
Here is the source for SciPy (in my version of 0.14) fsolve
.0), you can return the return values You can see two options:
def fsolve (func, x0, args = (), fprime = none, full_output = 0, col_deriv = 0, xtol = 1.49012e-8, maxfev = 0 , Band = none, epsfcn = none, factor = 100, diagram = none): option = {'col_deriv': col_deriv, 'xtol': xtol, 'maxfev': maxfev, 'band': full_output: x = 'Eps': epsfcn, 'factor': factor, 'diag': diag, 'full_output': full_output} res = _root_hybr (func, x0, args, jac = fprime, ** option) Res ['x'] info = ('Nfe V', 'njev', 'fjac', 'r', 'qtf') for k ('k, res.get (k)) k) info k' info ['fvec'] = Res ['funny'] return x, information, res ['status'], res ['message'] and: return rage ['x']
No comments:
Post a Comment