PHP Class MathPHP\Sequence\Basic

All sequences return an array of numbers in the sequence. The array index starting point depends on the sequence type.
Show file Open project: markrogoyski/math-php

Public Methods

Method Description
arithmeticProgression ( integer $n, integer $d, integer $a₁ ) : array Arithmetic progression A sequence of numbers such that the difference between the consecutive terms is constant.
cubicNumber ( integer $n ) : array Cubic numbers https://en.wikipedia.org/wiki/Cube_(algebra)
factorial ( integer $n ) : array Factorial https://en.wikipedia.org/wiki/Factorial
geometricProgression ( integer $n, number $a, number $r ) : array Geometric progression A sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio.
powersOfTen ( integer $n ) : array Powers of ten https://en.wikipedia.org/wiki/Power_of_10
powersOfTwo ( integer $n ) : array Powers of two https://en.wikipedia.org/wiki/Power_of_two
squareNumber ( integer $n ) : array Square numbers https://en.wikipedia.org/wiki/Square_number

Method Details

arithmeticProgression() public static method

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
return array Indexed from 1

cubicNumber() public static method

n³ Example: n = 5 Sequence: 0³, 1³, 2³, 3³, 4³ Sequence: 0, 1, 8, 27, 64 Array index: 0, 1, 2, 3, 4
public static cubicNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0 (indexes are the base number which is raised to the power of 3)

factorial() public static method

Example: n = 5 Sequence: 0!, 1!, 2!, 3!, 4! Sequence: 1, 1, 2, 6, 24 Array index: 0, 1, 2, 3, 4
public static factorial ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0 (indexes are the n!)

geometricProgression() public static method

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
return array Indexed from 0 (indexes are powers of common ratio)

powersOfTen() public static method

Example: n = 5 Sequence: 10⁰, 10¹, 10², 10³, 10⁴ Sequence: 1, 10, 100, 1000, 10000 Array index: 0, 1, 2, 3, 4
public static powersOfTen ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0 (indexes are the power 10 is raised to)

powersOfTwo() public static method

2ⁿ Example: n = 5 Sequence: 2⁰, 2¹, 2², 2³, 2⁴ Sequence: 1, 2, 4, 8, 16 Array index: 0, 1, 2, 3, 4
public static powersOfTwo ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0 (indexes are the power 2 is raised to)

squareNumber() public static method

n² Example: n = 5 Sequence: 0², 1², 2², 3², 4² Sequence: 0, 1, 4, 9, 16 Array index: 0, 1, 2, 3, 4
public static squareNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0 (indexes are the base number which is raised to the power of 2)