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

Source for file Polynomial_examples.php

Documentation is available at Polynomial_examples.php

  1. <?php
  2.  
  3. header('Content-type: text/plain');
  4.  
  5. include 'Math/Polynomial.php';
  6. include 'Math/PolynomialOp.php';
  7.  
  8. print("\n-- Algebra --\n");
  9. $p = new Math_Polynomial('3x^2 + 2x');
  10. $q = new Math_Polynomial('4x + 1');
  11. print('P is: ' $p->toString("\n");
  12. print('Q is: ' $q->toString("\n");
  13.  
  14. $mul Math_PolynomialOp::mul($p$q)// Multiply p by q
  15. print('P multiplied by Q is: ' $mul->toString("\n")// Print string representation
  16.  
  17. print('The degree of that result is: ' $mul->degree("\n");
  18. print('That result evaluated at x = 10 is: ' number_format(Math_PolynomialOp::evaluate($mul10)) "\n");
  19.  
  20. $sub Math_PolynomialOp::sub($p$q);
  21. print('P minus Q is: ' $sub->toString("\n");
  22.  
  23. $r = new Math_Polynomial('3x^3 - 5x^2 + 10x-3');
  24. $s = new Math_Polynomial('3x+1');
  25. $remainder = new Math_Polynomial();
  26.  
  27. print('R is: ' $r->toString("\n");
  28. print('S is: ' $s->toString("\n");
  29.  
  30. $div Math_PolynomialOp::div($r$s&$t);
  31. print('R divided by S is: ' $div->toString(' ( remainder of: ' $remainder->toString(' )' "\n");
  32.  
  33.  
  34. print("\n-- Creating Polynomials --\n");
  35. $roots Math_PolynomialOp::createFromRoots(12-3);
  36. print('Here is a polynomial with the roots 1, 2, and -3: ' $roots->toString("\n");
  37.  
  38.  
  39. print("\n-- Derivatives --\n");
  40. print('f(x) is: ' $p->toString("\n");
  41.  
  42. print('f\'(x) is: ' $der1->toString(' (first derivative)' "\n");
  43.  
  44. $der2 Math_PolynomialOp::getDerivative($p2);
  45. print('f\'\'(x) is: ' $der2->toString(' (second derivative)' "\n");
  46.  
  47. print("\n");
  48.  
  49. ?>

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