quickFactor

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2020 License: MPL-2.0 Imports: 5 Imported by: 0

README

Quick Factor CI/CD Go Reference

Command-line tool to find factors of a polynomial function.

Installation

This program can be installed two different ways:

1. With Golang installed
  • Open a command line
  • Run go get github.com/noah-friedman/find-factors/cmd/find-factors (NOTE: You must have $GOPATH/bin in the system path)
  • Run the program by running find-factors on the command line
2. Without Golang installed
  • Navigate to the releases page
  • Download the correct binary for your system from the latest release
  • macOS and Linux only: Run chmod +x path/to/binary in order to mark the binary as executable
  • Run the executable file

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

func (*Polynomial) F

func (p *Polynomial) F(x float64) float64

Find the value of the polynomial function using the provided 'x' value.

Example
x := 7.0
p := Polynomial{3, 5}
// 5x + 3 -> 5(7) + 3 == 38

fmt.Print(p.F(x)) 
Output:
38

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL