1 ## Copyright (C) 2002 Etienne Grossmann. All rights reserved.
3 ## This program is free software; you can redistribute it and/or modify it
4 ## under the terms of the GNU General Public License as published by the
5 ## Free Software Foundation; either version 2, or (at your option) any
8 ## This is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 ## ex = poly_2_ex (l, f) - Extremum of a 1-var deg-2 polynomial
15 ## l : 3 : Values of variable at which polynomial is known.
16 ## f : 3 : f(i) = Value of the degree-2 polynomial at l(i).
18 ## ex : 1 : Value for which f reaches its extremum
20 ## Assuming that f(i) = a*l(i)^2 + b*l(i) + c = P(l(i)) for some a, b, c,
21 ## ex is the extremum of the polynome P.
23 function ex = poly_2_ex (l, f)
26 ### This somewhat helps if solution is very close to one of the points.
31 m = (l(2) - l(1))/(l(3) - l(1));
32 d = (2*(f(1)*(m-1)+f(2)-f(3)*m));
34 printf ("poly_2_ex : divisor is small (solution at infinity)\n");
35 printf ("%8.3e %8.3e %8.3e, %8.3e %8.3e\n",\
36 f(1), diff (f), diff (sort (l)));
38 ex = (2*(l(1)>l(2))-1)*inf;
41 ex = ((l(3) - l(1))*((f(1)*(m^2-1) + f(2) - f(3)*m^2))) / d ;
44 # n = ((l(2)+l(3))*(l(2)-l(3)) + 2*(l(3)-l(2))*l(1)) / (l(3)-l(1))^2 ;
45 # ex = ((l(3) - l(1))*((f(1)*n + f(2) - f(3)*m^2))) / \
46 # (2*(f(1)*(m-1)+f(2)-f(3)*m));