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

Class: Math_PolynomialOp

Source Location: /Math_Polynomial-0.1.0/PolynomialOp.php

Class Overview


Class for operations on Math_Polynomial objects


Author(s):

Methods


Inherited Variables

Inherited Methods


Class Details

[line 103]
Class for operations on Math_Polynomial objects

Mathematical operations on Polynomial objects. All class methods are static methods and take as parameters either a Polynomial object or a string respresentation of a Polynomial in the form of: ax^n + bx^(n-1) + cx^(n-2) + ... yx + z



[ Top ]


Method Detail

add   [line 135]

object &add( mixed $p1, mixed $p2)

Add two Polynomials together and return the result

  1.  $p = new Polynomial("x + 2");
  2.  $res = PolynomialOp::add("x + 3"$p);
  3.  print($res->toString())// Prints 2x + 5 ( sum of the two )

  • See: Math_Polynomial::subtract()
  • Access: public

Parameters:

mixed   $p1   —  String representation or Polynomial object
mixed   $p2   — 

[ Top ]

create   [line 113]

object create( string $str)

Create a Polynomial object from a string/integer/float
  • Access: public

Parameters:

string   $str   — 

[ Top ]

createFromRoots   [line 387]

object &createFromRoots( array $arr)

Create a Polynomial object which has roots (zeros) provided as parameters

The roots can be passed in as either a variable length parameter list or a single array of float values.

  • Access: public

Parameters:

array   $arr   —  An array of roots

[ Top ]

createFunction   [line 866]

string createFunction( object $p)

Create a lambda-style anonymous function from the Polynomial

Creates an anonymous function representing the Polynomial which takes one parameter, an x value to evaluate at, and returns a unique name for the function.


Parameters:

object   $p   —  Polynomial object or string representing a Polynomial

[ Top ]

createSecantFunction   [line 1055]

string createSecantFunction( object $p, float $x1, float $x2)

Create a lambda-style function representing the secant line through two points

Parameters:

object   $p   — 
float   $x1   — 
float   $x2   — 

[ Top ]

createTangentFunction   [line 1008]

string createTangentFunction( object $p, float $x)

Create a lambda-style function representing the tangent line at a point

Parameters:

object   $p   — 
float   $x   — 

[ Top ]

div   [line 260]

object &div( object $p1, object $p2, [object $rem = null])

Divide one Polynomial by another, returning the result

