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

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

https://en.wikipedia.org/wiki/Geometric_progression an = arⁿ⁻¹ Example: n = 4 a = 2 r = 3 Sequence: 2(3)⁰, 2(3)¹, 2(3)², 2(3)³ Sequence: 2, 6, 18, 54 Array index: 0 1 2 3
public static geometricProgression ( integer $n, number $a, number $r ) : array
$n integer How many numbers in the sequence
$a number Scalar value
$r number Common ratio
Результат array Indexed from 0 (indexes are powers of common ratio)
    public static function geometricProgression(int $n, $a, $r) : array
    {
        if ($r === 0) {
            throw new Exception\BadParameterException('Common ratio r cannot be 0');
        }
        $progression = [];
        if ($n < 0) {
            return $progression;
        }
        for ($i = 0; $i < $n; $i++) {
            $progression[] = $a * $r ** $i;
        }
        return $progression;
    }