Documentation
¶
Overview ¶
Define types and functions related to factoring.
Define the Polynomial type and its methods.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FactoredPolynomial ¶ added in v0.0.2
type FactoredPolynomial struct {
Raw string
XIntercepts []float64
Unfactored Polynomial
}
A polynomial in factored form.
func Factor ¶ added in v0.0.2
func Factor(unfactored Polynomial, roundTo int) *FactoredPolynomial
Factor a polynomial function. Round numbers displayed in the 'Raw' field to 'roundTo' decimal places. If the function is not factorable, the 'Raw' field will read "not factorable".
Example (LongPolynomial) ¶
p := Polynomial{1, -4, 0, 7, 2} // 2x⁴ + 7x³ - 4x + 1
f := Factor(p, 2)
fmt.Println(f.Raw)
Output: (x + 1)(x - 0.5)(x - 0.3)(x + 3.3)
Example (QuadraticFormula) ¶
p := Polynomial{10, 2, 1} // x² + 2x + 10
f := Factor(p, 2)
fmt.Println(f.Raw)
Output: (x - ((-2 + √-36) / 2))(x - ((-2 - √-36) / 2))
Example (SimpleTrinomial) ¶
p := Polynomial{10, 7, 1} // x² + 7x + 10
f := Factor(p, 2)
fmt.Println(f.Raw)
Output: (x + 5)(x + 2)
type Polynomial ¶
type Polynomial []float64
A type that represents a polynomial function. Each array index is mapped to the corresponding term. For example,
Polynomial{5, -13, 1, 4}
Index: 0 1 2 3
represents the polynomial function:
x³ + x² - 13x + 5 Power of x: 3 2 1 0
func (*Polynomial) Degree ¶
func (p *Polynomial) Degree() int
Returns the degree (highest exponent) of the polynomial function.
Example ¶
p := Polynomial{5, -12, 4}
// 4x² - 12x + 5 --> highest exponent = 2
fmt.Print(p.Degree())
Output: 2
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
quick-factor
command
Command-line tool to find factors of a polynomial function.
|
Command-line tool to find factors of a polynomial function. |
Click to show internal directories.
Click to hide internal directories.