2
$\begingroup$

I am trying to find the formula for finding out if a number is heptagonal. I am also looking for the formula for finding out if a number is octagonal.

I already have the formula for finding out the nth heptagonal number and the nth octagonal number:

heptagonal: $\frac{n(5n - 3)}{2}$

octagonal: $n(3n-2n)$

For example, with these formulas the 20th heptagonal number is 970 and the 20th octagonal number is 1160. What I want to do is be able to do is plug in 1160 into my isOctagonal formula and get back 20th for octagonal. Or 970 and get back 20th for heptagonal.

I have managed to find these reverse formulas for triangular numbers, square numbers, pentagonal numbers, and hexagonal numbers. For example, the triangular one looks like this:$$n = \frac{\sqrt{8x + 1} - 1}{2}$$

Where x is the triangular candidate. If n is a natural number, n is the n-th triangular number.

I have been searching and searching for the heptagonal and octagonal formulas for a long time now and can't seem to find them.

  • 2
    Does this help? https://en.wikipedia.org/wiki/Polygonal_number2012-08-19
  • 0
    Do you know the quadratic formula?2012-08-19
  • 0
    Andrew - Actually, yes that does, thank you! I was searching specifically for the heptagonal and octagonal formulas and they were never listed on any pages. Never thought to check for a general formulas for all polygonal numbers. Now, hopefully I will be able to understand how to apply it. I'll give it a try. Thanks!2012-08-19
  • 0
    Micah, not quite. It has been in a long time since I have learned any formal maths. Usually I solve this stuff by programming. I bet I should look into it though, right? I take it, if I knew that, I would be able to determine what the formula is based on the heptagonal formula I already have?2012-08-19
  • 0
    It's the general way to solve this kind of thing. If you've got the formula you want from that wikipedia article, you might not need it, but if you want to be able to derive that formula for yourself that'd be how to do it...2012-08-19
  • 1
    Andrew, that formula works great! With the added bonus that I don't have to define different functions for every n-gonal number I want to find. I can just have one master isNGonal(s, n) and change s to represent the number of sides I am checking for!2012-08-19
  • 1
    Now that you have an answer, why not write it up and post it as an answer? This is permitted, even encouraged on this site. Then after a couple of days you can accept your own answer - again, that's encouraged - and close the books on it.2012-08-19
  • 0
    Gerry Myerson - Ok I will. I tried now but it won't let me answer for another 6 hours or so. Also, I don't know how to properly write-out the formula so I downloaded the formula picture from wikipedia. But I can't post images until I have 10 reputation.2012-08-20

1 Answers 1

2

For a given s-gonal number P(s, n) = x, one can find n by:

$$ n = \frac{\sqrt{(8s - 16)x + (s - 4)^2} + s -4}{2s-4} $$

Where n is a natural number, n is the n-th s-gonal number.

here is the Javascript function I will be using in my program:

function isNgonal(s, x) {   var n = (Math.sqrt(x * (8 * s - 16) + Math.pow(s - 4, 2)) + s - 4) / (2 * s - 4);   if(n % 1 === 0) { return n; } else { return false; }   } 

Where s is the number of sides and x is known polygonal number. If n is a natural number, n = the n-th s-gonal number

  • 1
    Another way to write it: $$\frac{s-4+\sqrt{s^2+8(s-2)(x-1)}}{2(s-2)}$$2012-08-21