Divide the first polynomial by another polynomial object or a string represention of another polynomial. Optionally, you can pass another Polynomial object by reference to store the remainder of the division operator.

  1.  $a = new Polynomial("4x^2 + 2x");
  2.  $b = new Polynomial("2x");
  3.  $remainder = new Polynomial();
  4.  $result = PolynomialOp::div($a$b$remainder);
  5.  print("A divided by B is: " $result->toString(" with a remainder of " $remainder->toString("\n");

  • Access: public

Parameters:

object   $p1   — 
object   $p2   — 
object   $rem   — 

[ Top ]

equals   [line 757]

bool equals( object $p1, object $p2)

Tell whether or not two Polynomials/string representations are equal
  • Access: public

Parameters:

object   $p1   — 
object   $p2   — 

[ Top ]

evaluate   [line 359]

float evaluate( $p, float $x, object $m1)

Evaluate the polynomial for a given x value
  • Return: The resulting value ( y value, or value of function f(x) )
  • Access: public

Parameters:

object   $m1   — 
float   $x   —  The x to evaluate the polynomial at
   $p   — 

[ Top ]

getAntiDerivative   [line 1295]

void &getAntiDerivative( object $p, [integer $n = 1], [integer $c = 0])

Get the nth anti-derivative of a Math_Polynomial

Returns the nth anti-derivative of the Polynomial. An optional constant can be passed in to have that appended as the x^0 term.

  • See: PolynomialOp::getDerivative()
  • Access: public

Parameters:

object   $p   — 
integer   $n   — 
integer   $c   — 

[ Top ]

getCriticalPoints   [line 843]

array getCriticalPoints( object $p)

Calculate and return an array of critical points for the Polynomial

Critical points of a Polynomial are where something 'important' happens in the Polynomial (inflection point, maximum, minumum, etc.)

  • Access: public

Parameters:

object   $p   — 

[ Top ]

getDerivative   [line 1349]

object A &getDerivative( object $p, [ $n = 1], integer $der_num)

Get the nth derivative of a Math_Polynomial

Returns the nth derivative of the Polynomial. Derivatives are commonly used in calculus as they represent slopes or acceleration. To get the first derivative, the second parameter should be a 1. For the second derivative parameter should be a two, etc. etc.

  • Return: polynomial object representing the nth derivative
  • See: PolynomialOp::getAntiDerivative()
  • Access: public

Parameters:

object   $p   —  The Polynomial object
integer   $der_num   —  The derivative you want (1 = 1st, 2 = 2nd, etc.)
   $n   — 

[ Top ]

getEndBehavior   [line 1251]

array getEndBehavior( object $p)

Get the end behavior of a Polynomial

The end behaviors are determined by the degree of the Polynomial and whether or not the coefficient is positive or negative. The values returned correspond to the MATH_POLYNOMIAL_QUADRANT_* constants for the cartesian coordinate system:

 	Quad 2 | Quad 1
  ---------------
 	Quad 3 | Quad 4

Returns an array containing two elements:

  1.      $end_behaviors Math_PolynomialOp::getEndBehavior('x^2 + 1');
  2.      print_r($end_behaviors);
  3.  
  4.      // prints:
  5.      Array
  6.      (
  7.          [0=> MATH_POLYNOMAIL_QUADRANT_2 // This is the left-end behavior
  8.          [1=> MATH_POLYNOMIAL_QUADRANT_1 // This is the right-end behavior
  9.      )

  • See: Math_PolynomialOp::getRightEndBehavior()
  • See: Math_PolynomialOp::getLeftEndBehavior()
  • Access: public

Parameters:

object   $p   — 

[ Top ]

getLocalMaximums   [line 904]

array getLocalMaximums( object $p, [float $x_min = null], [float $x_max = null])

Find and return an array of the local maximums of the Polynomial

By default the function returns all local maximums for the Polynomial. If you want just maximums on an interval, pass in the $x_min and $x_max parameters.


Parameters:

object   $p   — 
float   $x_min   — 
float   $x_max   — 

[ Top ]

getLocalMinimums   [line 945]

array getLocalMinimums( object $p, [float $x_min = null], [float $x_max = null])

Find and return an array of the minimums of the Polynomial

By default the method returns all minimums, if you want the minimums within an interval, pass in the $x_min and $x_max parameters.


Parameters:

object   $p   — 
float   $x_min   — 
float   $x_max   — 

[ Top ]

getRoots   [line 438]

array getRoots( object $p, [array $guesses = array()])

Get the roots of this Polynomial

For Polynomials of degree less than or equal to 4, the exact value of any real roots (zeros) of the Polynomial are returned. For Polynomials of higher degrees, the roots are estimated using the Newton-Raphson method from the Math_Numerical_RootFinding package. Remember that these roots are *estimates* and for high-degree polynomials all of the roots may not be calculated and returned!

If you're calculating roots for a higher-degree Polynomial and want to provide the initial guesses for the roots, you can pass them in as an array parameter.

If possible, this function will return integers instead of floats.


Parameters:

object   $p   — 
array   $guesses   — 

[ Top ]

getRootsCubic   [line 573]

array getRootsCubic( $p, object $m)

Find and return the real roots of a cubic Polynomial using the cubic formula

Parameters:

object   $m   — 
   $p   — 

[ Top ]

getRootsHighDegree   [line 790]

array getRootsHighDegree( $p, [array $guesses = array()], object $m)

Estimate and return the roots of a high-degree Polynomial ( degree 5 or greater )

This function uses Newton's method using the Math_Numerical_RootFinding PEAR package to estimate the real roots of high-degree Polynomials. If you already have estimates of where the roots might be, you can pass in an array of guesses. Otherwise, the method will try to calculate some good initial guesses for you.

You must have the Math_Numerical_RootFinding package installed for this method to work!


Parameters:

object   $m   — 
array   $guesses   — 
   $p   — 

[ Top ]

getRootsLinear   [line 492]

array getRootsLinear( $p, object $m)

Get the roots of a linear Polynomial

Parameters:

object   $m   — 
   $p   — 

[ Top ]

getRootsQuadratic   [line 528]

array getRootsQuadratic( $p, object $m)

Get the roots of a quadratic Polynomial (using the Quadratic Formula)
  • See: Math_Polynomial::getRoots()
  • Access: public

Parameters:

object   $m   — 
   $p   — 

[ Top ]

getRootsQuartic   [line 652]

array getRootsQuartic( object $p)

Find and return the roots of a Quartic Polynomial (degree 4) with the Quartic formula

Parameters:

object   $p   — 

[ Top ]

getSecantAt   [line 1029]

object getSecantAt( object $p, float $x1, float $x2)

Get a Math_Polynomial object representing the secant line through two points on the given Polynomial

Parameters:

object   $p   — 
float   $x1   — 
float   $x2   — 

[ Top ]

getSecantSlopeAt   [line 1118]

float getSecantSlopeAt( object $p, float $x1, float $x2)

Get the slope of a secant to the Polynomial passing through points x1 and x2

Parameters:

object   $p   — 
float   $x1   — 
float   $x2   — 

[ Top ]

getSlopeAt   [line 1087]

float getSlopeAt( object $p, float $x)

Get the slope of the Polynomial at a given x value

Parameters:

object   $p   — 
float   $x   — 

[ Top ]

getTangentAt   [line 982]

object getTangentAt( object $p, float $x)

Get a Polynomial object representing a tangent to the given Polynomial at the given point

Parameters:

object   $p   — 
float   $x   — 

[ Top ]

getTangentSlopeAt   [line 1101]

float getTangentSlopeAt( object $p, float $x)

Alias of Math_PolynomialOp::getSlopeAt()
  • Access: public

Parameters:

object   $p   — 
float   $x   — 

[ Top ]

isConstant   [line 1409]

bool isConstant( object $p)

Tell whether or not a Polynomial is constant (degree 0)
  • Access: public

Parameters:

object   $p   — 

[ Top ]

isEven   [line 1139]

bool isEven( mixed $p, [integer $num_test_points = 10])

Test if a Math_Polynomial object is an even function (i.e.: f(-x) == f(x) for all x)

Parameters:

mixed   $p   — 
integer   $num_test_points   — 

[ Top ]

isMath_Polynomial   [line 743]

bool isMath_Polynomial( object $p)

Tell whether or not an object is a Polynomial or not
  • Access: public

Parameters:

object   $p   — 

[ Top ]

isOdd   [line 1166]

bool isOdd( mixed $p, [integer $num_test_points = 10])

Test if a Math_Polynomial object is an odd function (i.e.: f(-x) == -f(x) for all x)

Parameters:

mixed   $p   — 
integer   $num_test_points   — 

[ Top ]

isZero   [line 1383]

bool isZero( object $p)

Tells whether or not the Polynomial is equivalent to zero
  • Return: TRUE if its equal to 0, FALSE if it is not
  • Access: public

Parameters:

object   $p   — 

[ Top ]

mod   [line 342]

object &mod( object $p1, object $p2)

Calculate the mod (%) $p1 of $p2 and return the result as a Polynomial

  1.  print('p1 % p2 is: ');
  2.  $mod Math_PolynomialOp::mod($p1$p2);
  3.  print($mod->toString());


Parameters:

object   $p1   — 
object   $p2   — 

[ Top ]

mul   [line 204]

object &mul( $p1, $p2, object $m1, object $m2)

Multiply two Polynomials together

The parameters may be either a Polynomial object or a string representation of a polynomial.

  • Access: public

Parameters:

object   $m1   —  Polynomial object or string representing polynomial
object   $m2   — 
   $p1   — 
   $p2   — 

[ Top ]

sub   [line 171]

object &sub( mixed $p1, mixed $p2)

Subtract one Polynomial from another Polynomial

Parameters:

mixed   $p1   —  The initial Polynomial
mixed   $p2   —  The Polynomial to subtract from the initial one

[ Top ]

_round   [line 467]

mixed _round( mixed $mixed)

Round an array of integers or single integer if its within the round boundary
  • Access: protected

Parameters:

mixed   $mixed   — 

[ Top ]


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