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