MathPHP\Sequence\Basic::arithmeticProgression PHP Метод

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

https://en.wikipedia.org/wiki/Arithmetic_progression Example: n = 10 d = 2 a₁ = 1 Sequence: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 Array index: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
public static arithmeticProgression ( integer $n, integer $d, integer $a₁ ) : array
$n integer How many numbers in the sequence
$d integer Difference between the elements of the sequence
$a₁ integer Starting number for the sequence
Результат array Indexed from 1
    public static function arithmeticProgression(int $n, int $d, int $a₁) : array
    {
        if ($n <= 0) {
            return [];
        }
        $progression[1] = $a₁;
        for ($i = 1; $i < $n; $i++) {
            $progression[$i + 1] = $progression[$i] + $d;
        }
        return $progression;
    }