Math_Polynomial [ class tree: Math_Polynomial ] [ index: Math_Polynomial ] [ all elements ] # Class: Math_Polynomial

Source Location: /Math_Polynomial-0.1.0/Polynomial.php

Polynomial class

### Class Details

[line 60]
Polynomial class

The Math_Polynomial class represents simple polynomials of the form: ax^n + bx^(n-1) + cx^(n-2) + ... yx + z

Methods having a Polynomial or mixed type as a parameter should be able to take either a string representation of a polynomial or a Polynomial object as a parameter. Simple algebraic operations on polynomials are supported using the following methods:

• subtract() Subtract another polynomial from the current polynomial
• multiply() Multiply the current polynomial by another polynomial
• divide() Divide the current polynomial by another polynomial
• mod() Perform the 'mod' function ( get the remainder of poly. division )
Other operations include:
• getDerivative(x) Get the nth derivative of the Polynomial
• degree() Get the degree ( highest exponent )
• evaluate(x) Evaluate the polynomial at a given x value
String representation of the Polynomial object can be retrieved with the toString() method.

[ Top ]

### Class Variables

#### \$_needs_combining =

[line 76]

Whether or not Polynomial may contain multiple terms of the same degree
• Access: protected

 Type: bool

[ Top ]

#### \$_needs_sorting =

[line 84]

Whether or nothe Polynomial terms list needs to be sorted
• Access: protected

 Type: bool

[ Top ]

#### \$_terms =

[line 68]

An array of PolynomialTerm objects
• Access: protected

 Type: array

[ Top ]

### Math_Polynomial (Constructor)   [line 95]

 ```Math_Polynomial Math_Polynomial( [mixed \$mixed_poly = null])```

Polynomial Constructor

Constructs an empty ( equal to 0 ) Polynomial object OR constructs a Polynomial from another Polynomial object or from a string representation of a polynomial.

#### Parameters:

 mixed \$mixed_poly — String or Polynomial to construct from

[ Top ]

 ```bool addTerm( object \$term)```

Add a term to the Polynomial

#### Parameters:

 object \$term —

[ Top ]

### degree   [line 421]

 ```integer degree( )```

Retrieve the degree ( highest exponent value ) of the polynomial
• Return: The degree of the polynomial
• Access: public

[ Top ]

### degreeString   [line 454]

 ```string degreeString( )```

Retrieve a string naming the degree of the polynomial

Tries to retrieve a string to name the polynomial degree, for example: 3 - Contant 3x - Linear equation 3x^2 - Quadtratic 3x^3 - Cubic etc.

• Return: String naming the polynomial degree
• Access: public

[ Top ]

### getTerm   [line 139]

 ```object getTerm( integer \$n)```

Get the term in the nth position from the Polynomial

#### Parameters:

 integer \$n —

[ Top ]

### numTerms   [line 120]

 ```integer numTerms( )```

Tell the number of terms in the Polynomial object

[ Top ]

### toString   [line 276]

 ```string toString( [bool \$spaces = true])```

Retrieve a string representation of the Polynomial
• Return: String representation
• Access: public

#### Parameters:

 bool \$spaces — Whether or not the string should contain spaces ( i.e.: 4x^2 - 2x vs. 4x^2-2x )

[ Top ]

### _combineLikeTerms   [line 379]

 ```void _combineLikeTerms( )```

Combine like terms inside the Polynomial object

Examines each term of the Polynomial and, if any of the terms have equivalent exponents, adds the two terms together ( add coefficients, keep the same exponent ) This is used to simplify the Polynomial for output.

• Access: protected

[ Top ]

### _parsePolynomial   [line 247]

 ```void _parsePolynomial( string \$str_poly)```

Parse a string

#### Parameters:

 string \$str_poly — A string representation of a Polynomial

[ Top ]

### _parseTerm   [line 188]

 ```object A _parseTerm( string \$str_term)```

Parse an individual term of Math_Polynomial into a Math_PolynomialTerm object

#### Parameters:

 string \$str_term —

[ Top ]

### _sortTerms   [line 349]

 ```void _sortTerms( )```

Sort the terms list

Uses a bubble-sort to sort the list of terms in descending order by their exponent values.

• Access: protected

[ Top ]

Documentation generated on Mon, 11 Mar 2019 14:38:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.