source: sourcecode/application/libraries/PHPExcel/Shared/trend/linearBestFitClass.php @ 1

Last change on this file since 1 was 1, checked in by dungnv, 11 years ago
File size: 3.3 KB
Line 
1<?php
2/**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2014 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_Trend
23 * @copyright  Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
25 * @version    1.8.0, 2014-03-02
26 */
27
28
29require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
30
31
32/**
33 * PHPExcel_Linear_Best_Fit
34 *
35 * @category   PHPExcel
36 * @package    PHPExcel_Shared_Trend
37 * @copyright  Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
38 */
39class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
40{
41        /**
42         * Algorithm type to use for best-fit
43         * (Name of this trend class)
44         *
45         * @var string
46         **/
47        protected $_bestFitType         = 'linear';
48
49
50        /**
51         * Return the Y-Value for a specified value of X
52         *
53         * @param        float          $xValue                 X-Value
54         * @return       float                                          Y-Value
55         **/
56        public function getValueOfYForX($xValue) {
57                return $this->getIntersect() + $this->getSlope() * $xValue;
58        }       //      function getValueOfYForX()
59
60
61        /**
62         * Return the X-Value for a specified value of Y
63         *
64         * @param        float          $yValue                 Y-Value
65         * @return       float                                          X-Value
66         **/
67        public function getValueOfXForY($yValue) {
68                return ($yValue - $this->getIntersect()) / $this->getSlope();
69        }       //      function getValueOfXForY()
70
71
72        /**
73         * Return the Equation of the best-fit line
74         *
75         * @param        int            $dp             Number of places of decimal precision to display
76         * @return       string
77         **/
78        public function getEquation($dp=0) {
79                $slope = $this->getSlope($dp);
80                $intersect = $this->getIntersect($dp);
81
82                return 'Y = '.$intersect.' + '.$slope.' * X';
83        }       //      function getEquation()
84
85
86        /**
87         * Execute the regression and calculate the goodness of fit for a set of X and Y data values
88         *
89         * @param        float[]        $yValues        The set of Y-values for this regression
90         * @param        float[]        $xValues        The set of X-values for this regression
91         * @param        boolean        $const
92         */
93        private function _linear_regression($yValues, $xValues, $const) {
94                $this->_leastSquareFit($yValues, $xValues,$const);
95        }       //      function _linear_regression()
96
97
98        /**
99         * Define the regression and calculate the goodness of fit for a set of X and Y data values
100         *
101         * @param       float[]         $yValues        The set of Y-values for this regression
102         * @param       float[]         $xValues        The set of X-values for this regression
103         * @param       boolean         $const
104         */
105        function __construct($yValues, $xValues=array(), $const=True) {
106                if (parent::__construct($yValues, $xValues) !== False) {
107                        $this->_linear_regression($yValues, $xValues, $const);
108                }
109        }       //      function __construct()
110
111}       //      class linearBestFit
Note: See TracBrowser for help on using the repository browser.