123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
- class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
- {
-
- protected $bestFitType = 'power';
-
- public function getValueOfYForX($xValue)
- {
- return $this->getIntersect() * pow(($xValue - $this->xOffset), $this->getSlope());
- }
-
- public function getValueOfXForY($yValue)
- {
- return pow((($yValue + $this->yOffset) / $this->getIntersect()), (1 / $this->getSlope()));
- }
-
- public function getEquation($dp = 0)
- {
- $slope = $this->getSlope($dp);
- $intersect = $this->getIntersect($dp);
- return 'Y = ' . $intersect . ' * X^' . $slope;
- }
-
- public function getIntersect($dp = 0)
- {
- if ($dp != 0) {
- return round(exp($this->intersect), $dp);
- }
- return exp($this->intersect);
- }
-
- private function powerRegression($yValues, $xValues, $const)
- {
- foreach ($xValues as &$value) {
- if ($value < 0.0) {
- $value = 0 - log(abs($value));
- } elseif ($value > 0.0) {
- $value = log($value);
- }
- }
- unset($value);
- 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->powerRegression($yValues, $xValues, $const);
- }
- }
- }
|