polylib::minpoly
-- approximate
minimal polynomialpolylib::minpoly
(a, n, x)
computes a
univariate polynomial f
in the variable x
of
degree n
with integer coefficients such that
a
equals a root of f
up to the precision
given by DIGITS
, and such that the sum of squares of its
coefficients is minimal among all polynomials with this property.
polylib::minpoly(a, n, x)
a |
- | arithmetical expression that can be converted to a floating point number |
n |
- | positive integer |
x |
- | identifier |
polylib::minpoly
returns a polynomial in
x
. Its coefficient ring is Expr
, all of its
coefficients are integers.
polylib::minpoly
is sensitive to the environment
variable DIGITS
.
lllint
, stats::linReg
, numeric::lagrange
We compute a polynomial of degree 4 that has a root
close to PI
(up to 6
decimal digits) and small integer coefficients:
>> DIGITS:=6: polylib::minpoly(PI, 4, x); delete DIGITS:
4 3 2 poly(7 x - 16 x - 16 x - 6 x - 9, [x])
If the root has to be even closer to PI
, bigger coefficients are needed:
>> DIGITS:=20: polylib::minpoly(PI, 4, x); delete DIGITS
4 3 2 poly(- 1951 x + 6379 x - 422 x + 283 x - 4468, [x])
numeric::minpoly