123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
- class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
- {
-
- protected $bestFitType = 'exponential';
-
- public function getValueOfYForX($xValue)
- {
- return $this->getIntersect() * pow($this->getSlope(), ($xValue - $this->xOffset));
- }
-
- public function getValueOfXForY($yValue)
- {
- return log(($yValue + $this->yOffset) / $this->getIntersect()) / log($this->getSlope());
- }
-
- public function getEquation($dp = 0)
- {
- $slope = $this->getSlope($dp);
- $intersect = $this->getIntersect($dp);
- return 'Y = ' . $intersect . ' * ' . $slope . '^X';
- }
-
- public function getSlope($dp = 0)
- {
- if ($dp != 0) {
- return round(exp($this->_slope), $dp);
- }
- return exp($this->_slope);
- }
-
- public function getIntersect($dp = 0)
- {
- if ($dp != 0) {
- return round(exp($this->intersect), $dp);
- }
- return exp($this->intersect);
- }
-
- private function exponentialRegression($yValues, $xValues, $const)
- {
- foreach ($yValues as &$value) {
- if ($value < 0.0) {
- $value = 0 - log(abs($value));
- } elseif ($value > 0.0) {
- $value = log($value);
- }
- }
- unset($value);
- $this->leastSquareFit($yValues, $xValues, $const);
- }
-
- public function __construct($yValues, $xValues = array(), $const = true)
- {
- if (parent::__construct($yValues, $xValues) !== false) {
- $this->exponentialRegression($yValues, $xValues, $const);
- }
- }
- }
|