From: Richard Kreckel Date: Fri, 23 Sep 2005 00:18:51 +0000 (+0000) Subject: * Make fsolve() accept relational objects as first arguments. X-Git-Tag: release_1-4-0~150 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=0c9cc6886e62e476de252b017161203f049edc8f * Make fsolve() accept relational objects as first arguments. --- diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index a9ad5ce5..26ebd937 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -668,7 +668,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"); @@ -681,6 +681,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])) { @@ -736,7 +742,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());