PHP code example of pipirima / trend-line-calculator

1. Go to this page and download the library: Download pipirima/trend-line-calculator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pipirima / trend-line-calculator example snippets



use Pipirima\TrendLine\Calculator;

// ...

        // create points
        $points = [
            [1, 2],
            [2, 3],
            [3, 6],
            [4, 8],
            [5, 10],
            [6, 12],
        ];

        // calculate trend line
        $calculator = new Calculator();
        $line = $calculator->calculateLine($points);

        // check its coefficients
        $this->assertLessThan(0.0001, abs(2.0857 - $line[0]));
        $this->assertLessThan(0.0001, abs(-0.46667 - $line[1]));