123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
- class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
- {
-
- protected $bestFitType = 'logarithmic';
-
- public function getValueOfYForX($xValue)
- {
- return $this->getIntersect() + $this->getSlope() * log($xValue - $this->xOffset);
- }
-
- public function getValueOfXForY($yValue)
- {
- return exp(($yValue - $this->getIntersect()) / $this->getSlope());
- }
-
- public function getEquation($dp = 0)
- {
- $slope = $this->getSlope($dp);
- $intersect = $this->getIntersect($dp);
- return 'Y = '.$intersect.' + '.$slope.' * log(X)';
- }
-
- private function logarithmicRegression($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);
- $this->leastSquareFit($yValues, $xValues, $const);
- }
-
- public function __construct($yValues, $xValues = array(), $const = true)
- {
- if (parent::__construct($yValues, $xValues) !== false) {
- $this->logarithmicRegression($yValues, $xValues, $const);
- }
- }
- }
|