<?php header('Content-type: text/plain'); include 'Math/Polynomial.php'; include 'Math/PolynomialOp.php'; print "\n-- Algebra --\n"; $p = new Math_Polynomial('3x^2 + 2x'); $q = new Math_Polynomial('4x + 1'); print 'P is: ' . $p->toString() . "\n"; print 'Q is: ' . $q->toString() . "\n"; $mul = Math_PolynomialOp::mul($p, $q); // Multiply p by q print 'P multiplied by Q is: ' . $mul->toString() . "\n"; // Print string representation print 'The degree of that result is: ' . $mul->degree() . "\n"; print 'That result evaluated at x = 10 is: ' . number_format(Math_PolynomialOp::evaluate($mul, 10)) . "\n"; $sub = Math_PolynomialOp::sub($p, $q); print 'P minus Q is: ' . $sub->toString() . "\n"; $r = new Math_Polynomial('3x^3 - 5x^2 + 10x-3'); $s = new Math_Polynomial('3x+1'); $remainder = new Math_Polynomial(); print 'R is: ' . $r->toString() . "\n"; print 'S is: ' . $s->toString() . "\n"; $div = Math_PolynomialOp::div($r, $s, &$t); print 'R divided by S is: ' . $div->toString() . ' ( remainder of: ' . $remainder->toString() . ' )' . "\n"; print "\n-- Creating Polynomials --\n"; $roots = Math_PolynomialOp::createFromRoots(1, 2, -3); print 'Here is a polynomial with the roots 1, 2, and -3: ' . $roots->toString() . "\n"; print "\n-- Derivatives --\n"; print 'f(x) is: ' . $p->toString() . "\n"; $der1 = Math_PolynomialOp::getDerivative($p);
<?php //header('Content-type: text/plain'); include 'Math/Polynomial.php'; include 'Math/PolynomialOp.php'; echo "<br />-- Algebra --<br />"; $p = new Math_Polynomial('3x^2 + 2x'); $q = new Math_Polynomial('4x + 1'); echo 'P is: ' . $p->toString() . "<br />"; echo 'Q is: ' . $q->toString() . "<br />"; $mul = Math_PolynomialOp::mul($p, $q); // Multiply p by q echo 'P multiplied by Q is: ' . $mul->toString() . "<br />"; // Print string representation echo 'The degree of that result is: ' . $mul->degree() . "<br />"; echo 'That result evaluated at x = 10 is: ' . number_format(Math_PolynomialOp::evaluate($mul, 10)) . "<br />"; $sub = Math_PolynomialOp::sub($p, $q); echo 'P minus Q is: ' . $sub->toString() . "<br />"; $r = new Math_Polynomial('3x^3 - 5x^2 + 10x-3'); $s = new Math_Polynomial('3x+1'); $remainder = new Math_Polynomial(); echo 'R is: ' . $r->toString() . "<br />"; echo 'S is: ' . $s->toString() . "<br />"; $div = Math_PolynomialOp::div($r, $s, $remainder); echo 'R divided by S is: ' . $div->toString() . ' ( remainder of: ' . $remainder->toString() . ' )' . "<br />"; echo "<br />-- Creating Polynomials --<br />"; $roots = Math_PolynomialOp::createFromRoots(1, 2, -3); echo 'Here is a polynomial with the roots 1, 2, and -3: ' . $roots->toString() . "<br />"; echo "<br />-- Derivatives --<br />"; echo 'f(x) is: ' . $p->toString() . "<br />"; $der1 = Math_PolynomialOp::getDerivative($p);
/** * Get the slope of a secant to the Polynomial passing through points x1 and x2 * * @see Math_PolynomialOp::getTangentSlopeAt(), Math_PolynomialOp::getSecantAt() * * @access public * * @param object $p * @param float $x1 * @param float $x2 * @return float */ function getSecantSlopeAt($p, $x1, $x2) { // y2 - y1 / x2 - x1 $y1 = Math_PolynomialOp::evaluate($p, $x1); $y2 = Math_PolynomialOp::evaluate($p, $x2); return ($y2 - $y1) / ($x2 - $x1); }