From: Richard Kreckel Date: Fri, 23 Sep 2005 00:19:35 +0000 (+0000) Subject: * Sync to HEAD (fsolve relational objects). X-Git-Tag: release_1-3-3~9 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=commitdiff_plain;h=d622ed77e574ba857949353435d90033f1b97f75;p=ginac.git * Sync to HEAD (fsolve relational objects). --- diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index 0f3ca0c7..e7ab635a 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -655,7 +655,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options) ////////// const numeric -fsolve(const ex& f, const symbol& x, const numeric& x1, const numeric& x2) +fsolve(const ex& f_in, const symbol& x, const numeric& x1, const numeric& x2) { if (!x1.is_real() || !x2.is_real()) { throw std::runtime_error("fsolve(): interval not bounded by real numbers"); @@ -668,6 +668,12 @@ fsolve(const ex& f, const symbol& x, const numeric& x1, const numeric& x2) // We keep the root bracketed: xx[0](f_in)) { + f = f_in.lhs()-f_in.rhs(); + } else { + f = f_in; + } const ex fx_[2] = { f.subs(x==xx[0]).evalf(), f.subs(x==xx[1]).evalf() }; if (!is_a(fx_[0]) || !is_a(fx_[1])) { @@ -723,7 +729,7 @@ fsolve(const ex& f, const symbol& x, const numeric& x1, const numeric& x2) // determined by the secant between the values xx[0] and xx[1]. // Don't set the secant_weight to one because that could disturb // the convergence in some corner cases! - static const double secant_weight = 0.96875; // == 31/32 < 1 + static const double secant_weight = 0.984375; // == 63/64 < 1 numeric xxmid = (1-secant_weight)*0.5*(xx[0]+xx[1]) + secant_weight*(xx[0]+fx[0]*(xx[0]-xx[1])/(fx[1]-fx[0])); numeric fxmid = ex_to(f.subs(x==xxmid).evalf());