Documentation
¶
Index ¶
- func SetNewtonIterations(n int) error
- type GraphOptions
- type Point
- type RealPolynomial
- func (rp1 *RealPolynomial) Add(rp2 *RealPolynomial) *RealPolynomial
- func (rp *RealPolynomial) At(x float64) float64
- func (rp *RealPolynomial) CoeffAtDegree(n int) 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) FindIntersectionWithin(a, b float64, rp2 *RealPolynomial) (Point, error)
- func (rp *RealPolynomial) FindIntersectionsWithin(a, b float64, rp2 *RealPolynomial) ([]Point, error)
- func (rp *RealPolynomial) FindRootWithin(a, b float64) (float64, error)
- func (rp *RealPolynomial) FindRootsWithin(a, b float64) ([]float64, error)
- func (rp *RealPolynomial) IsDegree(n int) bool
- 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) Print()
- func (rp *RealPolynomial) ShiftRight(offset int) *RealPolynomial
- func (rp *RealPolynomial) String() string
- func (rp1 *RealPolynomial) Sub(rp2 *RealPolynomial) *RealPolynomial
- type RealPolynomialGraph
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 GraphOptions ¶ added in v1.1.0
type GraphOptions struct { ShowAxis bool ShowGrid bool ShowIntersections bool ShowRoots bool ShowYintercepts bool ShowAxisLabels bool ShowIntersectionLabels bool ShowRootLabels bool ShowYinterceptLabels bool }
GraphOptions specify some visual options that the RealPolynomialGraph can have.
The options are:
ShowAxis // show the x = 0 and y = 0 axis lines. ShowGrid // show the grid. ShowIntersections // highlight the intersection points of all polynomials. ShowRoots // highlight the roots of all polynomials. ShowYintercepts // highlight the y-intercepts of all polynomials. ShowAxisLabels // label axis values. ShowIntersectionLabsls // label intersection points. ShowRootLabels // label roots. ShowYinterceptLabels // label y-intercepts.
type RealPolynomial ¶
type RealPolynomial struct {
// contains filtered or unexported fields
}
A 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) CoeffAtDegree ¶ added in v1.0.1
func (rp *RealPolynomial) CoeffAtDegree(n int) float64
CoeffAtDegree returns the coefficient at degree n.
n should be positive.
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) FindIntersectionWithin ¶
func (rp *RealPolynomial) FindIntersectionWithin(a, b float64, rp2 *RealPolynomial) (Point, error)
FindIntersectionWithin returns ANY intersection point 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) ([]Point, error)
FindIntersectionsWithin returns ALL intersection point 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) IsDegree ¶ added in v1.0.1
func (rp *RealPolynomial) IsDegree(n int) bool
IsDegree returns true if current instance is of degree n. Otherwise, false is returned.
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) Print ¶ added in v1.1.0
func (rp *RealPolynomial) Print()
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) String ¶ added in v1.1.0
func (rp *RealPolynomial) String() string
Expr returns a string representation of the current instance in increasing sum form.
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.
type RealPolynomialGraph ¶ added in v1.1.0
type RealPolynomialGraph struct {
// contains filtered or unexported fields
}
A RealPolynomialGraph represents the graph of a set of polynomials.
func NewGraph ¶ added in v1.1.0
func NewGraph(elements []*RealPolynomial, center Point, xResolution, yResolution int, viewX, viewY, xRenderStep, gridStep float64, options *GraphOptions) (*RealPolynomialGraph, error)
NewGraph returns a new *RealPolynomialGraph instance with the provided settings.
If any settings are invalid, an appropriate error is set.
The settings are:
center // the point at which the graph is centered. xResolution // the width of the graph in pixels. yResolution // the height of the graph in pixels. viewX // the width of the viewing area. For example, a viewX of 1.0 will provide a graph spanning the horizontally closed interval [center.X - 1.0, center.X + 1.0]. viewY // the height of the viewing area. For example, a viewY of 1.0 will provide a graph spanning the vertically closed interval [center.Y - 1.0, center.Y + 1.0]. xRenderStep // the detail the polynomial curves are rendered at. The closer this positive value is to 0.0, the more precise the curves will be (recommended to be 0.01). gridStep // the gap between consecutive axis lines. options // a *GraphOptions instance.
func (*RealPolynomialGraph) SaveAsPNG ¶ added in v1.1.0
func (g *RealPolynomialGraph) SaveAsPNG(path string) error
SaveAsPNG renders and saves the current instance as a PNG image file to the provided path.
If any rendering errors occur, an error addressing the problem is set.