1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
2 ## Copyright (C) 2009 Levente Torok <TorokLev@gmail.com>
4 ## This program is free software; you can redistribute it and/or modify it under
5 ## the terms of the GNU General Public License as published by the Free Software
6 ## Foundation; either version 3 of the License, or (at your option) any later
9 ## This program is distributed in the hope that it will be useful, but WITHOUT
10 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 ## You should have received a copy of the GNU General Public License along with
15 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## ex = poly_2_ex (l, f) - Extremum of a 1-var deg-2 polynomial
19 ## l : 3 : variable values
20 ## f : 3 : f(i) = value of polynomial at l(i)
22 ## ex : 1 : Value at which f reaches an extremum
24 ## Assuming that f(i) = a*l(i)^2 + b* l(i) + c = P(l(i)) for some a, b, c,
25 ## ex is the extremum of the polynome P.
27 function ex = __poly_2_extrema (l, f)
29 ### This somewhat helps if solution is very close to one of the points.
34 m = (l(2) - l(1))/(l(3) - l(1));
35 d = (2*(f(1)*(m-1)+f(2)-f(3)*m));
37 printf ("poly_2_ex : divisor is small (solution at infinity)\n");
38 printf ("%8.3e %8.3e %8.3e, %8.3e %8.3e\n",\
39 f(1), diff (f), diff (sort (l)));
41 ex = (2*(l(1)>l(2))-1)*inf;
44 ex = ((l(3) - l(1))*((f(1)*(m^2-1) + f(2) - f(3)*m^2))) / d ;
47 # n = ((l(2)+l(3))*(l(2)-l(3)) + 2*(l(3)-l(2))*l(1)) / (l(3)-l(1))^2 ;
48 # ex = ((l(3) - l(1))*((f(1)*n + f(2) - f(3)*m^2))) / \
49 # (2*(f(1)*(m-1)+f(2)-f(3)*m));