MathPHP\Functions\Map\Single::subtract PHP Méthode

subtract() public static méthode

Map subtract
public static subtract ( array $xs, number $k ) : array
$xs array
$k number Number to subtract from each element
Résultat array
    public static function subtract(array $xs, $k) : array
    {
        return array_map(function ($x) use($k) {
            return $x - $k;
        }, $xs);
    }

Usage Example

 /**
  * Calculates the regression parameters.
  */
 public function calculate()
 {
     $v = $this->v;
     $w = $this->w;
     $x’ = Single::subtract($this->xs, $v);
     $y’ = Single::subtract($this->ys, $w);
     $parameters = $this->leastSquares($y’, $x’, 1, 0)->getColumn(0);
     $this->m = $parameters[0];
     $this->b = $this->w - $this->m * $this->v;
     $this->parameters = [$this->b, $this->m];
 }
All Usage Examples Of MathPHP\Functions\Map\Single::subtract