PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/lib/classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php

https://bitbucket.org/designbyheart/original
PHP | 82 lines | 33 code | 17 blank | 32 comment | 2 complexity | 932d5b72101bf4193a3f21ded7b3430c MD5 | raw file
Possible License(s): GPL-3.0
  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_Logarithmic_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_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
  36. {
  37. protected $_bestFitType = 'logarithmic';
  38. public function getValueOfYForX($xValue) {
  39. return $this->getIntersect() + $this->getSlope() * log($xValue - $this->_Xoffset);
  40. } // function getValueOfYForX()
  41. public function getValueOfXForY($yValue) {
  42. return exp(($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.' * log(X)';
  48. } // function getEquation()
  49. private function _logarithmic_regression($yValues, $xValues, $const) {
  50. foreach($xValues as &$value) {
  51. if ($value < 0.0) {
  52. $value = 0 - log(abs($value));
  53. } elseif ($value > 0.0) {
  54. $value = log($value);
  55. }
  56. }
  57. unset($value);
  58. $this->_leastSquareFit($yValues, $xValues, $const);
  59. } // function _logarithmic_regression()
  60. function __construct($yValues, $xValues=array(), $const=True) {
  61. if (parent::__construct($yValues, $xValues) !== False) {
  62. $this->_logarithmic_regression($yValues, $xValues, $const);
  63. }
  64. } // function __construct()
  65. } // class logarithmicBestFit