Documentation ¶
Overview ¶
Package polygo is a collection of tools that make working with polynomials easier in Go.
Index ¶
- func SetNewtonIterations(n int) error
- type RealPolynomial
- func (rp1 *RealPolynomial) Add(rp2 *RealPolynomial) *RealPolynomial
- func (rp *RealPolynomial) At(x float64) float64
- func (rp *RealPolynomial) CountRootsWithin(a, b float64) int
- func (rp *RealPolynomial) Degree() int
- func (rp *RealPolynomial) Derivative() *RealPolynomial
- func (rp1 *RealPolynomial) Equal(rp2 *RealPolynomial) bool
- func (rp1 *RealPolynomial) EuclideanDiv(rp2 *RealPolynomial) (*RealPolynomial, *RealPolynomial)
- func (rp *RealPolynomial) Expr() string
- func (rp *RealPolynomial) FindIntersectionWithin(a, b float64, rp2 *RealPolynomial) ([2]float64, error)
- func (rp *RealPolynomial) FindIntersectionsWithin(a, b float64, rp2 *RealPolynomial) ([][2]float64, error)
- func (rp *RealPolynomial) FindRootWithin(a, b float64) (float64, error)
- func (rp *RealPolynomial) FindRootsWithin(a, b float64) ([]float64, error)
- func (rp *RealPolynomial) IsZero() bool
- func (rp *RealPolynomial) LeadCoeff() float64
- func (rp1 *RealPolynomial) Mul(rp2 *RealPolynomial) *RealPolynomial
- func (rp1 *RealPolynomial) MulNaive(rp2 *RealPolynomial) *RealPolynomial
- func (rp *RealPolynomial) MulS(s float64) *RealPolynomial
- func (rp *RealPolynomial) NumCoeffs() int
- func (rp *RealPolynomial) PrintExpr()
- func (rp *RealPolynomial) ShiftRight(offset int) *RealPolynomial
- func (rp1 *RealPolynomial) Sub(rp2 *RealPolynomial) *RealPolynomial
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetNewtonIterations ¶
SetNewtonIterations sets the number of iterations used in Newton's Method implmentation in root solving functions.
Types ¶
type RealPolynomial ¶
type RealPolynomial struct {
// contains filtered or unexported fields
}
A real RealPolynomial is represented as a slice of coefficients ordered increasingly by degree. For example, one can imagine: 5x^0 + 4x^1 + (-2)x^2 + ...
func NewRealPolynomial ¶
func NewRealPolynomial(coeffs []float64) (*RealPolynomial, error)
NewRealPolynomial returns a new *RealPolynomial instance with the given coeffs.
func (*RealPolynomial) Add ¶
func (rp1 *RealPolynomial) Add(rp2 *RealPolynomial) *RealPolynomial
Add adds the current instance and rp2 and returns the sum. The current instance is also set to the sum.
func (*RealPolynomial) At ¶
func (rp *RealPolynomial) At(x float64) float64
At returns the value of the current instance evaluated at x.
func (*RealPolynomial) CountRootsWithin ¶
func (rp *RealPolynomial) CountRootsWithin(a, b float64) int
CountRootsWithin returns the number of roots of the current instance on the closed interval [a, b]. If there are an infinite amount of roots, -1 is returned.
func (*RealPolynomial) Degree ¶
func (rp *RealPolynomial) Degree() int
Degree returns the degree of the current instance.
func (*RealPolynomial) Derivative ¶
func (rp *RealPolynomial) Derivative() *RealPolynomial
Derivative returns the derivative of the current instance. The current instance is not modified.
func (*RealPolynomial) Equal ¶
func (rp1 *RealPolynomial) Equal(rp2 *RealPolynomial) bool
Equal returns true if the current instance is equal to rp2. Otherwise, false is returned.
func (*RealPolynomial) EuclideanDiv ¶
func (rp1 *RealPolynomial) EuclideanDiv(rp2 *RealPolynomial) (*RealPolynomial, *RealPolynomial)
EuclideanDiv divides the current instance by rp2 and returns the result as a quotient-remainder pair. The current instance is also set to the quotient.
func (*RealPolynomial) Expr ¶
func (rp *RealPolynomial) Expr() string
Expr returns a string representation of the current instance in increasing sum form.
func (*RealPolynomial) FindIntersectionWithin ¶
func (rp *RealPolynomial) FindIntersectionWithin(a, b float64, rp2 *RealPolynomial) ([2]float64, error)
FindIntersectionWithin returns ANY intersection point (as a two-element slice) of the current instance and rp2 existing on the closed interval [a, b]. If there are no intersections on the provided interval, an error is set.
func (*RealPolynomial) FindIntersectionsWithin ¶
func (rp *RealPolynomial) FindIntersectionsWithin(a, b float64, rp2 *RealPolynomial) ([][2]float64, error)
FindIntersectionsWithin returns ALL intersection point (as a two-element slice) of the current instance and rp2 existing on the closed interval [a, b]. Unlike FindIntersectionWithin, no error is set if there are no intersections on the provided interval. Instead, an empty slice is returned. If there are an infinite number or solutions, an error is set.
func (*RealPolynomial) FindRootWithin ¶
func (rp *RealPolynomial) FindRootWithin(a, b float64) (float64, error)
FindRootWithin returns ANY root of the current instance existing on the closed interval [a, b]. If there are no roots on the provided interval, an error is set.
func (*RealPolynomial) FindRootsWithin ¶
func (rp *RealPolynomial) FindRootsWithin(a, b float64) ([]float64, error)
FindRootsWithin returns ALL roots of the current instance existing on the closed interval [a, b]. Unlike FindRootWithin, no error is set if there are no solutions on the provided interval. Instead, an empty slice is returned. If there are an infinite number of solutions on [a, b], an error is set.
func (*RealPolynomial) IsZero ¶
func (rp *RealPolynomial) IsZero() bool
IsZero returns true if current instance is equal to the zero polynomial. Otherwise, false is returned.
func (*RealPolynomial) LeadCoeff ¶
func (rp *RealPolynomial) LeadCoeff() float64
LeadCoeff Returns the coefficient of the highest degree term of the current instance.
func (*RealPolynomial) Mul ¶
func (rp1 *RealPolynomial) Mul(rp2 *RealPolynomial) *RealPolynomial
Mul multiplies the current instance with rp2 and returns the product. The current instance is also set to the product.
func (*RealPolynomial) MulNaive ¶
func (rp1 *RealPolynomial) MulNaive(rp2 *RealPolynomial) *RealPolynomial
MulNaive multiplies the current instance with rp2 and returns the product. The current instance is also set to the product.
It is not recommended to use this function. Use Mul instead.
func (*RealPolynomial) MulS ¶
func (rp *RealPolynomial) MulS(s float64) *RealPolynomial
MulS multiplies the current instance with the scalar s and returns the product. The current instance is also set to the product.
func (*RealPolynomial) NumCoeffs ¶
func (rp *RealPolynomial) NumCoeffs() int
NumCoeffs returns the number of coefficients of the current instance.
func (*RealPolynomial) PrintExpr ¶
func (rp *RealPolynomial) PrintExpr()
PrintExpr prints the string expression of the current instance in increasing sum form to standard output.
func (*RealPolynomial) ShiftRight ¶
func (rp *RealPolynomial) ShiftRight(offset int) *RealPolynomial
ShiftRight shifts the coefficients of each term in the current instance rightwards by offset and returns the resulting polynomial. The current instance is not modified. A right shift by N is equivalent to multipliying the current instance by x^N.
func (*RealPolynomial) Sub ¶
func (rp1 *RealPolynomial) Sub(rp2 *RealPolynomial) *RealPolynomial
Sub subtracts rp2 from the current instance and returns the difference. The current instance is also set to the difference.