def solwave_mck(x, c): """ Return solitary wave values at x, f_c(x). """ amp = solwave_amp_mck(c) def bracket(xx): """ Construct bracket for root solving about xx. """ aa = .5 * (1. + amp) bb = amp while (solwave_implicit_mck(aa, xx, amp)>0 and numpy.isfinite(solwave_implicit_mck(aa, xx, amp))): bb = aa aa = .5 * (aa + 1.) if numpy.isfinite(solwave_implicit_mck(aa, xx, amp)): return aa, bb else: return -1., -1. if numpy.isscalar(x): a, b = bracket(x) if a > 0. and b > 0.: f = brentq(solwave_implicit_mck, a, b, args = (x, amp)) else: f = 1. else: f = numpy.zeros(len(x)) for j in range(0, len(x)): a, b = bracket(x[j]) if a > 0. and b > 0.: f[j] = brentq(solwave_implicit_mck, a, b, args = (x[j], amp)) else: f[j] = 1. return f
def test_gh9254_flag_if_maxiter_exceeded(maximum_iterations, flag_expected): """ Test that if the maximum iterations is exceeded that the flag is not converged. """ result = zeros.brentq( lambda x: ((1.2*x - 2.3)*x + 3.4)*x - 4.5, -30, 30, (), 1e-6, 1e-6, maximum_iterations, full_output=True, disp=False) assert result[1].flag == flag_expected if flag_expected == zeros.CONVERR: # didn't converge because exceeded maximum iterations assert result[1].iterations == maximum_iterations elif flag_expected == zeros.CONVERGED: # converged before maximum iterations assert result[1].iterations < maximum_iterations