hi,
(+cc authors of the other root-finding thread[1], to get a bit more feedback)
as a possible first iteration, let me propose the following.
let's leave the general roots finding API (Bisection, Newton, Brent, ...) for later.
I am only interested (for now) in polynomial of degree n<=4.
package roots // import "
gonum.org/v1/gonum/roots"
// Poly2 returns the roots of the following 2nd degree polynomial:
// a x^2 + b x + c = 0
func Poly2(a, b, c float64) (r1, r2 float64) { ... }
// Poly3 returns the roots of the following 3rd degree polynomial:
// a x^3 + b x^2 + c x + d = 0
func Poly3(a, b, c, d float64) (z1, z2, z3 complex128) { ... }
// Poly4 returns the roots of the following 4th degree polynomial:
// a x^4 + b x^3 + c x^2 + d x + e = 0
func Poly4(a, b, c, d, e float64) (z1, z2, z3, z4 complex128) { ... }
the PolyN find the roots analytically (ie: sans using the companion matrix).
alternatively (or in addition), we could have the following catch all function:
func Polynomial(dst []complex128, ps []float64) []complex128 { ...}
that would deal with all cases (using the companion matrix for n>4).
or, just have the single "Polynomial" function to deal with all cases:
o := roots.Polynomial(nil, []float64{1,2,3,4})
the PolyN won't incur any slice allocation (neither on the user nor internally).
WDYT ?
-s
[1]:
https://groups.google.com/g/gonum-dev/c/F70xPKOQJs8
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