PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/designbyheart/original
PHP | 98 lines | 47 code | 19 blank | 32 comment | 5 complexity | fe22840a18e6ae4e22213de9119e2986 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_Power_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_Power_Best_Fit extends PHPExcel_Best_Fit
  36. {
  37. protected $_bestFitType = 'power';
  38. public function getValueOfYForX($xValue) {
  39. return $this->getIntersect() * pow(($xValue - $this->_Xoffset),$this->getSlope());
  40. } // function getValueOfYForX()
  41. public function getValueOfXForY($yValue) {
  42. return pow((($yValue + $this->_Yoffset) / $this->getIntersect()),(1 / $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.' * X^'.$slope;
  48. } // function getEquation()
  49. public function getIntersect($dp=0) {
  50. if ($dp != 0) {
  51. return round(exp($this->_intersect),$dp);
  52. }
  53. return exp($this->_intersect);
  54. } // function getIntersect()
  55. private function _power_regression($yValues, $xValues, $const) {
  56. foreach($xValues as &$value) {
  57. if ($value < 0.0) {
  58. $value = 0 - log(abs($value));
  59. } elseif ($value > 0.0) {
  60. $value = log($value);
  61. }
  62. }
  63. unset($value);
  64. foreach($yValues as &$value) {
  65. if ($value < 0.0) {
  66. $value = 0 - log(abs($value));
  67. } elseif ($value > 0.0) {
  68. $value = log($value);
  69. }
  70. }
  71. unset($value);
  72. $this->_leastSquareFit($yValues, $xValues, $const);
  73. } // function _power_regression()
  74. function __construct($yValues, $xValues=array(), $const=True) {
  75. if (parent::__construct($yValues, $xValues) !== False) {
  76. $this->_power_regression($yValues, $xValues, $const);
  77. }
  78. } // function __construct()
  79. } // class powerBestFit