PHP Class MathPHP\Sequence\Advanced

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

Public Methods

Method Description
fibonacci ( integer $n ) : array Fibonacci numbers Every number is the sum of the two preceding ones.
heptagonalNumber ( integer $n ) : array Heptagonal numbers Figurate numbers that represent heptagons.
hexagonalNumber ( integer $n ) : array Hexagonal numbers Figurate numbers that represent hexagons.
lazyCaterers ( integer $n ) : array Lazy caterer's sequence (central polygonal numbers) Describes the maximum number of pieces of a circle that can be made with a given number of straight cuts.
lookAndSay ( integer $n ) : array Look-and-say sequence (describe the previous term!) (Sequence A005150 in the OEIS)
lucasNumber ( integer $n ) : array Lucas numbers Every number is the sum of its two immediate previous terms.
magicSquares ( integer $n ) : array Magic squares series The constant sum in every row, column and diagonal of a magic square is called the magic constant or magic sum, M.
pellNumber ( integer $n ) : array Pell numbers The denominators of the closest rational approximations to the square root of 2.
pentagonalNumber ( integer $n ) : array Pentagonal numbers Figurate numbers that represent pentagons.
triangularNumber ( integer $n ) : array Triangular numbers Figurate numbers that represent equilateral triangles.

Method Details

fibonacci() public static method

https://en.wikipedia.org/wiki/Fibonacci_number F₀ = 0 F₁ = 1 Fᵢ = Fᵢ₋₁ + Fᵢ₋₂ Example: n = 6 Sequence: 0, 1, 1, 2, 3, 5 Array index: 0, 1, 2, 3, 4, 5
public static fibonacci ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0

heptagonalNumber() public static method

https://en.wikipedia.org/wiki/Heptagonal_number 5n² - 3n Hn = -------- 2 Example: n = 6 Sequence: 1, 4, 7, 13, 18, 27 Array index: 1, 2, 3, 4, 5, 6
public static heptagonalNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 1

hexagonalNumber() public static method

https://en.wikipedia.org/wiki/Hexagonal_number 2n × (2n - 1) hn = ------------- 2 Example: n = 6 Sequence: 1, 6, 15, 28, 45, 66 Array index: 1, 2, 3, 4, 5, 6
public static hexagonalNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 1

lazyCaterers() public static method

https://en.wikipedia.org/wiki/Lazy_caterer%27s_sequence https://oeis.org/A000124 n² + n + 2 p = ---------- 2 Using binomial coefficients: (n + 1) (n) (n) (n) p = 1 + ( ) = ( ) + ( ) + ( ) ( 2 ) (0) (1) (2) Example: n = 6 Sequence: 1, 2, 4, 7, 11, 16, 22 Array index: 0, 1, 2, 3, 4, 5, 6
public static lazyCaterers ( integer $n ) : array
$n integer How many numbers in the sequence
return array

lookAndSay() public static method

1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ... To generate a member of the sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit. 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, then one 1" or 1211. 1211 is read off as "one 1, one 2, then two 1s" or 111221. 111221 is read off as "three 1s, two 2s, then one 1" or 312211. https://en.wikipedia.org/wiki/Look-and-say_sequence https://oeis.org/A005150 Example: n = 6 Sequence: 1, 11, 21, 1211, 111221, 312211 Array index: 1, 2, 3, 4, 5, 6
public static lookAndSay ( integer $n ) : array
$n integer How many numbers in the sequence
return array of strings indexed from 1

lucasNumber() public static method

Similar to Fibonacci numbers except the base cases differ. https://en.wikipedia.org/wiki/Lucas_number L₀ = 2 L₁ = 1 Lᵢ = Lᵢ₋₁ + Lᵢ₋₂ Example: n = 6 Sequence: 2, 1, 3, 4, 7, 11 Array index: 0, 1, 2, 3, 4, 5
public static lucasNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0

magicSquares() public static method

https://oeis.org/A006003 https://edublognss.wordpress.com/2013/04/16/famous-mathematical-sequences-and-series/ n(n² + 1) M = --------- 2 Example: n = 6 Sequence: 0, 1, 5, 15, 34, 65 Array index: 0, 1, 2, 3, 4, 5,
public static magicSquares ( integer $n ) : array
$n integer How many numbers in the sequence
return array

pellNumber() public static method

https://en.wikipedia.org/wiki/Pell_number P₀ = 0 P₁ = 1 Pᵢ = 2Pᵢ₋₁ + Pᵢ₋₂ Example: n = 6 Sequence: 0, 1, 2, 5, 12, 29 Array index: 0, 1, 2, 3, 4, 5
public static pellNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 0

pentagonalNumber() public static method

https://en.wikipedia.org/wiki/Pentagonal_number 3n² - n pn = ------- 2 Example: n = 6 Sequence: 1, 5, 12, 22, 35, 51 Array index: 1, 2, 3, 4, 5, 6
public static pentagonalNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 1

triangularNumber() public static method

https://en.wikipedia.org/wiki/Triangular_number n(n + 1) Tn = -------- 2 Example: n = 6 Sequence: 1, 3, 6, 10, 15, 21 Array index: 1, 2, 3, 4, 5, 6
public static triangularNumber ( integer $n ) : array
$n integer How many numbers in the sequence
return array Indexed from 1