MathPHP\Functions\Map\Multi::divide PHP Метод

divide() публичный статический Метод

[x₁ / y₁, x₂ / y₂, ... ]
public static divide ( variadic $arrays ) : array
$arrays variadic Two or more arrays of numbers
Результат array
    public static function divide(array ...$arrays) : array
    {
        self::checkArrayLengths($arrays);
        $number_of_arrays = count($arrays);
        $length_of_arrays = count($arrays[0]);
        $quotients = array_map(function ($x) {
            return $x;
        }, $arrays[0]);
        for ($i = 0; $i < $length_of_arrays; $i++) {
            for ($j = 1; $j < $number_of_arrays; $j++) {
                $quotients[$i] /= $arrays[$j][$i];
            }
        }
        return $quotients;
    }

Usage Example

Пример #1
0
 /**
  * Calculate the regression parameters by least squares on linearized data
  * x / y = x / V + K / V
  */
 public function calculate()
 {
     // Linearize the relationship by dividing x by y
     $y’ = Multi::divide($this->xs, $this->ys);
     // Perform Least Squares Fit
     $linear_parameters = $this->leastSquares($y’, $this->xs)->getColumn(0);
     $V = 1 / $linear_parameters[1];
     $K = $linear_parameters[0] * $V;
     $this->parameters = [$V, $K];
 }