linearBestFitClass.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Shared_Best_Fit
  23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.6, 2011-02-27
  26. */
  27. require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
  28. /**
  29. * PHPExcel_Linear_Best_Fit
  30. *
  31. * @category PHPExcel
  32. * @package PHPExcel_Shared_Best_Fit
  33. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  34. */
  35. class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
  36. {
  37. protected $_bestFitType = 'linear';
  38. public function getValueOfYForX($xValue) {
  39. return $this->getIntersect() + $this->getSlope() * $xValue;
  40. } // function getValueOfYForX()
  41. public function getValueOfXForY($yValue) {
  42. return ($yValue - $this->getIntersect()) / $this->getSlope();
  43. } // function getValueOfXForY()
  44. public function getEquation($dp=0) {
  45. $slope = $this->getSlope($dp);
  46. $intersect = $this->getIntersect($dp);
  47. return 'Y = '.$intersect.' + '.$slope.' * X';
  48. } // function getEquation()
  49. private function _linear_regression($yValues, $xValues, $const) {
  50. $this->_leastSquareFit($yValues, $xValues,$const);
  51. } // function _linear_regression()
  52. function __construct($yValues, $xValues=array(), $const=True) {
  53. if (parent::__construct($yValues, $xValues) !== False) {
  54. $this->_linear_regression($yValues, $xValues, $const);
  55. }
  56. } // function __construct()
  57. } // class linearBestFit