PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/designbyheart/original
PHP | 98 lines | 45 code | 21 blank | 32 comment | 6 complexity | 9eac2b10f27d150ad59a195307ce8f91 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_Exponential_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_Exponential_Best_Fit extends PHPExcel_Best_Fit
  36. {
  37. protected $_bestFitType = 'exponential';
  38. public function getValueOfYForX($xValue) {
  39. return $this->getIntersect() * pow($this->getSlope(),($xValue - $this->_Xoffset));
  40. } // function getValueOfYForX()
  41. public function getValueOfXForY($yValue) {
  42. return log(($yValue + $this->_Yoffset) / $this->getIntersect()) / log($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. public function getSlope($dp=0) {
  50. if ($dp != 0) {
  51. return round(exp($this->_slope),$dp);
  52. }
  53. return exp($this->_slope);
  54. } // function getSlope()
  55. public function getIntersect($dp=0) {
  56. if ($dp != 0) {
  57. return round(exp($this->_intersect),$dp);
  58. }
  59. return exp($this->_intersect);
  60. } // function getIntersect()
  61. private function _exponential_regression($yValues, $xValues, $const) {
  62. foreach($yValues as &$value) {
  63. if ($value < 0.0) {
  64. $value = 0 - log(abs($value));
  65. } elseif ($value > 0.0) {
  66. $value = log($value);
  67. }
  68. }
  69. unset($value);
  70. $this->_leastSquareFit($yValues, $xValues, $const);
  71. } // function _exponential_regression()
  72. function __construct($yValues, $xValues=array(), $const=True) {
  73. if (parent::__construct($yValues, $xValues) !== False) {
  74. $this->_exponential_regression($yValues, $xValues, $const);
  75. }
  76. } // function __construct()
  77. } // class exponentialBestFit